How to integrate Capistrano with Docker for deployment? -


i not sure question relevant may try mix tools (capistrano , docker) should not mixed.

i have dockerized application deployed capistrano. docker compose used both development , staging environments.

this how project looks (the application files not shown):

capfile docker-compose.yml docker-compose.staging.yml config/     deploy.rb     deploy         staging.rb 

the docker compose files creates necessary containers (nginx, php, mongodb, elasticsearch, etc.) run app in development or staging environment (hence specific parameters defined in docker-compose.staging.yml).

the app deployed staging environment command:

cap staging deploy 

the folder architecture on server 1 of capistrano:

current releases     20160912150720     20160912151003     20160912153905 shared 

the following command has been run in current directory of staging server instantiate necessary containers run app:

docker-compose -f docker-compose.yml -f docker-compose.staging.yml -d 

so far good. things more complicated on next deploy: current symlink point new directory of releases directory:

  • if deploy.rb defines commands need executed inside containers (like docker-compose exec php composer install php), docker tells containers don't exist yet (because existing ones created on previous release folder).
  • if docker-compose -d command executed in capistrano deployment process, errors because of port conflicts (the previous containers still exist).

do have idea on how solve issue? should move away capistrano , different?

the idea keep (near) zero-downtime deployment capistrano offers flexibility of docker containers (providing several php versions various apps on same server instance).

as far understood, using capistrano on host , redeploy whole application stack, means containers. using capistrano orchestrate building, container creation , deployment.

while basically, when running cap deploy

  • build app ( based on current base pulled on host ) - includes gulp/grunt/build tasks
  • then "package" containers using "volume mounts"
  • during start / replace containers

you 'nearly' 0 downtime deployment.

if care downtime , formalising deployment process much, should right using proper pipeline implementation for

  • packaging / ci
  • deployment / distribution

i not think capistrano can/should 1 of tools can use during strategy. capistrano meant deployment of application directly on server using ssh , git transport. using cap build whole images on target server start containers, on top, imho.

packaging / building

either use ci/cd server jenkins/bamboo/gocd build release-image application. assuming app customised in terms of 'release', lets have db , app containers/services, app include source-code , regularly change during releases..

thus cd/ci process build new app-image (release) offsite on ci server. pulling source code of application packaging image using copy , run statement compile assets ( npm / gulp / grunt whatever ). happens not on production server, on ci/cd agent.

then push release-image, lets call image yourregistry.com/yourapp private registry new 'version' deployment.

deployment

with downtime (easy)

to deploy production or staging server downtime, docker-composer stop && docker-composer up - automatically pull newer image , start in stack - app upgraded

the server should of course able pull private repository.

withou downtime (more effort)

achieving zero-downtime deployment should use blue-green deployment concept. add proxy setup , no longer expose public port app, rather using proxy public port. current live system might running on random port 21231, proxy forwarding 443 21231.

we using random ports avoid conflict during deploying "second" system, covering 1 of issue mentioned.

when redeploying, start "new" container based on new app-image in addition (to old one), gets new random port 12312 - if like, run integration tests agains 12312 directly ( not use proxy ). if done , happy, reconfigure proxy forward 12312 - remove old container (21231).

if automate proxy-reconfiguration, in detail out of scope question, can use service-discovery , registrator makes random ports more practical , makes easy reconfigure proxy, let nginx/haproxy while running. tools be, example.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -