Add scripts for continous deployment

This commit is contained in:
Lucian Popescu 2022-05-22 21:52:12 +03:00
parent b3364eb0d5
commit 5331e57f8a
4 changed files with 41 additions and 4 deletions

View File

@ -2,7 +2,7 @@ version: '3.3'
services:
frontend:
image: lipopescu/wna:frontend_latest
image: lipopescu/wna:frontend_${TAG}
expose:
- 8081
ports:
@ -11,7 +11,7 @@ services:
- fe-be
mq_proxy:
image: lipopescu/wna:mq_proxy_latest
image: lipopescu/wna:mq_proxy_${TAG}
expose:
- 8080
ports:
@ -62,7 +62,7 @@ services:
- rmq-network
db_server:
image: lipopescu/wna:db_server_latest
image: lipopescu/wna:db_server_${TAG}
expose:
- "3001"
ports:
@ -77,7 +77,7 @@ services:
- db
mailsender:
image: lipopescu/wna:mailsender_latest
image: lipopescu/wna:mailsender_${TAG}
expose:
- "3434"
ports:

7
start-containers.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
LAST_COMMIT_LONG=$(git ls-remote git@github.com:lucic71/War-News-Aggregator.git HEAD | awk '{ print $1 }')
LAST_COMMIT=$(git rev-parse --short=8 $LAST_COMMIT_LONG)
TAG=${LAST_COMMIT} docker-compose up -d
./update-containers.sh &

7
stop-containers.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
LAST_COMMIT_LONG=$(git ls-remote git@github.com:lucic71/War-News-Aggregator.git HEAD | awk '{ print $1 }')
LAST_COMMIT=$(git rev-parse --short=8 $LAST_COMMIT_LONG)
TAG=${LAST_COMMIT} docker-compose down
pkill -f ./update-containers.sh

23
update-containers.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
while :
do
LAST_COMMIT_LONG=$(git ls-remote git@github.com:lucic71/War-News-Aggregator.git HEAD | awk '{ print $1 }')
LAST_COMMIT=$(git rev-parse --short=8 $LAST_COMMIT_LONG)
# If the latest image is not running locally, download it from DockerHub
if ! docker container ls | grep -q "${LAST_COMMIT}" ; then
# We must be sure that all four docker images were uploaded to DockerHub
until [ `wget -q https://registry.hub.docker.com/v1/repositories/lipopescu/wna/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}' | pcregrep -M "${LAST_COMMIT}" | wc -l` -eq 4 ]
do
:
done
# After the images were uploaded to DockerHub by the Github runner, the containers are ready to be upgraded
TAG=${LAST_COMMIT} docker-compose up -d
echo "Containers updated successfully to version ${LAST_COMMIT}"
fi
# Sleep for 5 minutes as commits are not generated very often
sleep $((5 * 60))
done