-
Notifications
You must be signed in to change notification settings - Fork 8
67 lines (58 loc) · 2.1 KB
/
deploy.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
name: Check code quality, run test code
on:
pull_request:
branches:
- main
types:
- closed
jobs:
deploy:
name: Deploy Docker image to ECR and Run docker image in EC2 instance
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: 코드 Checkout
uses: actions/checkout@v4
- name: AWS Credentials 가져오기
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: AWS ECR 로그인
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: 백엔드 도커 이미지 생성 및 배포
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }}
IMAGE_TAG: ${{ github.sha }}
run: |
# 도커 이미지 생성
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest .
# ECR로 도커 이미지 PUSH
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
- name: EC2에 배포 및 백엔드 어플리케이션 실행
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: ./deploy.sh
- name: 배포 결과 확인
if: always()
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
# 컨테이너 상태 확인
if docker ps | grep -q "${{ secrets.ECR_REPOSITORY_NAME }}"; then
echo "Container is running successfully"
exit 0
else
echo "Container is not running"
exit 1
fi