From 741ce35913c731452aeeba926459f01d0b56c583 Mon Sep 17 00:00:00 2001 From: Ardalan Mirzaei Date: Tue, 21 Jun 2022 13:22:21 +1000 Subject: [PATCH 1/3] intial push This is for issue #41 to minimise downtime. --- deployment.sh | 24 ++++++++++++++++++++++++ docker-compose.traefik.yml | 22 ++++++++++++++++++++++ docker-compose.yml | 13 ------------- hooks.json | 8 ++++++++ update.sh | 7 ++++++- 5 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 deployment.sh create mode 100644 docker-compose.traefik.yml create mode 100644 hooks.json diff --git a/deployment.sh b/deployment.sh new file mode 100644 index 0000000..6f1d7d3 --- /dev/null +++ b/deployment.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +git reset --hard HEAD +git pull + +if [ $(docker ps -f name=blue -q) ] +then + ENV="green" + OLD="blue" +else + ENV="blue" + OLD="green" +fi + +echo $ENV > ./updater/container_version + +echo "Starting "$ENV" container" +docker-compose --project-name=$ENV up -d + +echo "Waiting..." +sleep 5s + +echo "Stopping "$OLD" container" +docker-compose --project-name=$OLD stop diff --git a/docker-compose.traefik.yml b/docker-compose.traefik.yml new file mode 100644 index 0000000..95a9e19 --- /dev/null +++ b/docker-compose.traefik.yml @@ -0,0 +1,22 @@ +version: "3" + +services: + traefik: + image: traefik:alpine + ports: + - 80:80 + - 443:443 + networks: + - web + - default + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ./traefik/traefik.toml:/traefik.toml + - ./shared_config/acme.json:/acme.json + +volumes: + nginx_cache: + +networks: + web: + external: true \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 6bbe290..bbdfa76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,19 +43,6 @@ services: - traefik.enable=true - traefik.port=80 - traefik: - image: traefik:alpine - ports: - - 80:80 - - 443:443 - networks: - - web - - default - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - ./traefik/traefik.toml:/traefik.toml - - ./shared_config/acme.json:/acme.json - volumes: nginx_cache: diff --git a/hooks.json b/hooks.json new file mode 100644 index 0000000..42b10b2 --- /dev/null +++ b/hooks.json @@ -0,0 +1,8 @@ +[ + { + "id": "deployupdate", + "execute-command":"/deployment.sh", + "command-working-directory": "/", + "response-message": "Pushing new updates to server." + } +] diff --git a/update.sh b/update.sh index 5d164ea..559b949 100755 --- a/update.sh +++ b/update.sh @@ -3,5 +3,10 @@ git reset --hard HEAD git pull touch shared_config/acme.json & chmod 600 shared_config/acme.json +docker-compose down -f docker-compose.traefik.yml docker-compose down -docker-compose up --force-recreate --build -d \ No newline at end of file +docker-compose up -f docker-compose.traefik.yml --force-recreate --build -d +# docker-compose up --force-recreate --build -d +chmod 600 ./deployment.sh +. ./deployment.sh # run in global? +webhook -hooks hooks.json & # ensure installed: sudo apt-get install webhook From dc8c88b2447c77aacac221f780c9d6a0708eb9a4 Mon Sep 17 00:00:00 2001 From: Ardalan Mirzaei Date: Tue, 21 Jun 2022 13:38:05 +1000 Subject: [PATCH 2/3] make deployment executable --- update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.sh b/update.sh index 559b949..c96e694 100755 --- a/update.sh +++ b/update.sh @@ -7,6 +7,6 @@ docker-compose down -f docker-compose.traefik.yml docker-compose down docker-compose up -f docker-compose.traefik.yml --force-recreate --build -d # docker-compose up --force-recreate --build -d -chmod 600 ./deployment.sh +chmod +x ./deployment.sh . ./deployment.sh # run in global? webhook -hooks hooks.json & # ensure installed: sudo apt-get install webhook From fb8c31adfdb5a0580d3474df56e6bc2f273dddf1 Mon Sep 17 00:00:00 2001 From: Ardalan Mirzaei Date: Tue, 21 Jun 2022 13:40:25 +1000 Subject: [PATCH 3/3] Update update.sh --- update.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/update.sh b/update.sh index c96e694..42b9d3f 100755 --- a/update.sh +++ b/update.sh @@ -5,6 +5,8 @@ git pull touch shared_config/acme.json & chmod 600 shared_config/acme.json docker-compose down -f docker-compose.traefik.yml docker-compose down +docker-compose --project-name=blue stop +docker-compose --project-name=green stop docker-compose up -f docker-compose.traefik.yml --force-recreate --build -d # docker-compose up --force-recreate --build -d chmod +x ./deployment.sh