-
Notifications
You must be signed in to change notification settings - Fork 2
175 lines (150 loc) Β· 5.4 KB
/
develop-cd.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: develop cd
on:
push:
branches: [ "develop" ]
permissions:
checks: write
pull-requests: write
jobs:
INSTALL_DOCKER:
runs-on: ubuntu-latest
steps:
- name: Remote Check and install Docker
uses: appleboy/ssh-action@master
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.HOST_DEV }}
key: ${{ secrets.PRIVATE_KEY }}
password: ${{ secrets.HOST_PASSWORD }}
# key: ${{ secrets.PRIVATE_KEY }}
port: 22
script: |
if ! [ -x "$(command -v docker)" ]; then
echo "Docker is not installed. Installing Docker..."
sudo yum update
sudo amazon-linux-extras install docker
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
else
echo "Docker is already installed."
fi
if ! [ -x "$(command -v docker-compose)" ]; then
echo "Docker Compose is not installed. Installing Docker Compose..."
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
else
echo "Docker Compose is already installed."
fi
MOVE_FILE:
runs-on: ubuntu-latest
steps:
- name: checkout branch
uses: actions/checkout@v3
- name: create dir
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
key: ${{ secrets.PRIVATE_KEY }}
password: ${{ secrets.HOST_PASSWORD }}
# key: ${{ secrets.PRIVATE_KEY }}
script: |
mkdir -p /home/app/nginx/
- name: Copy configruation files
run:
echo "${{secrets.DEVELOP_ENV_FILE }}" > ./.env
- name: Send env file
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
password: ${{ secrets.HOST_PASSWORD }}
# key: ${{ secrets.PRIVATE_KEY }}
source: "./.env"
target: "/home/app"
- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
password: ${{ secrets.HOST_PASSWORD }}
# key: ${{ secrets.PRIVATE_KEY }}
source: "./docker-compose.yml"
target: "/home/app"
- name: Send deploy-dev.sh
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
password: ${{ secrets.HOST_PASSWORD }}
# key: ${{ secrets.PRIVATE_KEY }}
source: "./deploy-dev.sh"
target: "/home/app"
- name: Send nginx.conf
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
password: ${{ secrets.HOST_PASSWORD }}
# key: ${{ secrets.PRIVATE_KEY }}
source: "./nginx/default.conf"
target: "/home/app"
CD:
runs-on: ubuntu-latest
steps:
- name: checkout branch
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: set up environment Variable
run: |
echo "${{secrets.DEVELOP_ENV_FILE }}" > ./.env
echo "${{secrets.APPLICATION_TEST}}" >> ./src/test/resources/application-test.yml
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Setup Gradle permission
run: chmod +x ./gradlew
- name: Set Up With Run MySQL Docker Container
run: |
sudo docker run -d -p 3306:3306 --env MYSQL_DATABASE=dadok_test --env MYSQL_ROOT_PASSWORD=${{ secrets.TEST_DB_PASSWORD }} mysql:8.0.31
- name: Set Up With Run Redis
run: |
sudo docker run --name dadok-redis -p 6379:6379 -d redis --requirepass ${{ secrets.TEST_REDIS_PASSWORD }}
- name: build with Gradle
run: |
./gradlew clean
./gradlew build
./gradlew bootjar
- name: docker hub push
run: |
pwd
ls
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker build -t ${{ secrets.DOCKER_DEV_REPO }}:latest .
docker push ${{ secrets.DOCKER_DEV_REPO }}
- name: Deploy to develop
uses: appleboy/ssh-action@master
id: deploy-dev
if: contains(github.ref, 'develop')
with:
host: ${{ secrets.HOST_DEV }}
username: ${{ secrets.USERNAME }}
port: 22
password: ${{ secrets.HOST_PASSWORD }}
# key: ${{ secrets.PRIVATE_KEY }}
source: "docker-compose.yml"
script: |
cd /home/app
sudo docker pull ${{ secrets.DOCKER_DEV_REPO }}
chmod 777 ./deploy-dev.sh
./deploy-dev.sh
docker rmi $(docker images -aq)
echo "end deploy###"