Add 'rebuild.sh' to rebuild a docker image

This commit is contained in:
Tom Wiesing 2020-07-07 15:49:55 +02:00
parent 5905847b1c
commit a25c12b0fa
No known key found for this signature in database
GPG key ID: DC1F29F2BC78AB15
6 changed files with 57 additions and 11 deletions

View file

@ -153,6 +153,26 @@ To do so, use:
sudo bash /distillery/provision.sh SLUG
```
## Rebuild an instance -- 'rebuild.sh'
Sometimes it becomes necessary (because of changes to this project) to rebuild the docker image running a certain docker instance.
To do so, use:
```bash
sudo bash /distillery/rebuild.sh SLUG
```
Note that rebuilding an instance does restart the docker container resulting in a small (typical < 1 second) interruption to the website in question.
Furthermore, while the container recreated, the old image stays on the host.
To delete all instances, run:
```bash
sudo docker image prune --all
```
## Purge an existing WissKI instance -- 'purge.sh'

View file

@ -41,7 +41,7 @@ function install_resource_dir() {
for filename in "$from"/*; do
dest="$to/`basename "${filename}"`"
echo "Writing \"$dest\""
cp -r "$filename" "$dest"
cp -rTv "$filename" "$dest"
done
}

View file

@ -13,4 +13,12 @@ export DEBIAN_FRONTEND=noninteractive
# This file just sets a few utility functions to be used by the code.
# randompw generates a random password as per the configuration file.
alias randompw="cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $PASSWORD_LENGTH | head -n 1"
alias randompw="cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $PASSWORD_LENGTH | head -n 1"
# update_stack fully updates a docker-compose stack in the given location.
function update_stack() {
cd "$1"
docker-compose pull
docker-compose build --pull
docker-compose up -d
}

25
distillery/rebuild.sh Normal file
View file

@ -0,0 +1,25 @@
#!/bin/bash
set -e
# read the lib/shared.sh and read the slug argument.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR"
source "$DIR/lib/lib.sh"
require_slug_argument
# if the site doesn't exist, I can't open a shell.
if ! sql_bookkeep_exists "$SLUG"; then
log_error "=> Site '$SLUG' does not exist in bookeeping table. "
echo "I can't rebuild it. "
exit 1
fi;
# Read everything from the database
read -r INSTANCE_BASE_DIR MYSQL_DATABASE MYSQL_USER GRAPHDB_REPO GRAPHDB_USER <<< "$(sql_bookkeep_load "${SLUG}" "filesystem_base,sql_database,sql_user,graphdb_repository,graphdb_user" | tail -n +2)"
log_info " => Updating compose files"
install_resource_dir "compose/runtime" "$INSTANCE_BASE_DIR"
log_info "=> Rebuilding and restarting '$INSTANCE_BASE_DIR'"
update_stack "$INSTANCE_BASE_DIR"

View file

@ -6,8 +6,9 @@ DISABLE_LOG=1
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR"
source "$DIR/lib/lib.sh"
require_slug_argument
DISABLE_LOG=0
require_slug_argument
# if the site doesn't exist, I can't open a shell.
if ! sql_bookkeep_exists "$SLUG"; then

View file

@ -6,14 +6,6 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR"
source "$DIR/lib/lib.sh"
# update_stack fully updates a docker-compose stack in the given location.
function update_stack() {
cd "$1"
docker-compose pull
docker-compose build --pull
docker-compose up -d
}
log_info "=> Rebuilding and restarting 'web' stack"
update_stack "$DEPLOY_WEB_DIR"