Git Product home page Git Product logo

Comments (3)

maxhelias avatar maxhelias commented on July 29, 2024 1

Hi @BurningDog,

  1. I don't know very well either docker swarm but it seems that it is necessary to mention the image name on the service. Something like this :
php:
    image: php
    build:
      context: .
      target: symfony_php
   ....

And before, you will have to create the image beforehand and just use image property.

  1. For the switch, unfortunately I couldn't help you... But look at the docker swarm side, with tags from the image, there may be a management on this side that allows to attach / detach a service juste like for the scale.

  2. With redis, I recommend you to use https://github.com/snc/SncRedisBundle for session and cache.

Note: Don't forget also the managed file store for uploads or other. (the Flysytem library is very interesting for this purpose)

I hope this will help you

from symfony-docker.

BurningDog avatar BurningDog commented on July 29, 2024

I've ended up writing a bash script which does a blue/green deployment with the php container, extending this idea here: https://coderbook.com/@marcus/how-to-do-zero-downtime-deployments-of-docker-containers/

Unfortunately that means duplicating the entire php service in docker-compose.yml, calling one php-blue and the other php-green, but it works.

I've created a new environment variable, PHP_CONTAINER=php-blue, and in the Caddyfile I've set php_fastcgi {$PHP_CONTAINER}:9000. On deploy, I check whether blue or green is active, then spin up the other. Once the container is successfully running, tell Caddy to use it.

Like so:

#!/bin/sh
# Uses the blue-green deployment pattern to spin up a new container then tell Caddy to use it.
if [ $(docker ps -f name=php-blue -q) ]
then
    ENV="php-green"
    OLD="php-blue"
else
    ENV="php-blue"
    OLD="php-green"
fi

# Output colours - see https://stackoverflow.com/a/5947802/339213
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color

DOCKER_COMPOSE="SYMFONY_VERSION=4.4.* PHP_VERSION=7.4 docker-compose --env-file=.env.local -f docker-compose.yml -f docker-compose.prod.yml"

echo -e "${BLUE}DEPLOY${NC} Rebuilding and starting "$ENV" container"
eval $DOCKER_COMPOSE up -d --build $ENV

# Give it max 2 minutes
i=0
while ! docker ps -f name=$ENV | grep healthy
do
  sleep 1s
  ((i=i+1))
  if [ $i -eq 120 ]
  then
    echo -e "${RED}DEPLOY${NC} Timed out after 2 minutes."
    exit 1
  fi
done

echo -e "${BLUE}DEPLOY${NC} Switching Caddy from $OLD to $ENV"
docker-compose exec -e PHP_CONTAINER=$ENV caddy caddy reload -config /etc/caddy/Caddyfile
echo -e "${BLUE}DEPLOY${NC} Caddy switched from $OLD to $ENV"

echo -e "${BLUE}DEPLOY${NC} Waiting..."
sleep 5s

echo -e "${BLUE}DEPLOY${NC} Stopping "$OLD" container"
docker-compose stop $OLD

Is there a better way of doing this?

2 php containers also means that sessions need to be moved to something like Redis, so I've added that into my docker-compose.yml file along with a redis network which is also used be the php containers. This requires adding the following into php/conf.d/symfony.prod.ini:

session.save_handler = redis
session.save_path = "tcp://redis:6379?weight=1&timeout=2.5"

from symfony-docker.

maxhelias avatar maxhelias commented on July 29, 2024

I closed it due to lack of activity. Do not hesitate to reopen the issue if needed.

from symfony-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.