-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (73 loc) · 2.53 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: CI/CD Docker
on:
push:
branches: [develop, deploy/#102/SEO_Optimization]
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: |
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