Skip to content

Merge pull request #479 from boostcampwm2023/Fix/FE/#457 #149

Merge pull request #479 from boostcampwm2023/Fix/FE/#457

Merge pull request #479 from boostcampwm2023/Fix/FE/#457 #149

Workflow file for this run

name: CD using github action & docker
on:
push:
branches: ["main", "dev", "HotFix/**"]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest # 실행 환경 지정
steps:
- uses: actions/checkout@v3
- name: backend Docker build & push
run: |
docker login -u ${{ secrets.DOCKER_BACK_REPO }} -p ${{ secrets.DOCKER_BACK_PASSWORD }}
cd ./backend
docker build -f Dockerfile -t ${{ secrets.DOCKER_BACK_REPO }}/${{secrets.DOCKER_BACK_TAG}} .
docker push ${{ secrets.DOCKER_BACK_REPO }}/${{secrets.DOCKER_BACK_TAG}}
cd ..
echo "DATABASE_HOST=${{ secrets.DATABASE_HOST }}" > .env
echo "DATABASE_DATABASE=${{ secrets.DATABASE_DATABASE }}" >> .env
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
echo "DATABASE_PORT=${{ secrets.DATABASE_PORT }}" >> .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "MONGODB_URL=${{ secrets.MONGODB_URL }}" >> .env
echo "MONGODB_DBNAME=${{ secrets.MONGODB_DBNAME }}" >> .env
echo "JWT_ACCESS_TOKEN_SECRET=${{ secrets.JWT_ACCESS_TOKEN_SECRET }}" >> .env
echo "JWT_ACCESS_TOKEN_TIME=${{ secrets.JWT_ACCESS_TOKEN_TIME }}" >> .env
echo "NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}" >> .env
echo "NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}" >> .env
echo "REDIS_URL=${{ secrets.REDIS_URL }}" >> .env
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
echo "PORT=${{ secrets.BACK_PORT }}" >> .env
echo "FRONTEND_BASE_URL=${{ secrets.FRONTEND_BASE_URL }}" >> .env
echo "X_NCP_APIGW_API_KEY=${{ secrets.X_NCP_APIGW_API_KEY }}" >> .env
echo "X_NCP_CLOVASTUDIO_API_KEY=${{ secrets.X_NCP_CLOVASTUDIO_API_KEY }}" >> .env
echo "X_NCP_CLOVASTUDIO_REQUEST_ID=${{ secrets.X_NCP_CLOVASTUDIO_REQUEST_ID }}" >> .env
- name: Login to DockerHub for Frontend
uses: docker/login-action@v1
with:
username: ${{secrets.DOCKERHUB_USERNAME}} # 도커 허브 이름
password: ${{secrets.DOCKERHUB_TOKEN}} # 도커 허브 TOKEN
- name: build and release to DockerHub for Frontend
env:
NAME: wjdtjr8649 # 계정명
REPO: boostcamp-lockfestival # 레파지토리 이름(소문자만 가능)
run: |
cd frontend && docker build -t $REPO .
docker tag $REPO:latest $NAME/$REPO:latest
docker push $NAME/$REPO:latest
cd ..
- name: Copy .env to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "./.env"
target: "~"
overwrite: true
- name: Copy docker-compose.yaml to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "./docker-compose.yaml"
target: "~"
overwrite: true
- name: Copy nginx.conf to Remote Server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
source: "./nginx.conf"
target: "~/conf"
overwrite: true
- name: Remove copied file
run: |
rm ./docker-compose.yaml
rm ./.env
rm ./nginx.conf
- name: Depoly to Server
uses: appleboy/ssh-action@master
with:
host: ${{secrets.HOST}}
username: ${{secrets.USERNAME}}
key: ${{secrets.KEY}}
envs: GITHUB_SHA
script: |
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
export DOCKER_BACK_REPO=${{secrets.DOCKER_BACK_REPO}}
export DOCKER_BACK_TAG=${{secrets.DOCKER_BACK_TAG}}
export DATABASE_HOST=${{ secrets.DATABASE_HOST }}
export DATABASE_DATABASE=${{ secrets.DATABASE_DATABASE }}
export DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}
export DATABASE_PORT=${{ secrets.DATABASE_PORT }}
export DATABASE_USER=${{ secrets.DATABASE_USER }}
export MONGODB_URL=${{ secrets.MONGODB_URL }}
export MONGODB_DBNAME=${{ secrets.MONGODB_DBNAME }}
export JWT_ACCESS_TOKEN_SECRET=${{ secrets.JWT_ACCESS_TOKEN_SECRET }}
export JWT_ACCESS_TOKEN_TIME=${{ secrets.JWT_ACCESS_TOKEN_TIME }}
export NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}
export NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}
export REDIS_URL=${{ secrets.REDIS_URL }}
export NODE_ENV=${{ env.NODE_ENV }}
export PORT=${{ secrets.BACK_PORT }}
export FRONTEND_BASE_URL=${{ secrets.FRONTEND_BASE_URL }}
export X_NCP_APIGW_API_KEY=${{ secrets.X_NCP_APIGW_API_KEY }}
export X_NCP_CLOVASTUDIO_API_KEY=${{ secrets.X_NCP_CLOVASTUDIO_API_KEY }}
export X_NCP_CLOVASTUDIO_REQUEST_ID=${{ secrets.X_NCP_CLOVASTUDIO_REQUEST_ID }}
export DOCKER_REPO=${{ secrets.DOCKER_REPO }}
sudo docker pull ${{ secrets.DOCKER_BACK_REPO }}/${{secrets.DOCKER_BACK_TAG}}
docker-compose down
docker-compose up -d
rm -rf ~/.env
docker image prune -f