Skip to content

Commit 367199c

Browse files
authored
feat: #dev-deploy tag
1 parent 207931b commit 367199c

File tree

1 file changed

+143
-145
lines changed

1 file changed

+143
-145
lines changed

.github/workflows/dev.kodemy.deploy.yml

Lines changed: 143 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -36,161 +36,162 @@ env:
3636
JWT_KEY: ${{ secrets.JWT_KEY }}
3737

3838
jobs:
39-
# prepare:
40-
# name: Prepare
41-
# runs-on: self-hosted
42-
# environment: dev
43-
# steps:
44-
# - name: Check environments
45-
# run: |
46-
# REQUIRED_VARS=\
47-
# (
48-
# "WORKING_DIRECTORY"
49-
# "NETWORK_NAME"
50-
# "DATASOURCE_CONTAINER"
51-
# "DATASOURCE_USERNAME"
52-
# "DATASOURCE_PASSWORD"
53-
# "DATASOURCE_DB"
54-
# "RABBITMQ_HOST"
55-
# "RABBITMQ_PORT"
56-
# "RABBITMQ_USERNAME"
57-
# "RABBITMQ_PASSWORD"
58-
# "RABBITMQ_PASSWORD"
59-
# "ELASTICSEARCH_USERNAME"
60-
# "ELASTICSEARCH_PASSWORD"
61-
# "EUREKA_URL"
62-
# "FRONTEND_PUBLIC_HOST"
63-
# "CORS_ALLOWED_ORIGINS"
64-
# "GATEWAY_PUBLIC_HOST"
65-
# "OAUTH_GITHUB_ID"
66-
# "OAUTH_GITHUB_KEY"
67-
# "JWT_KEY"
68-
# "REDIS_HOST"
69-
# "REDIS_PORT"
70-
# )
71-
# EXIT=0
72-
# for VAR in "${REQUIRED_VARS[@]}"; do
73-
# [ -z "${!VAR}" ] && echo "Environment variable $VAR is missing." && EXIT=1
74-
# done
75-
# exit $EXIT
76-
# update-branch:
77-
# name: Update branch
78-
# needs: [ prepare ]
79-
# runs-on: self-hosted
80-
# environment: dev
81-
# steps:
82-
# - name: Update ${{ github.ref_name }}
83-
# uses: appleboy/ssh-action@master
84-
# env:
85-
# BRANCH: ${{ github.ref_name }}
86-
# with:
87-
# host: ${{ secrets.REMOTE_HOST }}
88-
# username: ${{ secrets.REMOTE_USER }}
89-
# port: ${{ secrets.REMOTE_PORT }}
90-
# key: ${{ secrets.SSH_PRIVATE_KEY }}
91-
# envs: WORKING_DIRECTORY,BRANCH
92-
# script: |
93-
# cd $WORKING_DIRECTORY
94-
# git checkout $BRANCH || exit 1
95-
# git pull origin $BRANCH || exit 1
96-
# validate:
97-
# name: Validate services
98-
# runs-on: self-hosted
99-
# needs: [ update-branch ]
100-
# environment: dev
101-
# steps:
102-
# - name: Validate services
103-
# uses: appleboy/ssh-action@master
104-
# with:
105-
# host: ${{ secrets.REMOTE_HOST }}
106-
# username: ${{ secrets.REMOTE_USER }}
107-
# port: ${{ secrets.REMOTE_PORT }}
108-
# key: ${{ secrets.SSH_PRIVATE_KEY }}
109-
# envs: WORKING_DIRECTORY,NETWORK_NAME,DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_DB
110-
# script: |
111-
# echo "Validate network"
112-
# docker network inspect $NETWORK_NAME > /dev/null 2>&1 \
113-
# || { echo "Network $NETWORK_NAME is not available."; exit 1; }
39+
prepare:
40+
name: Prepare
41+
runs-on: self-hosted
42+
environment: dev
43+
steps:
44+
- name: Check environments
45+
run: |
46+
REQUIRED_VARS=\
47+
(
48+
"WORKING_DIRECTORY"
49+
"NETWORK_NAME"
50+
"DATASOURCE_CONTAINER"
51+
"DATASOURCE_USERNAME"
52+
"DATASOURCE_PASSWORD"
53+
"DATASOURCE_DB"
54+
"RABBITMQ_HOST"
55+
"RABBITMQ_PORT"
56+
"RABBITMQ_USERNAME"
57+
"RABBITMQ_PASSWORD"
58+
"RABBITMQ_PASSWORD"
59+
"ELASTICSEARCH_USERNAME"
60+
"ELASTICSEARCH_PASSWORD"
61+
"EUREKA_URL"
62+
"FRONTEND_PUBLIC_HOST"
63+
"CORS_ALLOWED_ORIGINS"
64+
"GATEWAY_PUBLIC_HOST"
65+
"OAUTH_GITHUB_ID"
66+
"OAUTH_GITHUB_KEY"
67+
"JWT_KEY"
68+
"REDIS_HOST"
69+
"REDIS_PORT"
70+
)
71+
EXIT=0
72+
for VAR in "${REQUIRED_VARS[@]}"; do
73+
[ -z "${!VAR}" ] && echo "Environment variable $VAR is missing." && EXIT=1
74+
done
75+
exit $EXIT
76+
update-branch:
77+
name: Update branch
78+
needs: [ prepare ]
79+
runs-on: self-hosted
80+
environment: dev
81+
steps:
82+
- name: Update ${{ github.ref_name }}
83+
uses: appleboy/ssh-action@master
84+
env:
85+
BRANCH: ${{ github.ref_name }}
86+
with:
87+
host: ${{ secrets.REMOTE_HOST }}
88+
username: ${{ secrets.REMOTE_USER }}
89+
port: ${{ secrets.REMOTE_PORT }}
90+
key: ${{ secrets.SSH_PRIVATE_KEY }}
91+
envs: WORKING_DIRECTORY,BRANCH
92+
script: |
93+
cd $WORKING_DIRECTORY
94+
git checkout $BRANCH || exit 1
95+
git pull origin $BRANCH || exit 1
96+
validate:
97+
name: Validate services
98+
runs-on: self-hosted
99+
needs: [ update-branch ]
100+
environment: dev
101+
steps:
102+
- name: Validate services
103+
uses: appleboy/ssh-action@master
104+
with:
105+
host: ${{ secrets.REMOTE_HOST }}
106+
username: ${{ secrets.REMOTE_USER }}
107+
port: ${{ secrets.REMOTE_PORT }}
108+
key: ${{ secrets.SSH_PRIVATE_KEY }}
109+
envs: WORKING_DIRECTORY,NETWORK_NAME,DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_DB
110+
script: |
111+
echo "Validate network"
112+
docker network inspect $NETWORK_NAME > /dev/null 2>&1 \
113+
|| { echo "Network $NETWORK_NAME is not available."; exit 1; }
114114
115-
# echo "Validate database - container"
116-
# docker exec -t $DATASOURCE_CONTAINER pg_isready \
117-
# || { echo "PostgreSQL is not running."; exit 1; }
115+
echo "Validate database - container"
116+
docker exec -t $DATASOURCE_CONTAINER pg_isready \
117+
|| { echo "PostgreSQL is not running."; exit 1; }
118118
119-
# echo "Validate database - database"
120-
# docker exec -t $DATASOURCE_CONTAINER psql -lqt -U $DATASOURCE_USERNAME | grep -q $DATASOURCE_DB \
121-
# || { echo "Database $DATASOURCE_DB does not exist."; exit 1; }
119+
echo "Validate database - database"
120+
docker exec -t $DATASOURCE_CONTAINER psql -lqt -U $DATASOURCE_USERNAME | grep -q $DATASOURCE_DB \
121+
|| { echo "Database $DATASOURCE_DB does not exist."; exit 1; }
122122
123-
# echo "Validate database - schemas"
124-
# DATASOURCE_SCHEMAS=("kodemy-auth" "kodemy-backend" "kodemy-notification")
125-
# for SCHEMA in "${DATASOURCE_SCHEMAS[@]}"
126-
# do
127-
# docker exec -t $DATASOURCE_CONTAINER psql \
128-
# -U $DATASOURCE_USERNAME \
129-
# -d $DATASOURCE_DB \
130-
# -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name = '$SCHEMA'" \
131-
# | grep -q 1 || { echo "Schema $SCHEMA does not exist."; exit 1; }
132-
# done
123+
echo "Validate database - schemas"
124+
DATASOURCE_SCHEMAS=("kodemy-auth" "kodemy-backend" "kodemy-notification")
125+
for SCHEMA in "${DATASOURCE_SCHEMAS[@]}"
126+
do
127+
docker exec -t $DATASOURCE_CONTAINER psql \
128+
-U $DATASOURCE_USERNAME \
129+
-d $DATASOURCE_DB \
130+
-tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name = '$SCHEMA'" \
131+
| grep -q 1 || { echo "Schema $SCHEMA does not exist."; exit 1; }
132+
done
133133
134-
# build-and-deploy:
135-
# name: Build, Test, Deploy
136-
# runs-on: self-hosted
137-
# needs: [ validate ]
138-
# environment: dev
139-
# steps:
140-
# - name: Build, Test, Deploy
141-
# uses: appleboy/ssh-action@master
142-
# with:
143-
# host: ${{ secrets.REMOTE_HOST }}
144-
# username: ${{ secrets.REMOTE_USER }}
145-
# port: ${{ secrets.REMOTE_PORT }}
146-
# key: ${{ secrets.SSH_PRIVATE_KEY }}
147-
# envs: |
148-
# WORKING_DIRECTORY,
149-
# DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_PASSWORD,DATASOURCE_DB,
150-
# RABBITMQ_HOST,RABBITMQ_PORT,RABBITMQ_USERNAME,RABBITMQ_PASSWORD,
151-
# ELASTICSEARCH_HOSTS,ELASTICSEARCH_USERNAME,ELASTICSEARCH_PASSWORD,
152-
# EUREKA_URL,
153-
# FRONTEND_PUBLIC_HOST,CORS_ALLOWED_ORIGINS,
154-
# GATEWAY_PUBLIC_HOST,
155-
# OAUTH_GITHUB_ID,OAUTH_GITHUB_KEY,
156-
# JWT_KEY,
157-
# REDIS_HOST,REDIS_PORT
158-
# script: |
134+
build-and-deploy:
135+
name: Build, Test, Deploy
136+
runs-on: self-hosted
137+
needs: [ validate ]
138+
environment: dev
139+
steps:
140+
- name: Build, Test, Deploy
141+
uses: appleboy/ssh-action@master
142+
with:
143+
host: ${{ secrets.REMOTE_HOST }}
144+
username: ${{ secrets.REMOTE_USER }}
145+
port: ${{ secrets.REMOTE_PORT }}
146+
key: ${{ secrets.SSH_PRIVATE_KEY }}
147+
envs: |
148+
WORKING_DIRECTORY,
149+
DATASOURCE_CONTAINER,DATASOURCE_USERNAME,DATASOURCE_PASSWORD,DATASOURCE_DB,
150+
RABBITMQ_HOST,RABBITMQ_PORT,RABBITMQ_USERNAME,RABBITMQ_PASSWORD,
151+
ELASTICSEARCH_HOSTS,ELASTICSEARCH_USERNAME,ELASTICSEARCH_PASSWORD,
152+
EUREKA_URL,
153+
FRONTEND_PUBLIC_HOST,CORS_ALLOWED_ORIGINS,
154+
GATEWAY_PUBLIC_HOST,
155+
OAUTH_GITHUB_ID,OAUTH_GITHUB_KEY,
156+
JWT_KEY,
157+
REDIS_HOST,REDIS_PORT
158+
script: |
159159
160-
# cd $WORKING_DIRECTORY/commons
161-
# ./gradlew clean assemble
160+
cd $WORKING_DIRECTORY/commons
161+
./gradlew clean assemble
162162
163-
# cd $WORKING_DIRECTORY/kodemy-api-gateway
164-
# ./gradlew clean assemble -x test
165-
# cd $WORKING_DIRECTORY/kodemy-auth
166-
# ./gradlew clean assemble -x test
167-
# cd $WORKING_DIRECTORY/kodemy-backend
168-
# ./gradlew clean assemble -x test
169-
# cd $WORKING_DIRECTORY/kodemy-notification
170-
# ./gradlew clean assemble -x test
171-
# cd $WORKING_DIRECTORY/kodemy-search
172-
# ./gradlew clean assemble -x test
173-
# cd $WORKING_DIRECTORY/kodemy-service-registry
174-
# ./gradlew clean assemble -x test
163+
cd $WORKING_DIRECTORY/kodemy-api-gateway
164+
./gradlew clean assemble -x test
165+
cd $WORKING_DIRECTORY/kodemy-auth
166+
./gradlew clean assemble -x test
167+
cd $WORKING_DIRECTORY/kodemy-backend
168+
./gradlew clean assemble -x test
169+
cd $WORKING_DIRECTORY/kodemy-notification
170+
./gradlew clean assemble -x test
171+
cd $WORKING_DIRECTORY/kodemy-search
172+
./gradlew clean assemble -x test
173+
cd $WORKING_DIRECTORY/kodemy-service-registry
174+
./gradlew clean assemble -x test
175175
176-
# export DATASOURCE_URL=jdbc:postgresql://$DATASOURCE_CONTAINER/$DATASOURCE_DB
176+
export DATASOURCE_URL=jdbc:postgresql://$DATASOURCE_CONTAINER/$DATASOURCE_DB
177177
178-
# cd $WORKING_DIRECTORY
179-
# docker compose -f docker-compose.app.yml -f docker-compose.app.expose.yml up --build -d
180-
# - name: Cleanup
181-
# uses: appleboy/ssh-action@master
182-
# with:
183-
# host: ${{ secrets.REMOTE_HOST }}
184-
# username: ${{ secrets.REMOTE_USER }}
185-
# port: ${{ secrets.REMOTE_PORT }}
186-
# key: ${{ secrets.SSH_PRIVATE_KEY }}
187-
# script: |
188-
# docker system prune -f
178+
cd $WORKING_DIRECTORY
179+
docker compose -f docker-compose.app.yml -f docker-compose.app.expose.yml up --build -d
180+
- name: Cleanup
181+
uses: appleboy/ssh-action@master
182+
with:
183+
host: ${{ secrets.REMOTE_HOST }}
184+
username: ${{ secrets.REMOTE_USER }}
185+
port: ${{ secrets.REMOTE_PORT }}
186+
key: ${{ secrets.SSH_PRIVATE_KEY }}
187+
script: |
188+
docker system prune -f
189189
190190
create-tag:
191191
name: Create tag
192192
runs-on: self-hosted
193193
environment: dev
194+
needs: [ build-and-deploy ]
194195
steps:
195196
- name: Determine new tag
196197
id: tag
@@ -213,6 +214,3 @@ jobs:
213214
cd $WORKING_DIRECTORY
214215
git tag $TAG_NAME
215216
git push origin --tags
216-
217-
218-

0 commit comments

Comments
 (0)