-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (67 loc) · 2.54 KB
/
backend-prod-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
name: 애자일허브 backend PROD CD
env:
DOCKER_HUB_REPOSITORY: ${{ secrets.DOCKERHUB_USERNAME }}/agilehub-backend
on:
workflow_dispatch:
push:
branches:
- main
paths:
- "src/**"
jobs:
backend-docker-build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
push: true
tags: ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
platforms: linux/amd64,linux/arm64,windows/amd64
attempt-with-first-runner:
needs: [ backend-docker-build-and-push ]
if: ${{ needs.backend-docker-build-and-push.result == 'success' }}
runs-on: [ self-hosted, enable-runner ]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup SSH Key
run: |
echo "${{ secrets.PEM_KEY }}" > pem_key
chmod 600 pem_key
- name: WAS 인스턴스 접속 및 애플리케이션 실행 (첫 번째 시도)
run: |
ssh -i pem_key -o StrictHostKeyChecking=no ${{ secrets.WAS_USERNAME }}@${{ secrets.WAS_PUBLIC_IP }} << EOF
docker rm -f agilehub-backend || true
docker pull ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
docker run -d -p 8080:8080 --name agilehub-backend ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
EOF
attempt-with-second-runner:
needs: [ attempt-with-first-runner ]
if: needs.attempt-with-first-runner.result != 'success'
runs-on: [ self-hosted, evo-actions ]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup SSH Key
run: |
echo "${{ secrets.PEM_KEY }}" > pem_key
chmod 600 pem_key
- name: WAS 인스턴스 접속 및 애플리케이션 실행 (두 번째 시도)
run: |
ssh -i pem_key -o StrictHostKeyChecking=no ${{ secrets.WAS_USERNAME }}@${{ secrets.WAS_PUBLIC_IP }} << EOF
docker rm -f agilehub-backend || true
docker pull ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
docker run -d -p 8080:8080 --name agilehub-backend ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
EOF