forked from YJU-OKURA/project_minori-next-deployment-repo
-
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.
✨ feat: add Docker Next.js server setup and CI/CD pipeline
- Dockerfile: Add Dockerfile with standalone output for Next.js server. - next.config.js: Enable standalone output for efficient Docker builds. - package.json: Update `postinstall` script to conditionally install Husky. - ci.yml: Add new CI/CD pipeline for building and deploying to Amazon ECR. Related issue: YJU-OKURA#36
- Loading branch information
Showing
4 changed files
with
78 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Deploy to ECR | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
name: Build Image | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} | ||
aws-region: ap-northeast-2 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
run: | | ||
docker build -t minori-next . | ||
docker tag minori-next:latest 233629834663.dkr.ecr.us-east-1.amazonaws.com/minori-next:latest | ||
docker push 233629834663.dkr.ecr.us-east-1.amazonaws.com/minori-next:latest |
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,45 @@ | ||
# Base image | ||
FROM node:20-alpine AS base | ||
|
||
# Dependencies stage | ||
FROM base AS deps | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /src/app | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install --frozen-lockfile | ||
|
||
# Builder stage | ||
FROM base AS builder | ||
WORKDIR /src/app | ||
COPY --from=deps /src/app/node_modules ./node_modules | ||
COPY . . | ||
RUN yarn build | ||
|
||
# Final production image | ||
FROM base AS runner | ||
WORKDIR /src/app | ||
|
||
ENV NODE_ENV=production | ||
|
||
RUN addgroup --system --gid 1001 nodejs \ | ||
&& adduser --system --uid 1001 nextjs | ||
|
||
# Copy Next.js build output | ||
COPY --from=builder /src/app/public ./public | ||
COPY --from=builder /src/app/.next/standalone ./ | ||
COPY --from=builder /src/app/.next/static ./.next/static | ||
|
||
# Copy additional necessary files | ||
COPY --from=builder /src/app/package.json ./package.json | ||
COPY --from=builder /src/app/yarn.lock ./yarn.lock | ||
|
||
# Install production-only dependencies while ignoring optional ones | ||
RUN yarn install --frozen-lockfile --production --ignore-optional | ||
|
||
USER nextjs | ||
|
||
EXPOSE 3000 | ||
|
||
ENV PORT 3000 | ||
|
||
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 |
---|---|---|
|
@@ -17,4 +17,5 @@ module.exports = { | |
], | ||
}, | ||
reactStrictMode: false, | ||
output: 'standalone', | ||
}; |
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