Merge pull request #84 from modern-agile-team/publish/#83/Shop_Page #92
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, develop] | |
env: | |
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/react-auto-deploy | |
VERSION: ${{ github.sha }} | |
NAME: go_cicd | |
VITE_BASE_URL: ${{ secrets.VITE_BASE_URL }} | |
VITE_IMG_BASE_URL: ${{ secrets.VITE_IMG_BASE_URL }} | |
jobs: | |
# 빌드 Job | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
# GitHub Repository에서 Checkout | |
- uses: actions/checkout@v3 | |
# Docker Buildx 설정 | |
- name: Set up docker buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
# Docker 캐시 설정 | |
- name: Cache docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ env.VERSION }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
# GitHub Container Registry 로그인 | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.actor == 'bluetree7878' && secrets.bluetree7878_GHCR_TOKEN || secrets.rhehfl_ghcr_token }} | |
# Docker Build 및 Push | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
push: true | |
tags: ${{ env.DOCKER_IMAGE }}:latest | |
build-args: | | |
VITE_BASE_URL=${{ secrets.VITE_BASE_URL }} | |
VITE_IMG_BASE_URL=${{ secrets.VITE_IMG_BASE_URL }} | |
# 배포 Job | |
deploy: | |
needs: build # build 후에 실행되도록 설정 | |
name: Deploy | |
runs-on: [self-hosted, label-go] # AWS ./configure에서 사용할 label명 | |
steps: | |
# GitHub Container Registry 로그인 | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ github.actor == 'bluetree7878' && secrets.bluetree7878_GHCR_TOKEN || secrets.rhehfl_ghcr_token }} | |
# `.env` 파일 생성 | |
- name: Generate .env file | |
run: | | |
echo IMAGE_NAME=${{ env.DOCKER_IMAGE }} > /home/ubuntu/.env | |
# Docker Compose로 서비스 배포 | |
- name: Docker run | |
run: | | |
docker compose -f /home/ubuntu/docker-compose.yml down | |
docker compose -f /home/ubuntu/docker-compose.yml up -d --pull always |