-
Notifications
You must be signed in to change notification settings - Fork 3
79 lines (64 loc) · 2.82 KB
/
deploy-dev.yml
File metadata and controls
79 lines (64 loc) · 2.82 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
name: Deploy DEV
on:
workflow_dispatch:
push:
branches:
- develop
permissions:
contents: read
packages: write
jobs:
deploy-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login GHCR
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build & Push DEV Image
run: |
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker build -t ghcr.io/${REPO_LOWER}:dev .
docker push ghcr.io/${REPO_LOWER}:dev
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -p ${{ secrets.SERVER_PORT }} -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts || true
- name: Deploy DEV
run: |
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
# .env 파일 생성
echo "${{ secrets.DEV_ENV_FILE }}" > .env
# 파일 전송
scp -P ${{ secrets.SERVER_PORT }} -o StrictHostKeyChecking=no docker-compose-dev.yml ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEV_SERVER_PATH }}/docker-compose.yml
scp -P ${{ secrets.SERVER_PORT }} -o StrictHostKeyChecking=no .env ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEV_SERVER_PATH }}/.env
# 배포 실행
ssh -p ${{ secrets.SERVER_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << EOF
set -e
mkdir -p ${{ secrets.DEV_SERVER_PATH }}
cd ${{ secrets.DEV_SERVER_PATH }}
# GHCR 로그인 (Organization 레포의 경우 인증 필요)
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker compose pull
docker compose up -d --remove-orphans
docker compose ps
EOF
- name: Cleanup SSH
if: always()
run: |
rm -f ~/.ssh/id_rsa
rm -f ~/.ssh/known_hosts
notify:
needs: deploy-dev
if: always()
uses: ./.github/workflows/send-discord-message.yml
with:
title: ${{ needs.deploy-dev.result == 'success' && '🚀 DEV 배포 성공' || '❌ DEV 배포 실패' }}
description: "**Deploy DEV**"
url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
color: ${{ needs.deploy-dev.result == 'success' && 5763719 || 15158332 }}
fields: '[{"name":"브랜치","value":"${{ github.ref_name }}","inline":true},{"name":"커밋","value":"${{ github.sha }}","inline":true}]'
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}