-
Notifications
You must be signed in to change notification settings - Fork 3
50 lines (39 loc) · 1.66 KB
/
deployment.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
name: Deployment3
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
deploy:
name: Deploy3
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: is the github action running
run: echo "asdasd" >> by_the_github_action.txt
- name: stop and remove the previous container
run: |
if docker ps -a | grep -q 'hexa_homepage_backend'; then
if docker ps | grep -q 'hexa_homepage_backend'; then
docker stop hexa_homepage_backend
fi
docker container rm hexa_homepage_backend
fi
- name: build docker image
env:
Vault_Token: ${{ secrets.VAULT_TOKEN }}
run: docker build . --file dockerfile -t hexa_homepage_backend:${GITHUB_REF#refs/tags/} --network mysql_default --network redis_default --build-arg VAULT_TOKEN=${{env.Vault_Token}}
- name: run and test
run: |
docker run -d -p 8282:8080 --name hexa_homepage_backend hexa_homepage_backend:${GITHUB_REF#refs/tags/}
test_result="$(docker exec hexa_homepage_backend ./gradlew test)"
second_last_line="$(echo "$test_result" | tail -n 2 | head -n 1)"
if [[ "$second_last_line" =~ ^BUILD\ SUCCESSFUL ]]; then
echo "TEST SUCCESSFUL"
else
docker stop hexa_homepage_backend
docker container rm hexa_homepage_backend
last_version=$(docker images | grep 'hexa_homepage_backend' | awk '{print $2}' | tail -n 2 | head -n 1)
docker run -d -p 8282:8080 --name hexa_homepage_backend hexa_homepage_backend:$last_version
echo "TEST FAILED"
fi