-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (69 loc) · 2.54 KB
/
cd.yml
File metadata and controls
85 lines (69 loc) · 2.54 KB
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
84
85
name: CD
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: 코드 체크아웃
uses: actions/checkout@v4
- name: 이미지 태그 생성
id: vars
run: echo "tag=${GITHUB_SHA}" >> $GITHUB_OUTPUT
- name: 이미지 경로 생성
run: |
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=ghcr.io/${REPO_LOWER}/backend" >> $GITHUB_ENV
- name: GHCR 로그인
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: QEMU 설정
uses: docker/setup-qemu-action@v3
- name: Buildx 설정
uses: docker/setup-buildx-action@v3
- name: 멀티 아키텍처 이미지 빌드 및 푸시
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
-f Dockerfile \
-t $IMAGE_NAME:${{ steps.vars.outputs.tag }} \
-t $IMAGE_NAME:latest \
--push \
.
- name: 서버에 배포 디렉토리 생성
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
port: ${{ secrets.DEPLOY_PORT }}
script: |
mkdir -p ~/teampling
- name: 배포 파일 전송
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
port: ${{ secrets.DEPLOY_PORT }}
source: "docker-compose.prod.yaml,nginx.conf"
target: "~/teampling"
- name: 서버 배포 실행
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
port: ${{ secrets.DEPLOY_PORT }}
script: |
cd /home/${{ secrets.DEPLOY_USER }}/teampling
export IMAGE_TAG=${{ steps.vars.outputs.tag }}
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GHCR_PAT }}
docker compose -f docker-compose.prod.yaml pull app
docker compose -f docker-compose.prod.yaml run --rm app alembic upgrade head
docker compose -f docker-compose.prod.yaml up -d app nginx
docker image prune -f