Commit f3301ee1 authored by johandegn's avatar johandegn
Browse files

Added server deploy scripts to repo.

parent 1e0fe6b1
Pipeline #51960 passed with stage
in 40 seconds
#!/bin/bash
function deploy {
local url=$1
local service_name=$2
local run_arguments=$3
old_digest=$(docker inspect -f '{{.RepoDigests}}' ${url}:active | grep -o 'sha256:[0-9A-Fa-f]*')
# probably no existing image
if [ $? -ne 0 ]; then
echo "No existing image! Abort."
exit 1;
fi
new_digest=$(docker pull ${url}:latest | grep Digest | sed 's/Digest: //')
# network error or authentication might go wrong
if [ $? -ne 0 ]; then
echo "Auth or network err! Abort."
exit 2;
fi
# sanity check that new digest is formatted correctly and is same length as old.
# if it aint, it could be the result of a gitlab server error or such.
local check=$(echo $new_digest | grep -o 'sha256:[0-9A-Fa-f]*')
if [ "${#check}" -eq "0" ] || [ ${#old_digest} -ne 71 ]; then
echo "Damnit, something went bad! Crash and burn.."
exit 3;
fi
echo "Old digest: $old_digest"
echo "New digest: $new_digest"
if [ "$old_digest" != "$new_digest" ]; then
echo "Deploying new docker instance: $service_name."
docker stop $service_name
docker rm $service_name
docker rmi ${url}:active
docker tag ${url}:latest ${url}:active
docker run --network persist-net $run_arguments --name $service_name -d ${url}:active
result=0
else
echo "Already up to date."
fi
# remove/untag file. silence output
docker rmi ${url}:latest >/dev/null 2>&1
}
base_url="registry.gitlab.au.dk/exsys2021/da6/hold-afstand/"
slack_msg="A new version of the website has been deployed! Check it out: https://vm34.exsys2021.cs.au.dk/"
something_deployed=1
result=1
deploy ${base_url}"server" "server" "--network-alias server"
if [ $result -eq 0 ]; then
something_deployed=0
fi
echo
result=1
deploy ${base_url}"web" "web" "-p 80:80"
if [ $result -eq 0 ]; then
something_deployed=0
fi
if [ $something_deployed -eq 0 ]; then
# notify slack channel
/home/auuser/slack-notifier.sh $slack_msg
fi
echo "Done."
#!/bin/bash
url="registry.gitlab.au.dk/exsys2021/da6/hold-afstand"
old_digest=$(docker inspect -f '{{.RepoDigests}}' ${url}:active | grep -o 'sha256:[0-9A-Fa-f]*')
# probably no existing image
if [ $? -ne 0 ]; then
echo "No existing image! Abort."
exit 1;
fi
new_digest=$(docker pull ${url}:latest | grep Digest | sed 's/Digest: //')
# network error or authentication might go wrong
if [ $? -ne 0 ]; then
echo "Auth or network err! Abort."
exit 2;
fi
# sanity check that new digest is formatted correctly and is same length as old.
# if it aint, it could be the result of a gitlab server error or such.
check=$(echo $new_digest | grep -o 'sha256:[0-9A-Fa-f]*')
if [ "${#check}" -eq "0" ] || [ ${#old_digest} -ne ${#new_digest} ]; then
echo "Damnit, something went bad! Crash and burn.."
exit 3;
fi
echo "Old digest: $old_digest"
echo "New digest: $new_digest"
echo
if [ "$old_digest" != "$new_digest" ]; then
echo "Deploying new docker instance."
docker stop studerende-au
docker rm studerende-au
docker rmi ${url}:active
docker tag ${url}:latest ${url}:active
docker run -p 80:80 -p 443:443 --name studerende-au -d ${url}:active
# notify slack channel
/home/auuser/slack-notifier.sh "A new version of the website has been deployed! Check it out: https://vm34.exsys2021.cs.au.dk/"
else
echo "Already up to date."
fi
# remove/untag file. silence output
docker rmi registry.gitlab.au.dk/exsys2021/da6/hold-afstand:latest >/dev/null 2>&1
echo "Done."
#!/bin/bash
docker pull registry.gitlab.au.dk/exsys2021/da6/hold-afstand:latest
docker stop studerende-au
docker rm studerende-au
docker rmi registry.gitlab.au.dk/exsys2021/da6/hold-afstand:active
docker tag registry.gitlab.au.dk/exsys2021/da6/hold-afstand:latest registry.gitlab.au.dk/exsys2021/da6/hold-afstand:active
docker run -p 80:80 -p 443:443 --name studerende-au -d registry.gitlab.au.dk/exsys2021/da6/hold-afstand:active
docker rmi registry.gitlab.au.dk/exsys2021/da6/hold-afstand:latest
#!/bin/bash
# ----- CAUTION!!! -----
# This script removes all running containers,
# all local docker images and all unused
# docker networks.
#
# It then reconfiguring the network downloading
# the images and redeploys them.
base_url="registry.gitlab.au.dk/exsys2021/da6/hold-afstand/"
# stops docker containers
echo -n "Stopping containers..."
docker stop server >/dev/null 2>&1
docker stop web >/dev/null 2>&1
echo " Done."
# removes docker containers
echo -n "Removing containers..."
docker rm server >/dev/null 2>&1
docker rm web >/dev/null 2>&1
echo " Done."
# removes docker images
echo -n "Removing images..."
docker rmi ${base_url}server:active >/dev/null 2>&1
docker rmi ${base_url}web:active >/dev/null 2>&1
echo " Done."
# removes unused docker networks
echo -n "Removing docker network..."
docker network rm persist-net >/dev/null 2>&1
echo " Done."
# pulling the images
echo -n "Pulling latest sever image..."
docker pull ${base_url}server:latest >/dev/null 2>&1
echo " Done."
echo -n "Pulling latest web image..."
docker pull ${base_url}web:latest >/dev/null 2>&1
echo " Done."
# changes tags from latest to active
echo -n "Tagging..."
docker tag ${base_url}server:latest ${base_url}server:active >/dev/null 2>&1
docker tag ${base_url}web:latest ${base_url}web:active >/dev/null 2>&1
docker rmi ${base_url}server:latest >/dev/null 2>&1
docker rmi ${base_url}web:latest >/dev/null 2>&1
echo " Done."
# crates network
echo -n "Creates docker network..."
docker network create -d bridge persist-net --attachable >/dev/null 2>&1
echo " Done."
# spins up containers
echo -n "Spinning up containers..."
docker run --network persist-net --network-alias server --name server -d ${base_url}server:active >/dev/null 2>&1
docker run --network persist-net -p 80:80 --name web -d ${base_url}web:active >/dev/null 2>&1
echo " Done."
echo "All done!"
#!/bin/bash
# INFO: This script should be placed in auuser 's homefolder!
# sanity check
if [ "$#" == "0" ]; then
echo "The message should be passed as an argument!"
exit 1
fi
data='{"text":"'"$@"'"}'
url=$(head -n 1 slack-url)
curl -X POST -H 'Content-type: application/json' --data "$data" $url
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment