-
Notifications
You must be signed in to change notification settings - Fork 5
132 lines (112 loc) · 4.96 KB
/
cicd-dev.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
120
121
122
123
124
125
126
127
128
129
130
131
132
name: CI and CD in WashPedia Project
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"
- name: Replace SQL Queries
run: |
dir_path="./module-api/src/main/resources/db/migration"
old_text="changeRequired"
new_text="${{ secrets.PUBLIC_KEY }}"
find "dir_path" -type f -name "*.sql" -exec sed -i "s|old_text|new_text|g" {} +
- name: Set application yml file (api)
uses: microsoft/variable-substitution@v1
with:
files: ./module-api/src/main/resources/application.yml
env:
spring.profiles.active: "dev"
- name: Set application yml file (batch)
uses: microsoft/variable-substitution@v1
with:
files: ./module-batch/src/main/resources/application.yml
env:
spring.profiles.active: "dev"
- name: Set application-dev yml file (api)
uses: microsoft/variable-substitution@v1
with:
files: ./module-api/src/main/resources/application-dev.yml
env:
spring.datasource.url: ${{ secrets.DB_URL }}
spring.datasource.username: ${{ secrets.DB_USER }}
spring.datasource.password: ${{ secrets.DB_PW }}
spring.mail.username: ${{ secrets.SMTP_GOOGLE_EMAIL }}
spring.mail.password: ${{ secrets.SMTP_PASSWORD }}
spring.data.redis.host: ${{ secrets.REDIS_DEV_HOST }}
spring.data.redis.password: ${{ secrets.REDIS_DEV_PASSWORD }}
constants.host-url: ${{ secrets.DEV_HOST_URL }}
aws.credentials.access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws.credentials.secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws.s3.bucket.name: ${{ secrets.AWS_S3_BUCKET_NAME }}
aws.s3.bucket.url: ${{ secrets.AWS_S3_BUCKET_URL }}
- name: Set application-dev yml file (batch)
uses: microsoft/variable-substitution@v1
with:
files: ./module-batch/src/main/resources/application-dev.yml
env:
spring.datasource.url: ${{ secrets.VULTR_DB_URL }}
spring.datasource.username: ${{ secrets.DB_USER }}
spring.datasource.password: ${{ secrets.DB_PW }}
external.ecolife-api.path: ${{ secrets.ECOLIFE_PATH }}
external.ecolife-api.service-key: ${{ secrets.ECOLIFE_KEY }}
- name: Grant execute permission And Build with Gradle (api)
working-directory: ./module-api
run: |
chmod +x ./gradlew
./gradlew bootJar
- name: Grant execute permission And Build with Gradle (batch)
working-directory: ./module-batch
run: |
chmod +x ./gradlew
./gradlew bootJar
- name: DockerHub Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker Image Build And Push (api)
working-directory: ./module-api
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.MODULE_API_NAME }} . --platform=linux/amd64
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.MODULE_API_NAME }}
- name: Docker Image Build And Push (batch)
working-directory: ./module-batch
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.MODULE_BATCH_NAME }} . --platform=linux/amd64
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.MODULE_BATCH_NAME }}
- name: Application Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.VULTR_IP }}
username: ${{ secrets.VULTR_USERNAME }}
password: ${{ secrets.VULTR_PW }}
script: |
# Install Docker and Docker Compose
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Docker Compose
mkdir -p deploy
cd deploy
echo "${{ secrets.DB_INIT_SQL }}" > init.sql
echo "${{ secrets.DEV_REDIS_CONF }}" > ./redis/redis.conf
echo "${{ secrets.DOCKER_COMPOSE }}" > docker-compose.yml
echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker image prune -af
docker-compose pull
docker-compose down
docker-compose up -d