|
1 | | -# dock-watch |
2 | | -Python Flask service for querying the docker engine for information about deployed containers |
| 1 | +# DockWatch |
| 2 | +A system for listing out your deployed containers on a specific node. |
| 3 | +Should be running on the specific node. |
| 4 | + |
| 5 | +## Why DockWatch |
| 6 | +We do all have a full CI/CD setup, so what more do we need? |
| 7 | + |
| 8 | +Since we've might have enabled the possibility |
| 9 | +(_we do this in the **Example Setup** below_) to deploy from every |
| 10 | +branch of each repository - it's necessary to keep track of |
| 11 | +what is running on the nodes in each environment. |
| 12 | + |
| 13 | +With the DockWatch API running on each of the nodes, |
| 14 | +the DockWatch Web can list out each version of each application deployed. |
| 15 | + |
| 16 | +Through the Web component it will be possible to delete specific containers, |
| 17 | +when you feel to clean up earlier mess. |
| 18 | + |
| 19 | +### DockWatch pair |
| 20 | +The API does not necessarily need to be exposed outside the node, |
| 21 | +if you deploy the API and the Web containers side-by-side on each node. |
| 22 | +This will let you access a specific node and watch and/or clean up old deployments. |
| 23 | + |
| 24 | +### Central DockWatch Web |
| 25 | +Instead of having multiple access points for watching your deployments, |
| 26 | +it's possible to deploy one single instance of DockWatch Web and |
| 27 | +applying DockWatch API references in the Web UI. |
| 28 | + |
| 29 | + |
| 30 | +# Components |
| 31 | +System consist of two components, API and Web. |
| 32 | + |
| 33 | +### API |
| 34 | +Python Flask service for querying the docker engine. |
| 35 | +The API will return information about which images has deployed |
| 36 | +containers, what versions of each image that has containers, |
| 37 | +and the state of the containers. |
| 38 | + |
| 39 | +The API should always be running on the respective node. |
| 40 | + |
| 41 | +### Web |
| 42 | +DockWatch Web is a frontend for presenting the deployed containers |
| 43 | +on one or multiple nodes. |
| 44 | + |
| 45 | +The Web component should either be a central service, |
| 46 | +connected towards each API, or a single instance for each API deployed. |
| 47 | + |
| 48 | + |
| 49 | +# Usage |
| 50 | + |
| 51 | +## Build |
| 52 | +```bash |
| 53 | +docker build -t mabruras/dock-watch-api |
| 54 | +docker build -t mabruras/dock-watch-web |
| 55 | +``` |
| 56 | + |
| 57 | +## Deploy |
| 58 | +```bash |
| 59 | +docker run -d \ |
| 60 | + -p 5000:5000 \ |
| 61 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 62 | + mabruras/dock-watch-api |
| 63 | + |
| 64 | +docker run -d \ |
| 65 | + -p 3000:3000 \ |
| 66 | + mabruras/dock-watch-web |
| 67 | +``` |
| 68 | + |
| 69 | +## Example setup |
| 70 | + |
| 71 | +### Prerequisites |
| 72 | +* SCM (eg. Git w/`Github`) |
| 73 | +* CI-tool (eg. `Concourse`) |
| 74 | +* CD-tool (eg. `Rundeck`) |
| 75 | +* Proxy (eg. `Traefik`) |
| 76 | +* DockWatch |
| 77 | + |
| 78 | +### Flow |
| 79 | +#### SCM |
| 80 | +(_Source Control Management_) |
| 81 | + |
| 82 | +Make commits to the SCM, independent of branch, |
| 83 | +trigger the CI-tool through use of git-hooks. |
| 84 | + |
| 85 | +#### CI |
| 86 | +(_Continuous Integration_) |
| 87 | + |
| 88 | +Let the CI-tool Build/compile, |
| 89 | +or what ever the application/system requires, |
| 90 | +before it wraps the application up in a Docker image. |
| 91 | + |
| 92 | +For best result, let the docker image tags be on the following syntax: |
| 93 | +`${DCKR_REG}/${APP_NAME}:${BRANCH_NAME}`. |
| 94 | + |
| 95 | +Based on the following details (personal preference): |
| 96 | +* Application name: `Awesome App` |
| 97 | +* Registry url: `registry.example.com` |
| 98 | +* Issue tracker reference: `AA-123` |
| 99 | +* Branch name: `feature/AA-123` |
| 100 | + |
| 101 | +It's possible to create a setup like this: |
| 102 | +```bash |
| 103 | +DCKR_REG="registry.example.com" # Could be stored in the CI-tool |
| 104 | +APP_NAME="awesome-app" # Defined by the pipeline |
| 105 | +GIT_BRANCH="feature/aa-123_implement-stuff" # Should be fetched from either SCM or CI-tool |
| 106 | +VERSION=$(echo ${GIT_BRANCH##origin/} | tr "/_" -) # Replace / and _ with -, also remove "origin/" |
| 107 | + # from the branch name (optional) |
| 108 | +docker build -t ${DCKR_REG}/${APP_NAME}:${VERSION} ${PWD} |
| 109 | + |
| 110 | +# Resulting in: |
| 111 | +# registry.example.com/awesome-app:feature-aa-123-implement-stuff |
| 112 | +``` |
| 113 | + |
| 114 | +Add desired labels when building the Docker image. |
| 115 | +(All labels will be available through the API) |
| 116 | + |
| 117 | +Example labels: |
| 118 | +* `branch=${GIT_BRANCH}` |
| 119 | +* `app_name=${APP_NAME}` |
| 120 | +* `version=${VERSION}` |
| 121 | + |
| 122 | +_**TIP:** There could be a parameterized hook to |
| 123 | +auto trigger deployment to development environments_ |
| 124 | + |
| 125 | +#### CD |
| 126 | +(_Continuous Deployment_) |
| 127 | + |
| 128 | +After building the Docker image, push it to the registry, |
| 129 | +and the CI-tool should take over. |
| 130 | + |
| 131 | +`Rundeck` makes it possible to access one or more nodes, |
| 132 | +where it can be executed commands. |
| 133 | +Parameters should be: |
| 134 | +* `Application` |
| 135 | +* `Version` |
| 136 | +* `Environment` # Used to decide what nodes to access |
| 137 | +* `Registry` # If you have multiple Docker Registries |
| 138 | + |
| 139 | +Example: |
| 140 | +```bash |
| 141 | +IMG_REF="${REGISTRY}/${APPLICATION}:${VERSION}" |
| 142 | + |
| 143 | +docker run -d \ |
| 144 | + --name "${APPLICATION}-${VERSION}" \ |
| 145 | + ${IMG_REF} |
| 146 | +``` |
| 147 | + |
| 148 | +In this case, the `"${APPLICATION}-${VERSION}"` is representing the sub-domain, |
| 149 | +dependent on the Traefik configuration. |
| 150 | +So make sure `"${APPLICATION}-${VERSION}"` is "URL-friendly". |
| 151 | + |
| 152 | +When deploying, remember to include all necessary environment labels. |
| 153 | +Each label you add, will be available through the DockWatch API, |
| 154 | +and will let you modify the frontend based upon the labels. |
| 155 | + |
| 156 | +Example labels: |
| 157 | +* `environment=dev` # _Should be changed to actual environment_ |
| 158 | +* `url=app1.dev.example.com` # _Dependent on Traefik setup, |
| 159 | +container name (`app1` in this case) could represent the sub domain_ |
| 160 | + |
| 161 | +#### Proxy |
| 162 | +With `TræfIk`/traefik, you'll be able to auto detect |
| 163 | +your Docker containers, and create routes to each container. |
| 164 | + |
| 165 | +So optimal, the earlier example will result in the following accessible URL: |
| 166 | +`https://awesome-app-feature-aa-123-implement-stuff.dev.example.com` |
| 167 | + |
| 168 | +#### DockWatch |
| 169 | +DockWatch API will be running on each of the nodes, |
| 170 | +with a DockWatch Web container at it's side. |
| 171 | + |
| 172 | +The DockWatch Web is exposed through Traefik |
| 173 | +(`--label "traefik.frontend.rule='Host: dw.dev.example.com'"`) |
| 174 | +to easily access the DockWatch panel. |
0 commit comments