24 lines
1.0 KiB
Bash
Executable File
24 lines
1.0 KiB
Bash
Executable File
#!/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 &> /dev/null
|
|
echo "Containers updated successfully to version ${LAST_COMMIT}" >> update-containers.log
|
|
fi
|
|
|
|
# Sleep for 5 minutes as commits are not generated very often
|
|
sleep $((5 * 60))
|
|
done
|