๐ ๏ธ :: ๋ฒ์ ๋น๊ต ํจ์ ์์ #291
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Docker | |
on: | |
push: | |
branches: [main, dev] | |
env: | |
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/trading | |
VERSION: ${{ github.sha }} | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out source code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ env.VERSION }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ env.DOCKER_IMAGE }}:${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }} | |
build-args: | | |
START_SCRIPT=${{ github.ref == 'refs/heads/main' && 'start:prod' || 'start:dev' }} | |
ENV_FILE_NAME=${{ github.ref == 'refs/heads/main' && '.env.prod' || '.env.dev' }} | |
ENV_FILE_CONTENT=${{ github.ref == 'refs/heads/main' && secrets.PROD_ENV || secrets.DEV_ENV }} | |
deploy: | |
needs: build | |
name: Deploy | |
runs-on: [self-hosted, label-go] | |
steps: | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Docker run | |
run: | | |
NAME=go_cicd_${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }} | |
PORT=${{ github.ref == 'refs/heads/main' && '8080' || '3000' }} | |
NODE_ENV=${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }} | |
docker stop $NAME || true | |
docker rm $NAME || true | |
docker rmi ${{ env.DOCKER_IMAGE }}:$NODE_ENV || true | |
docker run -d -p $PORT:8080 --name $NAME --restart always ${{ env.DOCKER_IMAGE }}:$NODE_ENV | |
# dev์๋ฒ์ prod์๋ฒ๋ฅผ ๊ตฌ๋ถํ๊ธฐ ์ํด ์ธ๋ถํฌํธ๋ง ๋ค๋ฅด๊ฒ ์ค์ |