Skip to content

๐Ÿ”’ :: ์–ด๋“œ๋ฏผ auth guard ์ ์šฉ #283

๐Ÿ”’ :: ์–ด๋“œ๋ฏผ auth guard ์ ์šฉ

๐Ÿ”’ :: ์–ด๋“œ๋ฏผ auth guard ์ ์šฉ #283

Workflow file for this run

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์„œ๋ฒ„๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด ์™ธ๋ถ€ํฌํŠธ๋งŒ ๋‹ค๋ฅด๊ฒŒ ์„ค์ •