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..42b9d3f 100755 --- a/update.sh +++ b/update.sh @@ -3,5 +3,12 @@ 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 --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 +. ./deployment.sh # run in global? +webhook -hooks hooks.json & # ensure installed: sudo apt-get install webhook