-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (103 loc) · 3.87 KB
/
CD-prod.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: CD-prod
on:
push:
branches:
- release
jobs:
deploy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: make firebase.json
uses: jsdaniell/[email protected]
with:
dir: ./Api-Module/src/main/resources
json: ${{ secrets.FCM_JSON }}
name: firebase.json
- name: make promtail-prod.yaml
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PROD_HOST }}
username: ubuntu
key: ${{ secrets.PROD_KEY }}
source: "./.deploy/promtail-prod.yaml"
target: "/home/ubuntu"
strip_components: 2
- name: Set .env for configuration
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_HOST }}
username: ubuntu
key: ${{ secrets.PROD_KEY }}
script: |
rm -rf ./.env
touch ./.env
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> ./.env
echo "DOCKER_REPOSITORY=${{ secrets.DOCKER_REPOSITORY }}" >> ./.env
echo "DB_URL=${{ secrets.PROD_DB_URL }}" >> ./.env
echo "DB_USERNAME=${{ secrets.PROD_DB_USERNAME }}" >> ./.env
echo "DB_PASSWORD=${{ secrets.PROD_DB_PASSWORD }}" >> ./.env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> ./.env
echo "KAKAO_APP_ID=${{ secrets.KAKAO_APP_ID }}" >> ./.env
echo "APPLE_APP_ID=${{ secrets.APPLE_APP_ID }}" >> ./.env
echo "S3_BUCKET=${{ secrets.S3_BUCKET }}" >> ./.env
echo "AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }}" >> ./.env
echo "AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }}" >> ./.env
- name: Grant Execute Permission For Gradlew
run: chmod +x gradlew
- name: Build With Gradle
run: |
./gradlew build
- name: Docker build
run: docker build -f ./.deploy/Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }} .
- name: Docker Hub Login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker push
run: docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
- name: deploy docker-compose push
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PROD_HOST }}
username: ubuntu
key: ${{ secrets.PROD_KEY }}
source: "./.deploy/docker-compose.yml"
target: "/home/ubuntu"
strip_components: 2
- name: deploy docker-compose-prod push
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PROD_HOST }}
username: ubuntu
key: ${{ secrets.PROD_KEY }}
source: "./.deploy/docker-compose-prod.yml"
target: "/home/ubuntu"
strip_components: 2
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_HOST }}
username: ubuntu
key: ${{ secrets.PROD_KEY }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPOSITORY }}
docker stop ${{ secrets.DOCKER_REPOSITORY }}
docker rm -f ${{ secrets.DOCKER_REPOSITORY }}
docker compose -f docker-compose.yml -f docker-compose-prod.yml up -d
docker image prune -f