setting/#28/컴포즈 파일 수정 #36
Workflow file for this run
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: [feat/#28/ci-cd-setting] | |
# 환경설정 | |
env: | |
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/github-actions-auto | |
VERSION: ${{ github.sha }} | |
NAME: back | |
jobs: | |
# 빌드 Job | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
# github repository에서 checkout | |
- uses: actions/checkout@v3 | |
# docker build 수행 | |
- name: Set up docker buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
- 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 컨테이너 레지스트리에 로그인 후 빌드 & 푸시 | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
# 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 | |
# 배포 Job | |
deploy: | |
needs: build # build 후에 실행되도록 정의 | |
name: Deploy | |
runs-on: [self-hosted, label-go] # AWS ./configure에서 사용할 label명 | |
steps: | |
# GHCR 로그인 | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
# 앱 이미지 이름 업데이트 | |
- name: Update DOCKER_IMAGE in .env file | |
run: | | |
if grep -q '^IMAGE_NAME=' /home/ubuntu/.env; then | |
sed -i 's|^IMAGE_NAME=.*|IMAGE_NAME=${{ env.DOCKER_IMAGE }}:latest|' /home/ubuntu/.env | |
else | |
echo "IMAGE_NAME=${{ env.DOCKER_IMAGE }}:latest" >> /home/ubuntu/.env | |
fi | |
# 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 |