-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b5bf2e
commit 2473edf
Showing
69 changed files
with
3,513 additions
and
9,678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
|
||
# Exit on error | ||
set -e | ||
|
||
IMAGE_NAME="nextjs-docker" | ||
REGION="us-west-2" | ||
ACCOUNT_ID="000000000000" | ||
CLUSTER_NAME="nextjs-cluster" | ||
SERVICE_NAME="nextjs-service" | ||
TASK_FAMILY="nextjs-task" | ||
|
||
echo "Creating ECR repository..." | ||
REPO_URI=$(awslocal ecr create-repository \ | ||
--repository-name $IMAGE_NAME \ | ||
--region $REGION \ | ||
--query 'repository.repositoryUri' \ | ||
--output text) | ||
|
||
echo "Building Docker image..." | ||
docker build -t $IMAGE_NAME ./../../apps/nextjs | ||
|
||
echo "Tagging image..." | ||
docker tag $IMAGE_NAME:latest $REPO_URI:latest | ||
|
||
echo "Pushing image to ECR..." | ||
docker push $REPO_URI:latest | ||
|
||
# Create ECS Cluster | ||
echo "Creating ECS cluster..." | ||
awslocal ecs create-cluster \ | ||
--cluster-name $CLUSTER_NAME \ | ||
--region $REGION | ||
|
||
# Register Task Definition | ||
echo "Registering task definition..." | ||
awslocal ecs register-task-definition \ | ||
--family $TASK_FAMILY \ | ||
--container-definitions "[ | ||
{ | ||
\"name\": \"$IMAGE_NAME\", | ||
\"image\": \"$REPO_URI:latest\", | ||
\"cpu\": 256, | ||
\"memory\": 512, | ||
\"portMappings\": [ | ||
{ | ||
\"containerPort\": 3000, | ||
\"hostPort\": 3000, | ||
\"protocol\": \"tcp\" | ||
} | ||
], | ||
\"essential\": true | ||
} | ||
]" \ | ||
--requires-compatibilities "FARGATE" \ | ||
--network-mode "awsvpc" \ | ||
--cpu "256" \ | ||
--memory "512" | ||
|
||
# Create VPC | ||
echo "Creating VPC..." | ||
VPC_ID=$(awslocal ec2 create-vpc \ | ||
--cidr-block 10.0.0.0/16 \ | ||
--query 'Vpc.VpcId' \ | ||
--output text) | ||
|
||
# Create Subnet | ||
echo "Creating Subnet..." | ||
SUBNET_ID=$(awslocal ec2 create-subnet \ | ||
--vpc-id $VPC_ID \ | ||
--cidr-block 10.0.1.0/24 \ | ||
--query 'Subnet.SubnetId' \ | ||
--output text) | ||
|
||
# Create Security Group | ||
echo "Creating Security Group..." | ||
SG_ID=$(awslocal ec2 create-security-group \ | ||
--group-name ecs-sg \ | ||
--description "ECS Security Group" \ | ||
--vpc-id $VPC_ID \ | ||
--query 'GroupId' \ | ||
--output text) | ||
|
||
|
||
# Create ECS Service | ||
echo "Creating ECS service..." | ||
awslocal ecs create-service \ | ||
--cluster $CLUSTER_NAME \ | ||
--service-name $SERVICE_NAME \ | ||
--task-definition $TASK_FAMILY \ | ||
--desired-count 1 \ | ||
--launch-type FARGATE \ | ||
--network-configuration "awsvpcConfiguration={subnets=[$SUBNET_ID],securityGroups=[$SG_ID]}" \ | ||
--region $REGION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
npm-debug.log | ||
README.md | ||
.next | ||
.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
FROM node:18-alpine AS base | ||
|
||
# Install dependencies only when needed | ||
FROM base AS deps | ||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /app | ||
|
||
# Install dependencies based on the preferred package manager | ||
COPY package.json ./ | ||
RUN corepack enable pnpm && pnpm i | ||
|
||
# Rebuild the source code only when needed | ||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
|
||
# Next.js collects completely anonymous telemetry data about general usage. | ||
# Learn more here: https://nextjs.org/telemetry | ||
# Uncomment the following line in case you want to disable telemetry during the build. | ||
# ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
RUN corepack enable pnpm && pnpm run build | ||
|
||
# Production image, copy all the files and run next | ||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
ENV NODE_ENV=production | ||
# Uncomment the following line in case you want to disable telemetry during runtime. | ||
# ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
|
||
COPY --from=builder /app/public ./public | ||
|
||
# Set the correct permission for prerender cache | ||
RUN mkdir .next | ||
RUN chown nextjs:nodejs .next | ||
|
||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | ||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | ||
|
||
USER nextjs | ||
|
||
EXPOSE 3000 | ||
|
||
ENV PORT=3000 | ||
|
||
# server.js is created by next build from the standalone output | ||
# https://nextjs.org/docs/pages/api-reference/next-config-js/output | ||
ENV HOSTNAME="0.0.0.0" | ||
CMD ["node", "server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$schema": "https://ui.shadcn.com/schema.json", | ||
"style": "new-york", | ||
"rsc": true, | ||
"tsx": true, | ||
"tailwind": { | ||
"config": "tailwind.config.ts", | ||
"css": "src/styles/tailwind.css", | ||
"baseColor": "zinc", | ||
"cssVariables": true, | ||
"prefix": "" | ||
}, | ||
"aliases": { | ||
"components": "@/components", | ||
"utils": "@/lib/utils", | ||
"ui": "@/components/ui", | ||
"lib": "@/lib", | ||
"hooks": "@/hooks" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {} | ||
const nextConfig = { | ||
output: 'standalone', | ||
} | ||
|
||
export default nextConfig |
Oops, something went wrong.