Skip to content
This repository was archived by the owner on Dec 8, 2020. It is now read-only.
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

production deploy with zero server downtime #2

@boris-brtan

Description

@boris-brtan

Requirements

there is need to start maintenance page on the running container during the build of temporary container if there are some db changes.
after this issue will be fixed shopsys/shopsys#469 it will be possible to check whether in new version there are some db changes.

Idea on how to do it

We also want to have zero downtime deploy of the application during the deployment so we would need some shell script for it.
One possibility is to create temporary container from the new built image and temporary redirect bandwidth on it.

# make sure old deploy service with data is cleared
docker-compose -p production rm -fsv php-fpm-deploy
docker volume rm production_deploy-web-volume

# create container of deploy service with new data and image
docker-compose -p production up -d --force-recreate --no-deps -V php-fpm-deploy

docker-compose -p production exec -T php-fpm-deploy php phing build-deploy-part-1-db-independent

# check for new db migrations so the running container will be set to maintenance mode
no_db_changes=$(docker-compose -p production exec -T php-fpm-deploy php phing db-migrations-count | grep 'No migrations to execute' | wc -l)
if [ $no_db_changes -ne "1" ]; then php phing maintenance-on; fi
docker-compose -p production exec -T php-fpm php phing build-deploy-part-2-db-dependent

# change route to temporary container
rm -f web && ln -s /var/lib/docker/volumes/production_deploy-web-volume/_data/ web
sed -i 's/ php-fpm:9000/ php-fpm-deploy:9000/' /var/lib/docker/volumes/production_nginx-conf/_data/nginx.conf
docker-compose -p production up --no-deps -d -V webserver

# rebuild primary container
docker-compose -p production rm -fsv php-fpm
docker volume rm production_web-volume
docker-compose -p production up -d --force-recreate --no-deps -V php-fpm
docker-compose -p production exec -T php-fpm php phing build

# reroute to primary container
rm -f web && ln -s /var/lib/docker/volumes/production_web-volume/_data/ web
sed -i 's/ php-fpm-deploy:9000/ php-fpm:9000/' /var/lib/docker/volumes/production_nginx-conf/_data/nginx.conf
docker-compose -p production up --no-deps -d -V webserver

# clear temporary container
docker-compose -p production rm -fsv php-fpm-deploy
docker volume rm production_deploy-web-volume

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions