7676 < div data-md-component ="skip ">
7777
7878
79- < a href ="#1-adjustments-to -the-compose-file " class ="md-skip ">
79+ < a href ="#1-adjust -the-compose-file " class ="md-skip ">
8080 Skip to content
8181 </ a >
8282
444444 < ul class ="md-nav__list " data-md-component ="toc " data-md-scrollfix >
445445
446446 < li class ="md-nav__item ">
447- < a href ="#1-adjustments-to -the-compose-file " class ="md-nav__link ">
447+ < a href ="#1-adjust -the-compose-file " class ="md-nav__link ">
448448 < span class ="md-ellipsis ">
449- 1. Adjustments to the Compose file
449+ 1. Adjust the Compose file
450450 </ span >
451451 </ a >
452452
462462</ li >
463463
464464 < li class ="md-nav__item ">
465- < a href ="#4-deploying " class ="md-nav__link ">
465+ < a href ="#3-deployingupgrading " class ="md-nav__link ">
466466 < span class ="md-ellipsis ">
467- 4. Deploying
467+ 3. Deploying/Upgrading
468+ </ span >
469+ </ a >
470+
471+ < nav class ="md-nav " aria-label ="3. Deploying/Upgrading ">
472+ < ul class ="md-nav__list ">
473+
474+ < li class ="md-nav__item ">
475+ < a href ="#flip-traffic " class ="md-nav__link ">
476+ < span class ="md-ellipsis ">
477+ Flip traffic
468478 </ span >
469479 </ a >
470480
481+ </ li >
482+
483+ </ ul >
484+ </ nav >
485+
471486</ li >
472487
473488 </ ul >
525540 < ul class ="md-nav__list " data-md-component ="toc " data-md-scrollfix >
526541
527542 < li class ="md-nav__item ">
528- < a href ="#1-adjustments-to -the-compose-file " class ="md-nav__link ">
543+ < a href ="#1-adjust -the-compose-file " class ="md-nav__link ">
529544 < span class ="md-ellipsis ">
530- 1. Adjustments to the Compose file
545+ 1. Adjust the Compose file
531546 </ span >
532547 </ a >
533548
543558</ li >
544559
545560 < li class ="md-nav__item ">
546- < a href ="#4-deploying " class ="md-nav__link ">
561+ < a href ="#3-deployingupgrading " class ="md-nav__link ">
547562 < span class ="md-ellipsis ">
548- 4. Deploying
563+ 3. Deploying/Upgrading
564+ </ span >
565+ </ a >
566+
567+ < nav class ="md-nav " aria-label ="3. Deploying/Upgrading ">
568+ < ul class ="md-nav__list ">
569+
570+ < li class ="md-nav__item ">
571+ < a href ="#flip-traffic " class ="md-nav__link ">
572+ < span class ="md-ellipsis ">
573+ Flip traffic
549574 </ span >
550575 </ a >
551576
577+ </ li >
578+
579+ </ ul >
580+ </ nav >
581+
552582</ li >
553583
554584 </ ul >
@@ -576,9 +606,9 @@ <h1>Blue/Green Deployments</h1>
576606deploy to the idle stack, test it, and when ready, swap roles — giving
577607near-zero downtime and easy rollback.</ p >
578608< p > < img alt ="Blue/Green " src ="../assets/bluegreen.png " /> </ p >
579- < h2 id ="1-adjustments-to- the-compose-file "> 1. Adjustments to the Compose file</ h2 >
580- < p > Remove the exposed ports by removing the Caddy < code > ports:</ code > section in
581- < code > compose.yaml </ code > .</ p >
609+ < h2 id ="1-adjust- the-compose-file "> 1. Adjust the Compose file</ h2 >
610+ < p > Remove the Caddy < code > ports:</ code > section in < code > compose.yaml </ code > . Instead of exposing ports
611+ in the stacks, a "front proxy" will expose ports and proxy to the active stack .</ p >
582612< p > Set < code > CADDY_SITE_ADDRESS</ code > to only < code > :80</ code > (leaving TLS termination to the front
583613proxy):</ p >
584614< div class ="highlight "> < span class ="filename "> compose.yaml</ span > < pre > < span > </ span > < code > < span class ="nt "> caddy</ span > < span class ="p "> :</ span >
@@ -594,8 +624,8 @@ <h2 id="1-adjustments-to-the-compose-file">1. Adjustments to the Compose file</h
594624< span class ="w "> </ span > < span class ="nt "> name</ span > < span class ="p "> :</ span > < span class ="w "> </ span > < span class ="l l-Scalar l-Scalar-Plain "> user-data</ span >
595625</ code > </ pre > </ div >
596626< h2 id ="2-add-a-front-proxy "> 2. Add a Front Proxy</ h2 >
597- < p > The front proxy is a single container that binds < code > : 80</ code > and < code > : 443</ code > on the server
598- and routes requests into either the Blue or Green stack.</ p >
627+ < p > The < em > front proxy</ em > is a single container that binds ports < code > 80</ code > and < code > 443</ code > on the
628+ server and routes requests into either the Blue or Green stack.</ p >
599629< p > On the server, create a simple < code > Caddyfile</ code > :</ p >
600630< div class ="highlight "> < span class ="filename "> Caddyfile</ span > < pre > < span > </ span > < code > api.myapp.com {
601631 reverse_proxy blue_caddy:80
@@ -623,12 +653,23 @@ <h2 id="2-add-a-front-proxy">2. Add a Front Proxy</h2>
623653< span class ="w "> </ span > --network< span class ="w "> </ span > green_default< span class ="w "> </ span > < span class ="se "> \</ span >
624654< span class ="w "> </ span > caddy:2
625655</ code > </ pre > </ div >
626- < h2 id ="4-deploying "> 4. Deploying</ h2 >
627- < p > Update the idle stack:</ p >
628- < div class ="highlight "> < pre > < span > </ span > < code > docker< span class ="w "> </ span > compose< span class ="w "> </ span > pull
629- docker< span class ="w "> </ span > compose< span class ="w "> </ span > -p< span class ="w "> </ span > green< span class ="w "> </ span > up< span class ="w "> </ span > -d
656+ < h2 id ="3-deployingupgrading "> 3. Deploying/Upgrading</ h2 >
657+ < p > Deploying is the same as < a href ="../deploying/ "> before</ a > , but now we're deploying the
658+ < em > idle stack</ em > . For this example, < code > green</ code > is idle so that's the one we're
659+ deploying.</ p >
660+ < p > Create < code > blue</ code > and < code > green</ code > directories on the server and deploy < code > compose.yaml</ code >
661+ into the idle stack's directory:</ p >
662+ < div class ="highlight "> < pre > < span > </ span > < code > scp< span class ="w "> </ span > compose.yaml< span class ="w "> </ span > youruser@yourserver:green/compose.yaml
663+ </ code > </ pre > </ div >
664+ < p > Shell into the server and bring up the idle stack:</ p >
665+ < div class ="highlight "> < pre > < span > </ span > < code > < span class ="nb "> cd</ span > < span class ="w "> </ span > green
666+ docker< span class ="w "> </ span > compose< span class ="w "> </ span > pull
667+ docker< span class ="w "> </ span > compose< span class ="w "> </ span > up< span class ="w "> </ span > -d
630668</ code > </ pre > </ div >
631- < p > Edit the front proxy's config to flip traffic:</ p >
669+ < p > Docker will use the directory name < code > green</ code > as the project name, creating
670+ different containers, volumes and networks than the < code > blue</ code > stack.</ p >
671+ < h3 id ="flip-traffic "> Flip traffic</ h3 >
672+ < p > Point traffic to the < code > green</ code > stack, and make < code > blue</ code > idle:</ p >
632673< div class ="highlight "> < span class ="filename "> Caddyfile</ span > < pre > < span > </ span > < code > api.myapp.com {
633674 reverse_proxy green_caddy:80
634675}
@@ -637,11 +678,11 @@ <h2 id="4-deploying">4. Deploying</h2>
637678 reverse_proxy blue_caddy:80
638679}
639680</ code > </ pre > </ div >
640- < p > Restart Caddy :</ p >
681+ < p > Reload the front proxy's config :</ p >
641682< div class ="highlight "> < pre > < span > </ span > < code > docker< span class ="w "> </ span > < span class ="nb "> exec</ span > < span class ="w "> </ span > front-proxy< span class ="w "> </ span > caddy< span class ="w "> </ span > reload
642683</ code > </ pre > </ div >
643684< p > Cutover is instant. Green is now live, and Blue is the idle stack.</ p >
644- < p > And rollback is simple: flip the < code > Caddyfile</ code > back and < code > caddy reload</ code > .</ p >
685+ < p > And rollback is simple: flip the < code > Caddyfile</ code > back and < code > caddy reload</ code > again .</ p >
645686
646687
647688
0 commit comments