Skip to content

Commit

Permalink
Merge pull request #136 from sopt-makers/develop
Browse files Browse the repository at this point in the history
feat: change Prod deployment env to AWS Public ECR & set node version to 22
  • Loading branch information
Lim-Changi authored Sep 8, 2024
2 parents 2bb5812 + 78a6a48 commit 9a96f26
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 15 additions & 24 deletions .github/workflows/cd.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stage 1: Build the application
FROM node:16-alpine AS build
FROM node:22-alpine AS build

WORKDIR /app

Expand All @@ -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

Expand Down

0 comments on commit 9a96f26

Please sign in to comment.