From b931b0808ad69518bcafd4a99ff2c1f10b367a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B0=AC=EA=B8=B0?= Date: Sun, 8 Sep 2024 12:08:49 +0900 Subject: [PATCH 1/3] feat: set Prod AWS ECR Repo & use node v22 at deployment --- .github/workflows/cd.prod.yml | 39 ++++++++++++++--------------------- dockerfile | 4 ++-- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/.github/workflows/cd.prod.yml b/.github/workflows/cd.prod.yml index 04f234b..f788185 100644 --- a/.github/workflows/cd.prod.yml +++ b/.github/workflows/cd.prod.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16.x + node-version: 22.x cache: 'yarn' - name: Install dependencies run: yarn install --frozen-lockfile @@ -26,29 +26,20 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Docker meta - id: docker_meta - uses: crazy-max/ghaction-docker-meta@v3 + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 with: - images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} + aws-region: ${{ secrets.AWS_REGION }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: . - file: ./dockerfile - platforms: linux/amd64 - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE }}:latest + - name: Push Image to AWS ECR Public Repo + id: ecr-image-push + run: | + aws ecr-public get-login-password --region ${{ secrets.AWS_PUBLIC_REPO_REGION }} | docker login --username AWS --password-stdin public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }} + docker build -t ${{ secrets.PROD_ECR_REPO }}:latest . + docker tag ${{ secrets.PROD_ECR_REPO }}:latest public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.PROD_ECR_REPO }}:latest + docker push public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.PROD_ECR_REPO }}:latest deploy: @@ -66,5 +57,5 @@ jobs: sudo docker rm sopt.org-backend sudo docker rm -f $(docker ps -qa) sudo docker image prune -a -f - sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE }}:latest - sudo docker run --name sopt.org-backend --env-file .env -d -p 3000:3000 -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_PROD_IMAGE }}:latest + sudo docker pull public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.PROD_ECR_REPO }}:latest + sudo docker run --name sopt.org.backend --env-file .env -d -p 3000:3000 -t public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.PROD_ECR_REPO }}:latest diff --git a/dockerfile b/dockerfile index 24e6fbd..2cadc1d 100644 --- a/dockerfile +++ b/dockerfile @@ -1,5 +1,5 @@ # Stage 1: Build the application -FROM node:16-alpine AS build +FROM node:22-alpine AS build WORKDIR /app @@ -13,7 +13,7 @@ COPY . . RUN yarn build # Stage 2: Create the production image -FROM node:16-alpine AS production +FROM node:22-alpine AS production RUN apk add --no-cache udev ttf-freefont chromium From 651c3e12f7baf0b25347b91fdd0674e399e9f9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B0=AC=EA=B8=B0?= Date: Sun, 8 Sep 2024 12:10:47 +0900 Subject: [PATCH 2/3] fix: docker image name --- .github/workflows/cd.prod.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.prod.yml b/.github/workflows/cd.prod.yml index f788185..cf677bc 100644 --- a/.github/workflows/cd.prod.yml +++ b/.github/workflows/cd.prod.yml @@ -58,4 +58,4 @@ jobs: sudo docker rm -f $(docker ps -qa) sudo docker image prune -a -f sudo docker pull public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.PROD_ECR_REPO }}:latest - sudo docker run --name sopt.org.backend --env-file .env -d -p 3000:3000 -t public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.PROD_ECR_REPO }}:latest + sudo docker run --name sopt.org-backend --env-file .env -d -p 3000:3000 -t public.ecr.aws/${{ secrets.AWS_ACCOUNT_ID }}/${{ secrets.PROD_ECR_REPO }}:latest From 78a6a48eac9a56cc2219ef82611d32b27c5318a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B0=AC=EA=B8=B0?= Date: Sun, 8 Sep 2024 12:11:13 +0900 Subject: [PATCH 3/3] fix: dev deploy node version to 22 --- .github/workflows/cd.develop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cd.develop.yml b/.github/workflows/cd.develop.yml index 859cfb2..53a889c 100644 --- a/.github/workflows/cd.develop.yml +++ b/.github/workflows/cd.develop.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16.x + node-version: 22.x cache: 'yarn' - name: Install dependencies run: yarn install --frozen-lockfile