|
76 | 76 | <div data-md-component="skip"> |
77 | 77 |
|
78 | 78 |
|
79 | | - <a href="#1-caddy" class="md-skip"> |
| 79 | + <a href="#1-create-a-docker-network" class="md-skip"> |
80 | 80 | Skip to content |
81 | 81 | </a> |
82 | 82 |
|
|
444 | 444 | <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> |
445 | 445 |
|
446 | 446 | <li class="md-nav__item"> |
447 | | - <a href="#1-caddy" class="md-nav__link"> |
| 447 | + <a href="#1-create-a-docker-network" class="md-nav__link"> |
448 | 448 | <span class="md-ellipsis"> |
449 | | - 1. Caddy |
| 449 | + 1. Create a Docker Network |
450 | 450 | </span> |
451 | 451 | </a> |
452 | 452 |
|
453 | | - <nav class="md-nav" aria-label="1. Caddy"> |
| 453 | +</li> |
| 454 | + |
| 455 | + <li class="md-nav__item"> |
| 456 | + <a href="#2-adjust-caddy" class="md-nav__link"> |
| 457 | + <span class="md-ellipsis"> |
| 458 | + 2. Adjust Caddy |
| 459 | + </span> |
| 460 | + </a> |
| 461 | + |
| 462 | + <nav class="md-nav" aria-label="2. Adjust Caddy"> |
454 | 463 | <ul class="md-nav__list"> |
455 | 464 |
|
456 | 465 | <li class="md-nav__item"> |
457 | | - <a href="#set-the-caddy-container-name-explicitly" class="md-nav__link"> |
| 466 | + <a href="#name-the-caddy-containers" class="md-nav__link"> |
458 | 467 | <span class="md-ellipsis"> |
459 | | - Set the Caddy container name explicitly |
| 468 | + Name the Caddy containers |
460 | 469 | </span> |
461 | 470 | </a> |
462 | 471 |
|
|
603 | 612 | <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> |
604 | 613 |
|
605 | 614 | <li class="md-nav__item"> |
606 | | - <a href="#1-caddy" class="md-nav__link"> |
| 615 | + <a href="#1-create-a-docker-network" class="md-nav__link"> |
| 616 | + <span class="md-ellipsis"> |
| 617 | + 1. Create a Docker Network |
| 618 | + </span> |
| 619 | + </a> |
| 620 | + |
| 621 | +</li> |
| 622 | + |
| 623 | + <li class="md-nav__item"> |
| 624 | + <a href="#2-adjust-caddy" class="md-nav__link"> |
607 | 625 | <span class="md-ellipsis"> |
608 | | - 1. Caddy |
| 626 | + 2. Adjust Caddy |
609 | 627 | </span> |
610 | 628 | </a> |
611 | 629 |
|
612 | | - <nav class="md-nav" aria-label="1. Caddy"> |
| 630 | + <nav class="md-nav" aria-label="2. Adjust Caddy"> |
613 | 631 | <ul class="md-nav__list"> |
614 | 632 |
|
615 | 633 | <li class="md-nav__item"> |
616 | | - <a href="#set-the-caddy-container-name-explicitly" class="md-nav__link"> |
| 634 | + <a href="#name-the-caddy-containers" class="md-nav__link"> |
617 | 635 | <span class="md-ellipsis"> |
618 | | - Set the Caddy container name explicitly |
| 636 | + Name the Caddy containers |
619 | 637 | </span> |
620 | 638 | </a> |
621 | 639 |
|
@@ -732,16 +750,35 @@ <h1>Blue/Green Deployments</h1> |
732 | 750 | deploy to the idle stack, test it, and when ready, swap roles — giving |
733 | 751 | near-zero downtime and easy rollback.</p> |
734 | 752 | <p><img alt="Blue/Green" src="../assets/bluegreen.png" /></p> |
735 | | -<h2 id="1-caddy">1. Caddy</h2> |
736 | | -<h3 id="set-the-caddy-container-name-explicitly">Set the Caddy container name explicitly</h3> |
737 | | -<p>This allows us to switch between the two stacks:</p> |
| 753 | +<h2 id="1-create-a-docker-network">1. Create a Docker Network</h2> |
| 754 | +<p>Blue/Green adds some complexity because where before there was just "the |
| 755 | +stack", now you have:</p> |
| 756 | +<ol> |
| 757 | +<li>A <code>blue</code> stack</li> |
| 758 | +<li>A <code>green</code> stack</li> |
| 759 | +<li>A front proxy to direct traffic</li> |
| 760 | +<li>An external Postgres.</li> |
| 761 | +</ol> |
| 762 | +<p>Create a network to link them:</p> |
| 763 | +<div class="highlight"><pre><span></span><code>docker<span class="w"> </span>network<span class="w"> </span>create<span class="w"> </span>app |
| 764 | +</code></pre></div> |
| 765 | +<p>And add it to the Compose file:</p> |
| 766 | +<div class="highlight"><span class="filename">compose.yaml</span><pre><span></span><code><span class="nt">networks</span><span class="p">:</span> |
| 767 | +<span class="w"> </span><span class="nt">default</span><span class="p">:</span> |
| 768 | +<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">app</span> |
| 769 | +<span class="w"> </span><span class="nt">external</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">true</span> |
| 770 | +</code></pre></div> |
| 771 | +<h2 id="2-adjust-caddy">2. Adjust Caddy</h2> |
| 772 | +<h3 id="name-the-caddy-containers">Name the Caddy containers</h3> |
| 773 | +<p>Naming the Caddy containers <code>blue_caddy</code> and <code>green_caddy</code> allows the front |
| 774 | +proxy to direct traffic to the correct stacks:</p> |
738 | 775 | <div class="highlight"><span class="filename">compose.yaml</span><pre><span></span><code><span class="nt">caddy</span><span class="p">:</span> |
739 | 776 | <span class="w"> </span><span class="nt">container_name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">${STACK_NAME}_caddy</span> |
740 | 777 | </code></pre></div> |
741 | 778 | <h3 id="remove-exposed-ports">Remove exposed ports</h3> |
742 | | -<p>Remove the <code>caddy</code> service's <code>ports:</code> section in <code>compose.yaml</code>.</p> |
743 | | -<p>We'll no longer expose ports in the stacks, instead a simple "front proxy" will |
744 | | -sit in front of the two stacks, proxying to the active stack.</p> |
| 779 | +<p>We'll no longer expose ports in the stacks, instead a front proxy will sit in |
| 780 | +front of the two stacks, proxying to them.</p> |
| 781 | +<p>So remove the <code>caddy</code> service's <code>ports:</code> section in <code>compose.yaml</code>.</p> |
745 | 782 | <h3 id="serve-http-only-in-the-stacks">Serve HTTP-only in the stacks</h3> |
746 | 783 | <p>Set <code>CADDY_SITE_ADDRESS</code> to only <code>:80</code>, removing <code>:443</code> (leaving TLS |
747 | 784 | termination to the front proxy):</p> |
@@ -771,7 +808,7 @@ <h2 id="4-bring-up-two-stacks">4. Bring up two Stacks</h2> |
771 | 808 | <p>Shell into the server and bring up the idle stack:</p> |
772 | 809 | <div class="highlight"><pre><span></span><code><span class="nb">cd</span><span class="w"> </span>green |
773 | 810 | docker<span class="w"> </span>compose<span class="w"> </span>pull |
774 | | -docker<span class="w"> </span>compose<span class="w"> </span>up<span class="w"> </span>-d |
| 811 | +<span class="nv">STACK_NAME</span><span class="o">=</span>green<span class="w"> </span>docker<span class="w"> </span>compose<span class="w"> </span>up<span class="w"> </span>-d |
775 | 812 | </code></pre></div> |
776 | 813 | <p>Docker will use the directory name <code>green</code> as the project name, creating |
777 | 814 | different containers, volumes and networks than the <code>blue</code> stack.</p> |
|
0 commit comments