You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-30Lines changed: 75 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Docker-Blue-Green-Runner
2
2
3
-
> A Simple and Safe Blue-Green Deployment Starting from Your Source Code—Not from Your Prebuilt Docker Image
3
+
> An Isomorphic Blue-Green Deployment Starting from Your Source Code—Not from Your Prebuilt Docker Image
4
4
5
5
> [NOTE] To upgrade your app from v5 to v6, update your .env file with the following settings and proceed:
6
6
```.dotenv
@@ -50,39 +50,44 @@
50
50
## Features
51
51
52
52
1.**Achieve zero-downtime deployment using just your ``.env`` and ``Dockerfile``**
53
-
- Docker-Blue-Green-Runner's `run.sh` script is designed to simplify deployment: "With your `.env`, project, and a single Dockerfile, simply run 'bash run.sh'." This script covers the entire process from Dockerfile build to server deployment from scratch.
53
+
- Docker-Blue-Green-Runner's `run.sh` script is designed to simplify deployment: "With your `.env`, project, and a single Dockerfile, simply run 'bash run.sh'." If you prefer not to use `sudo`, see [WITH_SUDO](#with_sudo), set it in your `.env`, and run `apply-security.sh` first. This script covers the entire process from Dockerfile build to server deployment from scratch.
54
54
- This means you can easily migrate to another server with just the files mentioned above.
55
55
- In contrast, Traefik requires the creation and gradual adjustment of various configuration files, which requires your App's docker binary running.
56
56
57
57
58
-
2.**No unpredictable errors in reverse proxy and deployment : Implement safety measures to handle errors caused by your app or Nginx**
59
-
- If any error occurs in the app or router, ``deployment is halted`` to prevent any impact on the existing deployment
60
-
- Internal Integrity Check:
61
-
- Step 1: Use wait-for-it.sh (https://github.com/vishnubob/wait-for-it)
62
-
- Step 2: Perform a health check with customized settings defined in your .env file
63
-
- Nginx Router Test Container
64
-
- External Integrity Check
65
-
- Rollback Procedures
66
-
- Additional Know-hows on Docker: Tips and best practices for optimizing your Docker workflow and deployment processes
67
-
- For example, Traefik offers powerful dynamic configuration and service discovery; however, certain errors, such as a failure to detect containers (due to issues like unrecognized certificates), can lead to frustrating 404 errors that are hard to trace through logs alone.
- Manipulates NGINX configuration files directly to ensure container accessibility.
58
+
2.**[Beta] Isomorphic local-and-remote runner**
59
+
- The same `run.sh` and `.env` drive deployments locally and on remote servers over SSH.
60
+
- Remote servers receive the image binary and execute the same pipeline with `GIT_IMAGE_LOAD_FROM=file` (see [Production > GIT_IMAGE_LOAD_FROM=file](#1-git_image_load_fromfile-strategy-without-docker-registry)).
61
+
- Behavior stays consistent across environments; only the image source differs (build/registry/file).
71
62
63
+
3.**No unpredictable errors in reverse proxy and deployment : Implement safety measures to handle errors caused by your app or Nginx**
64
+
- If any error occurs in the app or router, ``deployment is halted`` to prevent any impact on the existing deployment
65
+
- Internal Integrity Check:
66
+
- Step 1: Use wait-for-it.sh (https://github.com/vishnubob/wait-for-it)
67
+
- Step 2: Perform a health check with customized settings defined in your .env file
68
+
- Nginx Router Test Container
69
+
- External Integrity Check
70
+
- Rollback Procedures
71
+
- Additional Know-hows on Docker: Tips and best practices for optimizing your Docker workflow and deployment processes
72
+
- For example, Traefik offers powerful dynamic configuration and service discovery; however, certain errors, such as a failure to detect containers (due to issues like unrecognized certificates), can lead to frustrating 404 errors that are hard to trace through logs alone.
- Run `bash check-current-states.sh` locally and `bash check-remote-current-states.sh` to fan out the same check to all configured remotes
81
+
-
82
+
-
83
+

80
84
81
-
4.**Security**
85
+
86
+
5.**Security**
82
87
- Refer to the [Security](#Security) section
83
88
84
89
85
-
5.**Production Deployment**
90
+
6.**Production Deployment**
86
91
- Refer to the [Production Deployment](#production-deployment) section
87
92
88
93
## Process Summary
@@ -255,6 +260,14 @@ sudo bash run.sh
255
260
256
261
### Information on Environment Variables
257
262
263
+
#### ``WITH_SUDO``
264
+
```dotenv
265
+
WITH_SUDO=true
266
+
```
267
+
- When `true`, the runner executes privileged operations with `sudo` where needed.
268
+
- When `false`, `sudo` is not used. After installing Docker-Blue-Green-Runner, follow the steps in the [Security](#security) section and then run the root-level `apply-security.sh` to set secure permissions. Also, grant appropriate host permissions for Docker, Nginx, and related resources to the user running the runner.
269
+
- For security, it is recommended to keep this `false` where possible and rely on proper host permissions and ACLs instead of broad sudo usage.
- Up to this point, your app has been running in a Docker container through the ``bash.run.sh`` command, enabling continuous Blue-Green deployments. However, you may want to deploy the built Docker image independently to another environment, and you likely wouldn't want to leave unnecessary source code, except for the Docker images and configuration files, on the production server.
461
-
- It is recommended to automate this process using Jenkins.
474
+
- The key environment variable enabling this is the ``GIT_IMAGE_LOAD_FROM``. Up to this point, ``GIT_IMAGE_LOAD_FROM`` has been set to ``build``.
475
+
476
+
### 1. ``GIT_IMAGE_LOAD_FROM=file`` strategy (Beta. without Docker Registry)
F[Git] -->|Github Action or Jenkins| E[Build Server]
487
+
```
488
+
- Set the Load Balancer to use "Round-Robin"
489
+
- What is "Round-Robin"?
490
+
- Round-robin is a load-balancing method that distributes incoming requests evenly across all available servers in a sequential order. For example, the first request goes to Server 1, the second request to Server 2, the third request to Server 3, and then it cycles back to Server 1. This ensures a balanced distribution of traffic across the servers.
491
+
- Your Github Action or Jenkins scripts just send the source codes to the Build Server or run ``git pull`` on the server.
492
+
- Set the 'Docker-Blue-Green-Runner' on the Build Server, and run ``run.sh`` with ``ONLY_BUILDING_APP_IMAGE_FOR_PRODUCTION``set to ``true``.
493
+
- The ``ONLY_BUILDING_APP_IMAGE_FOR_PRODUCTION=true`` creates the Docker binary file to ``./.docker/binary``
494
+
- If ``REMOTE_DEPLOYMENT_RUNNER_PATH``, ``REMOTE_DEPLOYMENT_IP_ADDRESS_LIST``, ``REMOTE_DEPLOYMENT_PORT_NUMBER_LIST``, and ``REMOTE_DEPLOYMENT_SSH_PRIVATE_KEY_LOCAL_PATH_WITH_FILE`` are set:
495
+
- The Runner automatically copies the binary to each server at ``${REMOTE_DEPLOYMENT_RUNNER_PATH}/.docker/binary``.
496
+
- If ``REMOTE_DEPLOYMENT_FAILURE_STRATEGY`` is set (``stop``|``rollback``|``go``), the Runner connects via SSH and executes ``sudo bash run.sh`` on each server after pre-checks (``GIT_IMAGE_LOAD_FROM=file`` and sudo). Failures follow the configured strategy.
497
+
- If ``REMOTE_DEPLOYMENT_FAILURE_STRATEGY`` is NOT set, you can perform the steps manually:
498
+
- Set ``GIT_IMAGE_LOAD_FROM=file`` on each server.
499
+
- Copy the binary to each server's ``${REMOTE_DEPLOYMENT_RUNNER_PATH}/.docker/binary``.
500
+
- Run ``run.sh`` on ``Server 1``; if any issues are found, run ``rollback.sh``.
501
+
- If no problems are detected, run ``run.sh`` on both ``Server 2`` and ``Server 3``.
462
502
463
-
### Upload Image (CI/CD Server -> Git)
503
+
- Tip: For smooth permission and volume access, include the UID of the ``REMOTE_DEPLOYMENT_SSH_USER`` in ``UIDS_BELONGING_TO_SHARED_VOLUME_GROUP_ID`` (in your `.env`).
504
+
505
+
- CI tip: If you set ``REMOTE_DEPLOYMENT_SSH_PRIVATE_KEY_LOCAL_PATH_WITH_FILE`` and ``REMOTE_DEPLOYMENT_SSH_USER`` to match your GitHub Actions credentials, and your workflow triggers ``sudo bash run.sh`` on the build server, then with ``REMOTE_DEPLOYMENT_FAILURE_STRATEGY`` configured, the Runner can perform end-to-end distribution and remote execution in a single run.
- If you run the ``push-to-git.sh`` command, it pushes the container image currently running on the test server to the ``Git Container Registry`` at the specified address.
- Place your CA's root certificate (.crt file) in /usr/local/share/ca-certificates/ and run sudo update-ca-certificates.
479
525
480
-
### Download Image (Git -> Production Server)
526
+
#### Download Image (Git -> Production Server)
481
527
- Your production server should have docker-blue-green-runner, .env, and run ``run.sh`` to deploy the built images above.
482
528
- The only difference is to set``GIT_IMAGE_LOAD_FROM=registry`` instead of ``GIT_IMAGE_LOAD_FROM=build``.
483
529
- When ``GIT_IMAGE_LOAD_FROM`` is set to ``build``, docker-blue-green-runner ``builds your Dockerfile``. However, when it is set to ``registry``, the runner ``downloads your images from the Git Container registry``.
- Round-robin is a load-balancing method that distributes incoming requests evenly across all available servers in a sequential order. For example, the first request goes to Server 1, the second request to Server 2, the third request to Server 3, and then it cycles back to Server 1. This ensures a balanced distribution of traffic across the servers.
508
-
- Set the 'Docker-Blue-Green-Runner' on each server.
553
+
- Set the 'Docker-Blue-Green-Runner' on each server with ``GIT_IMAGE_LOAD_FROM``set to ``registry``.
509
554
- Run ``run.sh`` on ``Server 1``
510
555
- Check the logs on ``Server 1``, if any issues are found, run the command``rollback.sh``.
511
556
- If no problems are detected, run the command``run.sh`` on both ``Server 2`` and ``Server 3``.
0 commit comments