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

Deploy without downtime #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions deployment.sh
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions docker-compose.traefik.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
8 changes: 8 additions & 0 deletions hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"id": "deployupdate",
"execute-command":"/deployment.sh",
"command-working-directory": "/",
"response-message": "Pushing new updates to server."
}
]
9 changes: 8 additions & 1 deletion update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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