-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (57 loc) · 1.97 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
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
# Docker Buildx를 설정한다
- 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@v5
with:
context: ./
# Dockerfile이 있는 위치
file: ./Dockerfile
# Dockerfile의 이름
push: true
# 이미지를 레지스트리에 푸시
tags: ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
backend-docker-pull-and-run:
needs: [ backend-docker-build-and-push ]
if: ${{ needs.backend-docker-build-and-push.result == 'success' }}
runs-on: [ self-hosted, ec2-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 -v /var/log/backend:/app/logs \
--env-file .env \
-d -p 8080:8080 --name agilehub-backend ${{ env.DOCKER_HUB_REPOSITORY }}:${{ github.sha }}
EOF