-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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/} --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 | ||
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 |