Skip to content

Commit

Permalink
Merge pull request #167 from boostcampwm2023/deploy/165-github-action…
Browse files Browse the repository at this point in the history
…-docker-ver

[Deploy] Docker Image를 활용한  Github Action CI/CD 구축
  • Loading branch information
mingxoxo authored Nov 29, 2023
2 parents 094e919 + a00027f commit 34355a5
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build and Push Backend

on:
push:
paths:
- "BE/**"
branches:
- main

jobs:
build-and-push-backend:
runs-on: ubuntu-20.04

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y curl
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Login to NCP Container Registry
uses: docker/login-action@v3
with:
registry: byeolsoop-registry.kr.ncr.ntruss.com
username: ${{ secrets.API_ACCESS_KEY }}
password: ${{ secrets.API_SECRET_KEY }}

- name: Build and Push Backend Docker Image
run: |
docker build -t byeolsoop-registry.kr.ncr.ntruss.com/backend:byeolsoop -f ./docker/be/Dockerfile .
docker push byeolsoop-registry.kr.ncr.ntruss.com/backend:byeolsoop
pull-and-deploy:
needs: build-and-push-backend
runs-on: ubuntu-20.04

steps:
- name: SSH-deploy
uses: appleboy/ssh-action@master
with:
host: ${{secrets.VPC_HOST}}
username: ${{secrets.VPC_USER}}
password: ${{secrets.VPC_PASSWORD}}
port: ${{secrets.VPC_PORT}}
script: |
cd /home/docker-byeolsoop
docker system prune -a
docker pull byeolsoop-registry.kr.ncr.ntruss.com/backend:byeolsoop
docker compose up --force-recreate --build -d --quiet-pull 2>log.out
cat log.out
55 changes: 55 additions & 0 deletions .github/workflows/deploy-frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build and Push frontend

on:
push:
paths:
- "FE/**"
branches:
- main

jobs:
build-and-push-frontend:
runs-on: ubuntu-20.04

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y curl
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
- name: Login to NCP Container Registry
uses: docker/login-action@v3
with:
registry: byeolsoop-registry.kr.ncr.ntruss.com
username: ${{ secrets.API_ACCESS_KEY }}
password: ${{ secrets.API_SECRET_KEY }}

- name: Build and Push Frontend Docker Image
run: |
docker build -t byeolsoop-registry.kr.ncr.ntruss.com/frontend:byeolsoop -f ./docker/fe/Dockerfile .
docker push byeolsoop-registry.kr.ncr.ntruss.com/frontend:byeolsoop
pull-and-deploy:
runs-on: ubuntu-20.04
needs: build-and-push-frontend

steps:
- name: SSH-deploy
uses: appleboy/ssh-action@master
with:
host: ${{secrets.VPC_HOST}}
username: ${{secrets.VPC_USER}}
password: ${{secrets.VPC_PASSWORD}}
port: ${{secrets.VPC_PORT}}
script: |
cd /home/docker-byeolsoop
docker system prune -a
docker pull byeolsoop-registry.kr.ncr.ntruss.com/frontend:byeolsoop
docker compose up --force-recreate --build -d --quiet-pull 2>log.out
cat log.out
21 changes: 21 additions & 0 deletions docker/be/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:20.10.0-alpine3.18

LABEL author jeongmin

WORKDIR /usr/src/app

ENV LANG=ko_KR.UTF-8 \
LANGUAGE=ko_KR.UTF-8

RUN apk add --update git && \
apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \
echo "Asia/Seoul" > /etc/timezone

RUN git clone https://github.com/boostcampwm2023/web08-ByeolSoop . \
&& cd BE && npm install --force

WORKDIR /usr/src/app/BE

CMD [ "npm", "run", "start" ]

22 changes: 22 additions & 0 deletions docker/fe/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:20.10.0-alpine3.18

LABEL author jeongmin

WORKDIR /usr/src/app

ENV LANG=ko_KR.UTF-8 \
LANGUAGE=ko_KR.UTF-8

RUN apk add --update git && \
apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \
echo "Asia/Seoul" > /etc/timezone

RUN git clone https://github.com/boostcampwm2023/web08-ByeolSoop . \
&& cd FE && npm install --force

WORKDIR /usr/src/app/FE

RUN find ./src/ -type f |xargs sed -i 's/223.130.129.145:3005/223.130.129.145\/api/g'

CMD [ "npm", "run", "start" ]

0 comments on commit 34355a5

Please sign in to comment.