From e182ae339f16cd7644843b85802a5adf7eff7e18 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 15:34:14 +0900 Subject: [PATCH 01/49] =?UTF-8?q?chore:=20.env=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 3e56e601..f3283ba4 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -19,7 +19,7 @@ jobs: node-version: '18' - run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.local + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production env: SECRETS_CONTEXT: ${{ toJson(secrets) }} From 8b836d2706ee270d9e2b99f6cea769d9c83eae9b Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 16:07:40 +0900 Subject: [PATCH 02/49] =?UTF-8?q?chore:=20env=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index d90312e8..4bed835f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,8 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . +COPY .env.production .env.production + RUN \ if [ -f yarn.lock ]; then yarn run build; \ else echo "Lockfile not found." && exit 1; \ From 80aec88f0d690f92a4ed0c48b033800238d1dc4d Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 16:37:20 +0900 Subject: [PATCH 03/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index f3283ba4..3f4e2b56 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -19,7 +19,7 @@ jobs: node-version: '18' - run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + jecho "${{ secrets.ENV_PRODUCTION }}" > .env.production env: SECRETS_CONTEXT: ${{ toJson(secrets) }} From 21a6955105e371709d6f420c3ca41ef48ffb550a Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 16:40:03 +0900 Subject: [PATCH 04/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 3f4e2b56..bc1fabf7 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -20,8 +20,7 @@ jobs: - run: | jecho "${{ secrets.ENV_PRODUCTION }}" > .env.production - env: - SECRETS_CONTEXT: ${{ toJson(secrets) }} + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 From 3d3aca6a8edbc58754fe057ea1b58e6a2f95fa69 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 16:40:19 +0900 Subject: [PATCH 05/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index bc1fabf7..e7d5fb58 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -19,7 +19,7 @@ jobs: node-version: '18' - run: | - jecho "${{ secrets.ENV_PRODUCTION }}" > .env.production + echo "${{ secrets.ENV_PRODUCTION }}" > .env.production - name: Configure AWS credentials From 3a1ed8c74f88f39b4ce9e4be62b324decb2f36d5 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 16:59:20 +0900 Subject: [PATCH 06/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index e7d5fb58..32a6f0e2 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -17,7 +17,6 @@ jobs: uses: actions/setup-node@v2 with: node-version: '18' - - run: | echo "${{ secrets.ENV_PRODUCTION }}" > .env.production From 7ccf0e549a5557fc5eaa74655677336127b349a8 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 17:11:10 +0900 Subject: [PATCH 07/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 121 ++++++++++++++++------------------- 1 file changed, 55 insertions(+), 66 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 32a6f0e2..dce980ef 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -1,66 +1,55 @@ -name: CD-AWS Test - -on: - push: - branches: - - main - -jobs: - Deploy-Production: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Set up Node.js environment - uses: actions/setup-node@v2 - with: - node-version: '18' - - run: | - echo "${{ secrets.ENV_PRODUCTION }}" > .env.production - - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v3 - 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@v2 - - - name: Build, tag, and push docker image to Amazon ECR - env: - REGISTRY: ${{ steps.login-ecr.outputs.registry }} - REPOSITORY: washfit-client - IMAGE_TAG: latest - run: | - docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . - docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - - - name: Application Run - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.AWS_EC2_HOST }} - username: ${{ secrets.AWS_USERNAME }} - key: ${{ secrets.AWS_KEY}} - script: | - # Install Docker and Docker Compose - sudo dnf update - sudo dnf install docker - sudo systemctl start docker - sudo systemctl enable docker - sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - sudo chmod +x /usr/local/bin/docker-compose - - # Docker Compose - mkdir -p deploy - cd deploy - echo "${{ secrets.DOCKER_COMPOSE_AWS }}" > docker-compose.yml - - docker-compose pull - docker-compose down - docker-compose up -d \ No newline at end of file +FROM node:18-alpine AS base + +FROM base AS deps + +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# 종속성 복사와 패키지 설치 +COPY package.json yarn.lock* ./ +RUN \ + if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ + else echo "Lockfile not found." && exit 1; \ + fi + +# 소스 코드 복사 +COPY . . + +FROM base AS builder + +WORKDIR /app + +# 종속성 복사 +COPY --from=deps /app/node_modules ./node_modules + +# 소스 코드 빌드 +RUN \ + if [ -f yarn.lock ]; then yarn run build; \ + else echo "Lockfile not found." && exit 1; \ + fi + +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +RUN mkdir .next +RUN chown nextjs:nodejs .next + +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 + +ENV HOSTNAME "0.0.0.0" + +CMD ["node", "server.js"] \ No newline at end of file From 1210c3cffd221a295180d2ae5ec0ac9af69b1962 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 17:22:32 +0900 Subject: [PATCH 08/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index dce980ef..833152fc 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -5,24 +5,21 @@ FROM base AS deps RUN apk add --no-cache libc6-compat WORKDIR /app -# 종속성 복사와 패키지 설치 COPY package.json yarn.lock* ./ RUN \ if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ else echo "Lockfile not found." && exit 1; \ fi - -# 소스 코드 복사 COPY . . FROM base AS builder WORKDIR /app -# 종속성 복사 COPY --from=deps /app/node_modules ./node_modules -# 소스 코드 빌드 +COPY .env.production .env.production + RUN \ if [ -f yarn.lock ]; then yarn run build; \ else echo "Lockfile not found." && exit 1; \ From ae1ee317f52a29c690f00518a1662b0596969a93 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 18:22:09 +0900 Subject: [PATCH 09/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 120 ++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 52 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 833152fc..f3283ba4 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -1,52 +1,68 @@ -FROM node:18-alpine AS base - -FROM base AS deps - -RUN apk add --no-cache libc6-compat -WORKDIR /app - -COPY package.json yarn.lock* ./ -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - else echo "Lockfile not found." && exit 1; \ - fi -COPY . . - -FROM base AS builder - -WORKDIR /app - -COPY --from=deps /app/node_modules ./node_modules - -COPY .env.production .env.production - -RUN \ - if [ -f yarn.lock ]; then yarn run build; \ - else echo "Lockfile not found." && exit 1; \ - fi - -FROM base AS runner -WORKDIR /app - -ENV NODE_ENV production - -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs - -COPY --from=builder /app/public ./public - -RUN mkdir .next -RUN chown nextjs:nodejs .next - -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 - -ENV HOSTNAME "0.0.0.0" - -CMD ["node", "server.js"] \ No newline at end of file +name: CD-AWS Test + +on: + push: + branches: + - main + +jobs: + Deploy-Production: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Node.js environment + uses: actions/setup-node@v2 + with: + node-version: '18' + + - run: | + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + env: + SECRETS_CONTEXT: ${{ toJson(secrets) }} + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v3 + 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@v2 + + - name: Build, tag, and push docker image to Amazon ECR + env: + REGISTRY: ${{ steps.login-ecr.outputs.registry }} + REPOSITORY: washfit-client + IMAGE_TAG: latest + run: | + docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + + - name: Application Run + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.AWS_EC2_HOST }} + username: ${{ secrets.AWS_USERNAME }} + key: ${{ secrets.AWS_KEY}} + script: | + # Install Docker and Docker Compose + sudo dnf update + sudo dnf install docker + sudo systemctl start docker + sudo systemctl enable docker + sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + + # Docker Compose + mkdir -p deploy + cd deploy + echo "${{ secrets.DOCKER_COMPOSE_AWS }}" > docker-compose.yml + + docker-compose pull + docker-compose down + docker-compose up -d \ No newline at end of file From 1ffa4925dd9dd40ed3f382c5f2a622bf4ff61823 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 20:14:34 +0900 Subject: [PATCH 10/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4bed835f..07976445 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -COPY .env.production .env.production +COPY .env.production /app/.env.production RUN \ if [ -f yarn.lock ]; then yarn run build; \ From 48f6489f6d4e85e9dd70346aedffe0fb4fe7c8c7 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 20:22:02 +0900 Subject: [PATCH 11/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 07976445..5ebfc387 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,13 +18,13 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -COPY .env.production /app/.env.production - RUN \ if [ -f yarn.lock ]; then yarn run build; \ else echo "Lockfile not found." && exit 1; \ fi +COPY .env.production /app/.env.production + FROM base AS runner WORKDIR /app @@ -49,4 +49,4 @@ ENV PORT 3000 ENV HOSTNAME "0.0.0.0" -CMD ["node", "server.js"] \ No newline at end of file +CMD ["node", "server.js"] From 26718993b2a213571c4d3321f122b9ee1d3584ed Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 20:27:59 +0900 Subject: [PATCH 12/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5ebfc387..6d6d5055 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,6 @@ RUN \ else echo "Lockfile not found." && exit 1; \ fi -COPY .env.production /app/.env.production - FROM base AS runner WORKDIR /app @@ -41,12 +39,16 @@ RUN chown nextjs:nodejs .next 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.production 파일을 환경 변수로 설정 +ARG NODE_ENV=production +ARG HOSTNAME=0.0.0.0 +ARG PORT=3000 +ENV NODE_ENV $NODE_ENV +ENV HOSTNAME $HOSTNAME +ENV PORT $PORT -ENV PORT 3000 +USER nextjs -ENV HOSTNAME "0.0.0.0" +EXPOSE $PORT CMD ["node", "server.js"] From cf5fe9e7d89d5db8b06f9ab85427c010b1c83e1e Mon Sep 17 00:00:00 2001 From: bottlewook Date: Fri, 23 Feb 2024 20:33:26 +0900 Subject: [PATCH 13/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index f3283ba4..bb574748 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -40,7 +40,7 @@ jobs: REPOSITORY: washfit-client IMAGE_TAG: latest run: | - docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: Application Run @@ -65,4 +65,4 @@ jobs: docker-compose pull docker-compose down - docker-compose up -d \ No newline at end of file + docker-compose up -d From 846f45130218e319456a6380b1d8b6c60e0afeb7 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 11:02:17 +0900 Subject: [PATCH 14/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index bb574748..aedbf49f 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -19,7 +19,7 @@ jobs: node-version: '18' - run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env env: SECRETS_CONTEXT: ${{ toJson(secrets) }} From 9a61b3a2b651138c85d6f71d4d44ad857c912a49 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 13:05:06 +0900 Subject: [PATCH 15/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 65 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d6d5055..204f521a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,54 @@ -FROM node:18-alpine AS base - -FROM base AS deps +# Multi-stage build +# 1단계: 환경 설정 및 dependancy 설치 +FROM node:18-alpine AS deps RUN apk add --no-cache libc6-compat + +# 명령어를 실행할 디렉터리 지정 WORKDIR /app -COPY package.json yarn.lock* ./ -RUN \ - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ - else echo "Lockfile not found." && exit 1; \ - fi +# Dependancy install을 위해 package.json, package-lock.json, yarn.lock 복사 +COPY package.json yarn.lock* ./ + +# Dependancy 설치 (새로운 lock 파일 수정 또는 생성 방지) +RUN yarn --frozen-lockfile + +########################################################### -FROM base AS builder +# 2단계: next.js 빌드 단계 +FROM node:18-alpine AS builder +# Docker를 build할때 개발 모드 구분용 환경 변수를 명시함 +ARG ENV_MODE + +# 명령어를 실행할 디렉터리 지정 WORKDIR /app +# node_modules 등의 dependancy를 복사함. COPY --from=deps /app/node_modules ./node_modules COPY . . -RUN \ - if [ -f yarn.lock ]; then yarn run build; \ - else echo "Lockfile not found." && exit 1; \ - fi +# 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. +COPY .env.$ENV_MODE .env.production +RUN yarn build + +########################################################### + +# 3단계: next.js 실행 단계 +FROM node:18-alpine AS runner -FROM base AS runner +# 명령어를 실행할 디렉터리 지정 WORKDIR /app ENV NODE_ENV production +# container 환경에 시스템 사용자를 추가함 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs +# next.config.js에서 output을 standalone으로 설정하면 +# 빌드에 필요한 최소한의 파일만 ./next/standalone로 출력이 된다. +# standalone 결과물에는 public 폴더와 static 폴더 내용은 포함되지 않으므로, 따로 복사를 해준다. COPY --from=builder /app/public ./public RUN mkdir .next @@ -39,16 +57,15 @@ RUN chown nextjs:nodejs .next COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static -# .env.production 파일을 환경 변수로 설정 -ARG NODE_ENV=production -ARG HOSTNAME=0.0.0.0 -ARG PORT=3000 -ENV NODE_ENV $NODE_ENV -ENV HOSTNAME $HOSTNAME -ENV PORT $PORT +# 컨테이너의 수신 대기 포트를 3000으로 설정 +EXPOSE 3000 -USER nextjs +ENV PORT 3000 +# set hostname to localhost +ENV HOSTNAME "0.0.0.0" -EXPOSE $PORT +# node로 애플리케이션 실행 +CMD ["node", "server.js"] -CMD ["node", "server.js"] +# standalone으로 나온 결과값은 node 자체적으로만 실행 가능 +# CMD ["npm", "start"] \ No newline at end of file From bce172e927971d9b9cc0109810e65939ef647833 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 13:08:11 +0900 Subject: [PATCH 16/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index aedbf49f..b99b6bc3 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -40,7 +40,7 @@ jobs: REPOSITORY: washfit-client IMAGE_TAG: latest run: | - docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . --build-arg ENV_MODE=production docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: Application Run From 38a20799d25172ef16f2ad43229d358c24830af8 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 13:10:22 +0900 Subject: [PATCH 17/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- Dockerfile | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index b99b6bc3..aedbf49f 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -40,7 +40,7 @@ jobs: REPOSITORY: washfit-client IMAGE_TAG: latest run: | - docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . --build-arg ENV_MODE=production + docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: Application Run diff --git a/Dockerfile b/Dockerfile index 204f521a..eed1a067 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,6 @@ COPY --from=deps /app/node_modules ./node_modules COPY . . # 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. -COPY .env.$ENV_MODE .env.production RUN yarn build ########################################################### @@ -60,10 +59,6 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # 컨테이너의 수신 대기 포트를 3000으로 설정 EXPOSE 3000 -ENV PORT 3000 -# set hostname to localhost -ENV HOSTNAME "0.0.0.0" - # node로 애플리케이션 실행 CMD ["node", "server.js"] From 68f1bd24d47112416e926d2df5b935465191666f Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 13:30:58 +0900 Subject: [PATCH 18/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index aedbf49f..cf19e0ae 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -12,16 +12,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - - name: Set up Node.js environment - uses: actions/setup-node@v2 - with: - node-version: '18' - - - run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env - env: - SECRETS_CONTEXT: ${{ toJson(secrets) }} - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 From ec8210d00c1fa0fa4f861a8fdff5df8e0236116d Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 13:46:55 +0900 Subject: [PATCH 19/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index eed1a067..33f55dc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,6 +53,7 @@ COPY --from=builder /app/public ./public RUN mkdir .next RUN chown nextjs:nodejs .next +COPY --from=builder --chown=nextjs:nodejs /app/.env.production.local ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static From 6d47979b0c5fdb43bdc3eb48654392eb5e716417 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 14:02:08 +0900 Subject: [PATCH 20/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 33f55dc9..700ec471 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,7 +53,7 @@ COPY --from=builder /app/public ./public RUN mkdir .next RUN chown nextjs:nodejs .next -COPY --from=builder --chown=nextjs:nodejs /app/.env.production.local ./ +COPY --from=builder /app/.env.production ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static From 01776d9eee8d8136e5b6e69fe2f76658966b0401 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 14:27:56 +0900 Subject: [PATCH 21/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- Dockerfile | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index cf19e0ae..ae30dbcb 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -30,7 +30,7 @@ jobs: REPOSITORY: washfit-client IMAGE_TAG: latest run: | - docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker build --no-cache -t --build-arg ENV_MODE=production $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: Application Run diff --git a/Dockerfile b/Dockerfile index 700ec471..6a468610 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,10 @@ FROM node:18-alpine AS deps RUN apk add --no-cache libc6-compat # 명령어를 실행할 디렉터리 지정 -WORKDIR /app +WORKDIR /usr/src/app # Dependancy install을 위해 package.json, package-lock.json, yarn.lock 복사 -COPY package.json yarn.lock* ./ +COPY package.json yarn.lock ./ # Dependancy 설치 (새로운 lock 파일 수정 또는 생성 방지) RUN yarn --frozen-lockfile @@ -22,13 +22,14 @@ FROM node:18-alpine AS builder ARG ENV_MODE # 명령어를 실행할 디렉터리 지정 -WORKDIR /app +WORKDIR /usr/src/app # node_modules 등의 dependancy를 복사함. -COPY --from=deps /app/node_modules ./node_modules +COPY --from=deps /usr/src/app/node_modules ./node_modules COPY . . # 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. +COPY .env.$ENV_MODE ./.env.production RUN yarn build ########################################################### @@ -37,10 +38,8 @@ RUN yarn build FROM node:18-alpine AS runner # 명령어를 실행할 디렉터리 지정 -WORKDIR /app - -ENV NODE_ENV production - +WORKDIR /usr/src/app + # container 환경에 시스템 사용자를 추가함 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs @@ -48,14 +47,9 @@ RUN adduser --system --uid 1001 nextjs # next.config.js에서 output을 standalone으로 설정하면 # 빌드에 필요한 최소한의 파일만 ./next/standalone로 출력이 된다. # standalone 결과물에는 public 폴더와 static 폴더 내용은 포함되지 않으므로, 따로 복사를 해준다. -COPY --from=builder /app/public ./public - -RUN mkdir .next -RUN chown nextjs:nodejs .next - -COPY --from=builder /app/.env.production ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder /usr/src/app/public ./public +COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/static ./.next/static # 컨테이너의 수신 대기 포트를 3000으로 설정 EXPOSE 3000 From 3d33ea603872e5721e3dc18d9c4acc2cf55185f4 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 14:29:44 +0900 Subject: [PATCH 22/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- Dockerfile | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index ae30dbcb..cf19e0ae 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -30,7 +30,7 @@ jobs: REPOSITORY: washfit-client IMAGE_TAG: latest run: | - docker build --no-cache -t --build-arg ENV_MODE=production $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: Application Run diff --git a/Dockerfile b/Dockerfile index 6a468610..dd496658 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,6 @@ RUN yarn --frozen-lockfile # 2단계: next.js 빌드 단계 FROM node:18-alpine AS builder -# Docker를 build할때 개발 모드 구분용 환경 변수를 명시함 -ARG ENV_MODE - # 명령어를 실행할 디렉터리 지정 WORKDIR /usr/src/app @@ -29,7 +26,6 @@ COPY --from=deps /usr/src/app/node_modules ./node_modules COPY . . # 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. -COPY .env.$ENV_MODE ./.env.production RUN yarn build ########################################################### From 432f85739e4b1b349ea4d2ad8054d62031641e4e Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 15:58:53 +0900 Subject: [PATCH 23/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index cf19e0ae..2c3c55d6 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -33,6 +33,10 @@ jobs: docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG + - name: ECR Login + run: | + aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com + - name: Application Run uses: appleboy/ssh-action@v1.0.3 with: From 7480b9bbe6785618589bfe22f715de8c336e536c Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 16:18:35 +0900 Subject: [PATCH 24/49] =?UTF-8?q?chore:=20dockerfile=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index dd496658..d7db9328 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM node:18-alpine AS deps RUN apk add --no-cache libc6-compat # 명령어를 실행할 디렉터리 지정 -WORKDIR /usr/src/app +WORKDIR /app # Dependancy install을 위해 package.json, package-lock.json, yarn.lock 복사 COPY package.json yarn.lock ./ @@ -18,14 +18,18 @@ RUN yarn --frozen-lockfile # 2단계: next.js 빌드 단계 FROM node:18-alpine AS builder +# Docker를 build할때 개발 모드 구분용 환경 변수를 명시함 +ARG ENV_MODE + # 명령어를 실행할 디렉터리 지정 -WORKDIR /usr/src/app +WORKDIR /app # node_modules 등의 dependancy를 복사함. -COPY --from=deps /usr/src/app/node_modules ./node_modules +COPY --from=deps /app/node_modules ./node_modules COPY . . # 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. +COPY .env.$ENV_MODE .env.production RUN yarn build ########################################################### @@ -34,8 +38,8 @@ RUN yarn build FROM node:18-alpine AS runner # 명령어를 실행할 디렉터리 지정 -WORKDIR /usr/src/app - +WORKDIR /app + # container 환경에 시스템 사용자를 추가함 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs @@ -43,9 +47,9 @@ RUN adduser --system --uid 1001 nextjs # next.config.js에서 output을 standalone으로 설정하면 # 빌드에 필요한 최소한의 파일만 ./next/standalone로 출력이 된다. # standalone 결과물에는 public 폴더와 static 폴더 내용은 포함되지 않으므로, 따로 복사를 해준다. -COPY --from=builder /usr/src/app/public ./public -COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/static ./.next/static +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # 컨테이너의 수신 대기 포트를 3000으로 설정 EXPOSE 3000 From e2ecf1ad8d731986530435755709dbd13703752a Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 16:20:51 +0900 Subject: [PATCH 25/49] =?UTF-8?q?chore:=20dockerfile=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 2c3c55d6..9749fe9f 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -30,7 +30,7 @@ jobs: REPOSITORY: washfit-client IMAGE_TAG: latest run: | - docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker build --no-cache -t --build-arg ENV_MODE=production $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: ECR Login From c44a569c67bea6353e5675330968afabe5038d64 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 16:22:25 +0900 Subject: [PATCH 26/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- Dockerfile | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 9749fe9f..2c3c55d6 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -30,7 +30,7 @@ jobs: REPOSITORY: washfit-client IMAGE_TAG: latest run: | - docker build --no-cache -t --build-arg ENV_MODE=production $REGISTRY/$REPOSITORY:$IMAGE_TAG . + docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - name: ECR Login diff --git a/Dockerfile b/Dockerfile index d7db9328..25e83813 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,6 @@ RUN yarn --frozen-lockfile # 2단계: next.js 빌드 단계 FROM node:18-alpine AS builder -# Docker를 build할때 개발 모드 구분용 환경 변수를 명시함 -ARG ENV_MODE - # 명령어를 실행할 디렉터리 지정 WORKDIR /app @@ -28,8 +25,6 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -# 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. -COPY .env.$ENV_MODE .env.production RUN yarn build ########################################################### From 9eda5d384453272b6f3c0a2b62aa74f125271dd5 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 16:44:04 +0900 Subject: [PATCH 27/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 2c3c55d6..b582a5f7 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -37,6 +37,11 @@ jobs: run: | aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com + run: | + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + env: + SECRETS_CONTEXT: ${{ toJson(secrets) }} + - name: Application Run uses: appleboy/ssh-action@v1.0.3 with: From bddcf56bd501d71748a11d2a8eecb1148a64097e Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 16:44:56 +0900 Subject: [PATCH 28/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index b582a5f7..62aa92b9 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -36,8 +36,6 @@ jobs: - name: ECR Login run: | aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - - run: | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production env: SECRETS_CONTEXT: ${{ toJson(secrets) }} From 35f11deccf4922cd8769d8ed157ae23e554d01f6 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 16:51:55 +0900 Subject: [PATCH 29/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 62aa92b9..029f4122 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -36,7 +36,7 @@ jobs: - name: ECR Login run: | aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > ENV.PRODUCTION env: SECRETS_CONTEXT: ${{ toJson(secrets) }} From b3b7c50a4ebf83fc4c150a256060bfd8eb08289d Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:00:30 +0900 Subject: [PATCH 30/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 3 --- Dockerfile | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 029f4122..16c7198b 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -36,9 +36,6 @@ jobs: - name: ECR Login run: | aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > ENV.PRODUCTION - env: - SECRETS_CONTEXT: ${{ toJson(secrets) }} - name: Application Run uses: appleboy/ssh-action@v1.0.3 diff --git a/Dockerfile b/Dockerfile index 25e83813..5411c56a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,8 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . +COPY .env.production .env.production + RUN yarn build ########################################################### From e32d9c29db87f435398a166bfdf1974ceeb5f363 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:05:31 +0900 Subject: [PATCH 31/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 7 +++++++ Dockerfile | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 16c7198b..248a75a1 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -12,6 +12,13 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + + - name: Set up Node.js environment + uses: actions/setup-node@v2 + with: + node-version: '18' + run: | + echo "${{ secrets.ENV_PRODUCTION }}" > .env.production - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 diff --git a/Dockerfile b/Dockerfile index 5411c56a..25e83813 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,8 +25,6 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -COPY .env.production .env.production - RUN yarn build ########################################################### From 4d9e6e54a0ae5e6d634220232ee60abac8db1ead Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:08:07 +0900 Subject: [PATCH 32/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 248a75a1..d3f5ab9e 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -20,6 +20,7 @@ jobs: run: | echo "${{ secrets.ENV_PRODUCTION }}" > .env.production + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 with: From 362df187ff218c21134dad3b0698c25b641e0255 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:11:07 +0900 Subject: [PATCH 33/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index d3f5ab9e..be4581be 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -17,10 +17,10 @@ jobs: uses: actions/setup-node@v2 with: node-version: '18' + run: | echo "${{ secrets.ENV_PRODUCTION }}" > .env.production - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 with: From bd261899d3a281b39cdd9fcb4e6b9ee87aa58626 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:11:48 +0900 Subject: [PATCH 34/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index be4581be..56282a13 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -14,10 +14,8 @@ jobs: uses: actions/checkout@v3 - name: Set up Node.js environment - uses: actions/setup-node@v2 with: node-version: '18' - run: | echo "${{ secrets.ENV_PRODUCTION }}" > .env.production From bad2c55a835731b2068333cf0ed99c9760b30efa Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:18:12 +0900 Subject: [PATCH 35/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 56282a13..3e3c6dd6 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -14,11 +14,14 @@ jobs: uses: actions/checkout@v3 - name: Set up Node.js environment + uses: actions/checkout@v3 with: node-version: '18' - run: | + - run: | echo "${{ secrets.ENV_PRODUCTION }}" > .env.production - + env: | + SECRETS_CONTEXT: ${{ toJSON(secrets) }} + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 with: From c7de1610553e62970baf8a2c93e302f856336522 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:18:30 +0900 Subject: [PATCH 36/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 3e3c6dd6..f7432ab6 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -20,7 +20,7 @@ jobs: - run: | echo "${{ secrets.ENV_PRODUCTION }}" > .env.production env: | - SECRETS_CONTEXT: ${{ toJSON(secrets) }} + SECRETS_CONTEXT: ${{ toJSON(secrets) }} - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 From 784608421f779f7f13fb45baf1d1d823ee926405 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 17:28:47 +0900 Subject: [PATCH 37/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index f7432ab6..7731bc1f 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -19,8 +19,6 @@ jobs: node-version: '18' - run: | echo "${{ secrets.ENV_PRODUCTION }}" > .env.production - env: | - SECRETS_CONTEXT: ${{ toJSON(secrets) }} - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 From 057e706013fd5d6b3f3746fcf0539e6f5e4116f1 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 18:04:48 +0900 Subject: [PATCH 38/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 7731bc1f..943e2215 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -13,12 +13,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Node.js environment - uses: actions/checkout@v3 - with: - node-version: '18' - - run: | - echo "${{ secrets.ENV_PRODUCTION }}" > .env.production + - name: Create .env file + run: | + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + env: + SECRETS_CONTEXT: ${{ toJson(secrets) }} - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 From afd9ff058504b5c191c3f660c6faee882ba4a4b0 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 18:34:48 +0900 Subject: [PATCH 39/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 16 ++++++++++------ Dockerfile | 12 +++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 943e2215..30549de6 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -13,12 +13,16 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Create .env file - run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + - name: Set up Node.js environment + uses: actions/setup-node@v2 + with: + node-version: '18' + + - run: | + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env env: SECRETS_CONTEXT: ${{ toJson(secrets) }} - + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 with: @@ -42,7 +46,7 @@ jobs: - name: ECR Login run: | aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - + - name: Application Run uses: appleboy/ssh-action@v1.0.3 with: @@ -65,4 +69,4 @@ jobs: docker-compose pull docker-compose down - docker-compose up -d + docker-compose up -d \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 25e83813..eed1a067 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apk add --no-cache libc6-compat WORKDIR /app # Dependancy install을 위해 package.json, package-lock.json, yarn.lock 복사 -COPY package.json yarn.lock ./ +COPY package.json yarn.lock* ./ # Dependancy 설치 (새로운 lock 파일 수정 또는 생성 방지) RUN yarn --frozen-lockfile @@ -18,6 +18,9 @@ RUN yarn --frozen-lockfile # 2단계: next.js 빌드 단계 FROM node:18-alpine AS builder +# Docker를 build할때 개발 모드 구분용 환경 변수를 명시함 +ARG ENV_MODE + # 명령어를 실행할 디렉터리 지정 WORKDIR /app @@ -25,6 +28,7 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . +# 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. RUN yarn build ########################################################### @@ -35,6 +39,8 @@ FROM node:18-alpine AS runner # 명령어를 실행할 디렉터리 지정 WORKDIR /app +ENV NODE_ENV production + # container 환경에 시스템 사용자를 추가함 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs @@ -43,6 +49,10 @@ RUN adduser --system --uid 1001 nextjs # 빌드에 필요한 최소한의 파일만 ./next/standalone로 출력이 된다. # standalone 결과물에는 public 폴더와 static 폴더 내용은 포함되지 않으므로, 따로 복사를 해준다. COPY --from=builder /app/public ./public + +RUN mkdir .next +RUN chown nextjs:nodejs .next + COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static From 8b19f3f35262153387a865c643121af8e2963f85 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 18:38:56 +0900 Subject: [PATCH 40/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 30549de6..3972b91f 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -43,9 +43,9 @@ jobs: docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - - name: ECR Login - run: | - aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com + # - name: ECR Login + # run: | + # aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - name: Application Run uses: appleboy/ssh-action@v1.0.3 From 6b5479c77fa5e0169c785e62f64a736f15aed2d4 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 18:59:06 +0900 Subject: [PATCH 41/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 16 +++------------- Dockerfile | 27 +++++++++------------------ 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 3972b91f..1c426075 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -12,16 +12,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - - - name: Set up Node.js environment - uses: actions/setup-node@v2 - with: - node-version: '18' - - - run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env - env: - SECRETS_CONTEXT: ${{ toJson(secrets) }} - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v3 @@ -43,9 +33,9 @@ jobs: docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - # - name: ECR Login - # run: | - # aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com + - name: ECR Login + run: | + aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - name: Application Run uses: appleboy/ssh-action@v1.0.3 diff --git a/Dockerfile b/Dockerfile index eed1a067..dd496658 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,10 @@ FROM node:18-alpine AS deps RUN apk add --no-cache libc6-compat # 명령어를 실행할 디렉터리 지정 -WORKDIR /app +WORKDIR /usr/src/app # Dependancy install을 위해 package.json, package-lock.json, yarn.lock 복사 -COPY package.json yarn.lock* ./ +COPY package.json yarn.lock ./ # Dependancy 설치 (새로운 lock 파일 수정 또는 생성 방지) RUN yarn --frozen-lockfile @@ -18,14 +18,11 @@ RUN yarn --frozen-lockfile # 2단계: next.js 빌드 단계 FROM node:18-alpine AS builder -# Docker를 build할때 개발 모드 구분용 환경 변수를 명시함 -ARG ENV_MODE - # 명령어를 실행할 디렉터리 지정 -WORKDIR /app +WORKDIR /usr/src/app # node_modules 등의 dependancy를 복사함. -COPY --from=deps /app/node_modules ./node_modules +COPY --from=deps /usr/src/app/node_modules ./node_modules COPY . . # 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. @@ -37,10 +34,8 @@ RUN yarn build FROM node:18-alpine AS runner # 명령어를 실행할 디렉터리 지정 -WORKDIR /app - -ENV NODE_ENV production - +WORKDIR /usr/src/app + # container 환경에 시스템 사용자를 추가함 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs @@ -48,13 +43,9 @@ RUN adduser --system --uid 1001 nextjs # next.config.js에서 output을 standalone으로 설정하면 # 빌드에 필요한 최소한의 파일만 ./next/standalone로 출력이 된다. # standalone 결과물에는 public 폴더와 static 폴더 내용은 포함되지 않으므로, 따로 복사를 해준다. -COPY --from=builder /app/public ./public - -RUN mkdir .next -RUN chown nextjs:nodejs .next - -COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder /usr/src/app/public ./public +COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/static ./.next/static # 컨테이너의 수신 대기 포트를 3000으로 설정 EXPOSE 3000 From 0082db8492615667dbf4f3cac5dd43d2d7012646 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 19:15:48 +0900 Subject: [PATCH 42/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 5 ++++- Dockerfile | 17 ++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 1c426075..3eba02b6 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -36,7 +36,10 @@ jobs: - name: ECR Login run: | aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production + env: + SECRETS_CONTEXT: ${{ toJson(secrets) }} + - name: Application Run uses: appleboy/ssh-action@v1.0.3 with: diff --git a/Dockerfile b/Dockerfile index dd496658..25e83813 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM node:18-alpine AS deps RUN apk add --no-cache libc6-compat # 명령어를 실행할 디렉터리 지정 -WORKDIR /usr/src/app +WORKDIR /app # Dependancy install을 위해 package.json, package-lock.json, yarn.lock 복사 COPY package.json yarn.lock ./ @@ -19,13 +19,12 @@ RUN yarn --frozen-lockfile FROM node:18-alpine AS builder # 명령어를 실행할 디렉터리 지정 -WORKDIR /usr/src/app +WORKDIR /app # node_modules 등의 dependancy를 복사함. -COPY --from=deps /usr/src/app/node_modules ./node_modules +COPY --from=deps /app/node_modules ./node_modules COPY . . -# 구축 환경에 따라 env 변수를 다르게 가져가야 하는 경우 환경 변수를 이용해서 env를 구분해준다. RUN yarn build ########################################################### @@ -34,8 +33,8 @@ RUN yarn build FROM node:18-alpine AS runner # 명령어를 실행할 디렉터리 지정 -WORKDIR /usr/src/app - +WORKDIR /app + # container 환경에 시스템 사용자를 추가함 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs @@ -43,9 +42,9 @@ RUN adduser --system --uid 1001 nextjs # next.config.js에서 output을 standalone으로 설정하면 # 빌드에 필요한 최소한의 파일만 ./next/standalone로 출력이 된다. # standalone 결과물에는 public 폴더와 static 폴더 내용은 포함되지 않으므로, 따로 복사를 해준다. -COPY --from=builder /usr/src/app/public ./public -COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/standalone ./ -COPY --from=builder --chown=nextjs:nodejs /usr/src/app/.next/static ./.next/static +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # 컨테이너의 수신 대기 포트를 3000으로 설정 EXPOSE 3000 From 6d3447877cdde56bdebe2834100712acb24927de Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 19:34:29 +0900 Subject: [PATCH 43/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 25e83813..892284e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,8 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # 컨테이너의 수신 대기 포트를 3000으로 설정 EXPOSE 3000 +ENV PORT 3000 + # node로 애플리케이션 실행 CMD ["node", "server.js"] From 52fc86b952918ae9f2c44174c305fd21bbf7bee7 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Mon, 26 Feb 2024 19:47:55 +0900 Subject: [PATCH 44/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 3eba02b6..7b9c7550 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -33,13 +33,6 @@ jobs: docker build --no-cache -t $REGISTRY/$REPOSITORY:$IMAGE_TAG . docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG - - name: ECR Login - run: | - aws ecr get-login-password | docker login --username AWS --password-stdin 654654231595.dkr.ecr.ap-northeast-2.amazonaws.com - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production - env: - SECRETS_CONTEXT: ${{ toJson(secrets) }} - - name: Application Run uses: appleboy/ssh-action@v1.0.3 with: From 7f91d754ef2560441a42068d38625fa9bd0d5bef Mon Sep 17 00:00:00 2001 From: bottlewook Date: Tue, 27 Feb 2024 02:11:57 +0900 Subject: [PATCH 45/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 892284e4..25e83813 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,8 +49,6 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # 컨테이너의 수신 대기 포트를 3000으로 설정 EXPOSE 3000 -ENV PORT 3000 - # node로 애플리케이션 실행 CMD ["node", "server.js"] From bfd18eeacab3d368786a867c0f5d7ef8b5ef5e71 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Tue, 27 Feb 2024 02:19:40 +0900 Subject: [PATCH 46/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 7b9c7550..324b3e05 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -35,6 +35,8 @@ jobs: - name: Application Run uses: appleboy/ssh-action@v1.0.3 + env: + PORT: 8000 with: host: ${{ secrets.AWS_EC2_HOST }} username: ${{ secrets.AWS_USERNAME }} From c2b75fdbaa26e0f4daff00d7d16cde30416b7fc0 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Tue, 27 Feb 2024 02:32:20 +0900 Subject: [PATCH 47/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 324b3e05..975d2d43 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -24,6 +24,12 @@ jobs: id: login-ecr uses: aws-actions/amazon-ecr-login@v2 + - name: Create .env file + run: | + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env + env: + SECRETS_CONTEXT: ${{ toJson(secrets) }} + - name: Build, tag, and push docker image to Amazon ECR env: REGISTRY: ${{ steps.login-ecr.outputs.registry }} From 334122a24444d48d3d9bd034fe707d7d1b9f474c Mon Sep 17 00:00:00 2001 From: bottlewook Date: Tue, 27 Feb 2024 02:36:19 +0900 Subject: [PATCH 48/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 975d2d43..59f46a64 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -26,7 +26,7 @@ jobs: - name: Create .env file run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production env: SECRETS_CONTEXT: ${{ toJson(secrets) }} From 07d490a1c3a0762f6eb39d6079eded0e718014f4 Mon Sep 17 00:00:00 2001 From: bottlewook Date: Tue, 27 Feb 2024 02:53:25 +0900 Subject: [PATCH 49/49] =?UTF-8?q?chore:=20yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cd-aws.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cd-aws.yml b/.github/workflows/cd-aws.yml index 59f46a64..b4ca8509 100644 --- a/.github/workflows/cd-aws.yml +++ b/.github/workflows/cd-aws.yml @@ -26,9 +26,8 @@ jobs: - name: Create .env file run: | - jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env.production - env: - SECRETS_CONTEXT: ${{ toJson(secrets) }} + touch .env.local + echo "${{ secrets.ENV_PRODUCTION }}" > .env.production - name: Build, tag, and push docker image to Amazon ECR env: