Revert "🚨 :: find all group by에 name 추가" #279
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서버를 구분하기 위해 외부포트만 다르게 설정 |