Merge pull request #178 from modern-agile-team/publish/#174/Responsiv… #248
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@v4 | |
# Docker Buildx 설정 | |
- name: Set up docker buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
# 캐시 디렉토리 확인 및 생성 | |
- name: Ensure cache directory exists | |
run: mkdir -p /tmp/.buildx-cache | |
# Docker 캐시 복원 및 저장 | |
- name: Cache docker layers | |
id: cache-docker | |
uses: actions/cache@v4 | |
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@v3 | |
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@v6 | |
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@v3 | |
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: | | |
if [ -n "$(docker images -f "dangling=true" -q)" ]; then | |
docker rmi $(docker images -f "dangling=true" -q) | |
fi | |
docker compose -f /home/ubuntu/docker-compose.yml down | |
docker compose -f /home/ubuntu/docker-compose.yml up -d --pull always |