Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the update script to work on a single container instead of all #ab1538439 #34

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 42 additions & 25 deletions update
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/bin/bash

####################################################################################
# Vars
####################################################################################
#
# Update docker images on an instance.
#

#
# vars
#
dockerUsername=""
dockerPassword=""
dockerComposeFile=/etc/spida/docker-compose.yml
dockerContainers=""

####################################################################################
# Parses Args
####################################################################################
#
# parses args
#
function parseCommandLineArguments() {
while [ $# -gt 0 ]
do
case "$1" in
--username) dockerUsername="$2"; shift;;
--password) dockerPassword="$2"; shift;;
--composefile) dockerComposeFile="$2"; shift;;
--username) dockerUsername="$2"; shift;;
--password) dockerPassword="$2"; shift;;
--composefile) dockerComposeFile="$2"; shift;;
--containers) dockerContainers="$2"; shift;;

*)
echo >&2 \
Expand All @@ -25,6 +31,7 @@ function parseCommandLineArguments() {
--username dockerhub username (will prompt for username if argument is not passed)
--password dockerhub password (will prompt for password if argument is not passed)
--composefile the location of the docker compose file (defaults to $dockerComposeFile)
--containers the docker containers to be affected
"
exit 1;;
*) break;; # terminate while loop
Expand All @@ -33,9 +40,9 @@ function parseCommandLineArguments() {
done
}

####################################################################################
# Logs in to Docker
####################################################################################
#
# logs in to Docker
#
function dockerLogin() {
if [[ "$dockerUsername" = "" ]]; then
read -p "Docker username: " dockerUsername
Expand All @@ -45,27 +52,37 @@ function dockerLogin() {
read -s -p "Docker password: " dockerPassword
fi

sudo docker login -u $dockerUsername -p $dockerPassword
sudo docker login -u "$dockerUsername" -p "$dockerPassword"

if [ $? -ne 0 ]; then
echo "login failed, exiting."
exit 1
fi


}

parseCommandLineArguments $@
#
# parse arguments
#
parseCommandLineArguments "$@"

#
# update the docker containers
#
dockerLogin

echo "stopping docker containers..."
sudo docker-compose -f $dockerComposeFile stop
echo "removing old docker containers..."
sudo docker-compose -f $dockerComposeFile rm --force
echo "updating docker containers..."
sudo docker-compose -f $dockerComposeFile pull
echo "starting new docker containers..."
sudo docker-compose -f $dockerComposeFile up -d
echo "stopping docker containers $dockerContainers..."
sudo docker-compose -f "$dockerComposeFile" stop "$dockerContainers"

echo "removing old docker containers $dockerContainers..."
sudo docker-compose -f "$dockerComposeFile" rm --force "$dockerContainers"

echo "updating docker containers $dockerContainers..."
sudo docker-compose -f "$dockerComposeFile" pull "$dockerContainers"

echo "starting new docker containers $dockerContainers..."
sudo docker-compose -f "$dockerComposeFile" up -d "$dockerContainers"

echo "removing old docker images"
sudo docker system prune --all --force

sudo docker logout