-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (69 loc) · 2.25 KB
/
prod-cd.yml
File metadata and controls
78 lines (69 loc) · 2.25 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
name: cd-prod
on:
push:
branches: [ "main" ]
jobs:
docker-build-push:
environment: prod
runs-on: ubuntu-latest
steps:
- name: Github Repository Checkout
uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.ACCESS_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle / Run Test
uses: gradle/gradle-build-action@v2
with:
arguments: build
- name: Docker Hub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.PROD_DOCKER_HUB_USERNAME }}
password: ${{ secrets.PROD_DOCKER_HUB_PASSWORD }}
- name: Docker Image Build and Push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.PROD_DOCKER_HUB_REPOSITORY_TAGNAME }}
send-docker-compose-file-to-ec2:
environment: prod
runs-on: ubuntu-latest
steps:
- name: Github Repository Checkout
uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.ACCESS_TOKEN }}
- name: Copy Deployment Files to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PROD_EC2_INSTANCE_HOST }}
username: ${{ secrets.PROD_EC2_INSTANCE_USERNAME }}
key: ${{ secrets.PROD_EC2_INSTANCE_PRIVATE_KEY }}
source: './secret/prod/docker-compose.yml'
target: '~/pickple/deploy'
strip_components: 3
deploy-to-ec2:
needs: [ docker-build-push, send-docker-compose-file-to-ec2 ]
environment: prod
runs-on: ubuntu-latest
steps:
- name: Docker Container Run
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_EC2_INSTANCE_HOST }}
username: ${{ secrets.PROD_EC2_INSTANCE_USERNAME }}
key: ${{ secrets.PROD_EC2_INSTANCE_PRIVATE_KEY }}
script: |
docker pull ${{ secrets.PROD_DOCKER_HUB_REPOSITORY_TAGNAME }}
cd ~/pickple/deploy
docker-compose -p pickple-prod down
docker-compose -p pickple-prod up -d
docker image prune -f