From 687832542c28eae78faf33b05f716463bfbc8f55 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sat, 22 Feb 2020 19:53:58 +0100 Subject: [PATCH] Modified to use bootstrap archive. --- docker-compose.yml | 21 +++++---------------- start_or_update.sh | 47 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7fded96..8ee3430 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: reverse-proxy: image: reverse-proxy:$VERSION_PROXY - build: "https://git.scimetis.net/yohan/docker-reverse-proxy.git" + #build: "https://git.scimetis.net/yohan/docker-reverse-proxy.git" restart: always ports: - 80:80/tcp @@ -12,13 +12,13 @@ services: networks: - reverse-proxy volumes: - - reverse-proxy_conf:/etc/apache2/sites-available:Z - - reverse-proxy_conf_enabled:/etc/apache2/sites-enabled:Z - - reverse-proxy_letsencrypt:/etc/letsencrypt:Z + - /mnt/volumes/reverse-proxy_conf/data:/etc/apache2/sites-available:Z + - /mnt/volumes/reverse-proxy_conf_enabled/data:/etc/apache2/sites-enabled:Z + - /mnt/volumes/reverse-proxy_letsencrypt/data:/etc/letsencrypt:Z cron: image: cron:$VERSION_CRON - build: "https://git.scimetis.net/yohan/docker-cron.git" + #build: "https://git.scimetis.net/yohan/docker-cron.git" restart: always network_mode: "host" volumes: @@ -28,14 +28,3 @@ networks: reverse-proxy: external: true - -volumes: - - reverse-proxy_conf: - external: true - - reverse-proxy_conf_enabled: - external: true - - reverse-proxy_letsencrypt: - external: true diff --git a/start_or_update.sh b/start_or_update.sh index e625879..e7f26d5 100755 --- a/start_or_update.sh +++ b/start_or_update.sh @@ -1,9 +1,50 @@ #!/bin/bash +test -f ~/openrc.sh || exit 1 +source ~/openrc.sh +INSTANCE=$(~/env_py3/bin/openstack server show -c id --format value $(hostname)) +for VOLUME in reverse-proxy_conf reverse-proxy_conf_enabled reverse-proxy_letsencrypt +do + if ! mountpoint -q /mnt/volumes/${VOLUME} + then + VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show ${VOLUME} -c id --format value) + test -e /dev/disk/by-id/*${VOLUME_ID:0:20} || nova volume-attach $INSTANCE $VOLUME_ID auto + sudo mount /dev/disk/by-id/*${VOLUME_ID:0:20} /mnt/volumes/${VOLUME} + fi +done + sudo chown root. crontab sudo chmod 644 crontab + +export OS_REGION_NAME=GRA +source ~/duplicity_password.sh + +sudo docker image inspect duplicity:latest &> /dev/null ||{ echo "ERROR: duplicity:latest image not found, exiting."; exit 1; } + +rm -rf ~/build +mkdir -p ~/build +for name in docker-cron docker-reverse-proxy +do + sudo -E docker run --rm -e SWIFT_USERNAME=$OS_USERNAME \ + -e SWIFT_PASSWORD=$OS_PASSWORD \ + -e SWIFT_AUTHURL=$OS_AUTH_URL \ + -e SWIFT_AUTHVERSION=$OS_IDENTITY_API_VERSION \ + -e SWIFT_TENANTNAME=$OS_TENANT_NAME \ + -e SWIFT_REGIONNAME=$OS_REGION_NAME \ + -e PASSPHRASE=$PASSPHRASE \ + --name backup-restore -v ~/build:/mnt/build --entrypoint /bin/bash duplicity:latest \ + -c "duplicity restore --name bootstrap --file-to-restore ${name}.tar.gz swift://bootstrap /mnt/build/${name}.tar.gz" + tar -xzf ~/build/${name}.tar.gz -C ~/build/ +done + # --force-recreate is used to recreate container when crontab file has changed unset VERSION_PROXY VERSION_CRON -VERSION_PROXY=$(git ls-remote https://git.scimetis.net/yohan/docker-reverse-proxy.git| head -1 | cut -f 1|cut -c -10) \ -VERSION_CRON=$(git ls-remote https://git.scimetis.net/yohan/docker-cron.git| head -1 | cut -f 1|cut -c -10) \ - sudo -E bash -c 'docker-compose up -d --force-recreate' +DIRECTORY=$(pwd) +cd ~/build/docker-reverse-proxy; export VERSION_PROXY=$(git show-ref --head| head -1 | cut -f 1|cut -c -10); cd $DIRECTORY +cd ~/build/docker-cron; export VERSION_CRON=$(git show-ref --head| head -1 | cut -f 1|cut -c -10); cd $DIRECTORY +sudo docker build -t reverse-proxy:$VERSION_PROXY ~/build/docker-reverse-proxy +sudo docker build -t cron:$VERSION_CRON ~/build/docker-cron + +sudo -E bash -c 'docker-compose up -d --force-recreate' + +rm -rf ~/build