forked from hongik-devtalk/Devtalk-Server-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (74 loc) · 2.97 KB
/
Copy pathdeploy.yml
File metadata and controls
90 lines (74 loc) · 2.97 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
86
87
88
89
90
name: Deploy Devtalk Project
on:
push:
branches:
- main
env:
SPRING_REPOSITORY: devtalk-server-ecr
NGINX_REPOSITORY: devtalk-nginx-ecr
IMAGE_TAG: latest
permissions:
contents: read
id-token: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build Spring Boot Jar with prod profile
run: |
SPRING_PROFILES_ACTIVE=prod ./gradlew clean build -x test
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_GITHUB_ACTION_ROLE_ARN }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and Push Spring Image
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t $REGISTRY/${{ env.SPRING_REPOSITORY }}:${{ env.IMAGE_TAG }} .
docker push $REGISTRY/${{ env.SPRING_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Build and Push Nginx Image
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
cd nginx
docker build -t $REGISTRY/${{ env.NGINX_REPOSITORY }}:${{ env.IMAGE_TAG }} .
docker push $REGISTRY/${{ env.NGINX_REPOSITORY }}:${{ env.IMAGE_TAG }}
- name: Copy docker-compose file to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.DEPLOY_SERVER_HOST }}
username: ${{ secrets.DEPLOY_SERVER_USER }}
key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
port: ${{ secrets.DEPLOY_SERVER_PORT }}
source: "docker-compose-prod.yml"
target: "/home/ubuntu/Devtalk-Server-Application"
- name: Deploy to Server
uses: appleboy/ssh-action@master
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_PASSWORD: ${{ steps.login-ecr.outputs.docker_password_061391278365_dkr_ecr_ap_northeast_2_amazonaws_com }}
with:
host: ${{ secrets.DEPLOY_SERVER_HOST }}
username: ${{ secrets.DEPLOY_SERVER_USER }}
key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
port: ${{ secrets.DEPLOY_SERVER_PORT }}
envs: ECR_REGISTRY,ECR_PASSWORD,SPRING_REPOSITORY,NGINX_REPOSITORY,IMAGE_TAG # ② EC2로 전달
script: |
echo "Using Registry: $ECR_REGISTRY"
echo "$ECR_PASSWORD" | docker login --username AWS --password-stdin "$ECR_REGISTRY"
cd /home/ubuntu/Devtalk-Server-Application
docker-compose -f docker-compose-prod.yml down --rmi all -v --remove-orphans
docker-compose -f docker-compose-prod.yml pull
docker-compose -f docker-compose-prod.yml up -d