|
1 | 1 | # DockWatch |
2 | | -A system for listing out your deployed containers on a specific node. |
3 | | -Should be running on the specific node. |
| 2 | +An application for listing out your deployed containers on a specific node. |
4 | 3 |
|
5 | 4 | ## Why DockWatch |
6 | 5 | We do all have a full CI/CD setup, so what more do we need? |
7 | 6 |
|
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. |
| 7 | +Since we've might have enabled the possibility to deploy code from |
| 8 | +every branch in each of the repositories - it's necessary to keep |
| 9 | +track of what is running on all the nodes in each environment. |
12 | 10 |
|
13 | | -With the DockWatch API running on each of the nodes, |
14 | | -the DockWatch Web can list out each version of each application deployed. |
| 11 | +With the DockWatch running on each of the nodes in an environment, it's |
| 12 | +possible to get an overview of all running containers on each node. |
15 | 13 |
|
16 | | -Through the Web component it will be possible to delete specific containers, |
17 | | -when you feel to clean up earlier mess. |
| 14 | +Through the UI it will be possible to interact with specific containers, |
| 15 | +like delete, restart or access logs. Main focus should be to clean |
| 16 | +up earlier deployments, of feature branches that is not relevant anymore. |
18 | 17 |
|
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. |
| 18 | +~~It is possible to configure each DockWatch to access |
| 19 | +the other APIs of the other DockWatch instances. |
| 20 | +This is done runtime, by adding a new Node with name, |
| 21 | +API URL and other grouping tags~~ |
| 22 | +_Currently not implemented, WIP_ |
23 | 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 | 24 |
|
| 25 | +# Technology |
| 26 | +DockWatch mainly consist of two components; **API** and **Web**. |
29 | 27 |
|
30 | | -# Components |
31 | | -System consist of two components, API and Web. |
| 28 | +Both systems are bundled, where a Python Flask instance serves a React |
| 29 | +frontend, as well as an API for interaction with the Docker engine. |
32 | 30 |
|
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. |
| 31 | +~~̃It's not necessary to take use of the Web component for each node. |
| 32 | +Because of the possibility to add other API URLs runtime~~ |
38 | 33 |
|
39 | | -The API should always be running on the respective node. |
| 34 | +## API |
| 35 | +The API is a Python Flask service for querying the docker engine, |
| 36 | +on the node where it's deployed. It will return information about |
| 37 | +all running containers, which image they are created of, |
| 38 | +including version tags, and labels for both image and container. |
40 | 39 |
|
41 | 40 | ### 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. |
| 41 | +The Web component is a React JS system, served as static files, |
| 42 | +from the Flask server. It's responsible for presenting the API data |
| 43 | +from one ~~or multiple~~ node~~s~~. |
47 | 44 |
|
48 | 45 |
|
49 | 46 | # Usage |
50 | 47 |
|
51 | | -## Build |
| 48 | +## Getting started |
| 49 | +To just run the system, use the following command. Note that the `/var/run/docker.sock` |
| 50 | +always should be mounted, to actually access the local docker engine. |
52 | 51 | ```bash |
53 | | -docker build -t mabruras/dock-watch-api |
54 | | -docker build -t mabruras/dock-watch-web |
| 52 | +docker run -v /var/run/docker.sock:/var/run/docker.sock mabruras/dockwatch |
55 | 53 | ``` |
56 | 54 |
|
57 | | -## Deploy |
| 55 | +It's recommended to run DockWatch with the `hidden`-label, |
| 56 | +to avoid it discovering itself, and not being able shut it down through itself. |
| 57 | +Make also sure to export the `1609`-port where the application is running. |
58 | 58 | ```bash |
59 | 59 | docker run -d \ |
60 | | - -p 5000:5000 \ |
| 60 | + -p 1609:1609 \ |
| 61 | + -l "dockwatch.hidden=True" \ |
61 | 62 | -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 |
| 63 | + mabruras/dockwatch |
67 | 64 | ``` |
68 | 65 |
|
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 | 66 |
|
85 | | -#### CI |
86 | | -(_Continuous Integration_) |
| 67 | +## Standalone Applications |
| 68 | +It is possible to deploy either of the components (API and Web) standalone, |
| 69 | +even though it's recommended to always be deployed as a complete system. |
87 | 70 |
|
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 | 71 |
|
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: |
| 72 | +### Deploy |
| 73 | +You can deploy a single instance of the API, which is |
| 74 | +useful when planning to use a centralized DockWatch Web instance. |
102 | 75 | ```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 | | -``` |
| 76 | +docker build -t mabruras/dockwatch-api api |
113 | 77 |
|
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_ |
| 78 | +docker run -d \ |
| 79 | + -p 1609:1609 \ |
| 80 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 81 | + mabruras/dockwatch-api |
| 82 | +``` |
124 | 83 |
|
125 | | -#### CD |
126 | | -(_Continuous Deployment_) |
| 84 | +If there is deployed multiple singular APIs in the environment, |
| 85 | +it might be useful to only deploy a singular Web instance, without any connected API. |
| 86 | +When deploying a singular Web component, |
| 87 | +make note of the `REACT_APP_API_URL` to override the default API URL. |
| 88 | +~~There is also possible to manually add multiple other API references through the UI.~~ |
| 89 | +```bash |
| 90 | +docker build -t mabruras/dockwatch-web web |
127 | 91 |
|
128 | | -After building the Docker image, push it to the registry, |
129 | | -and the CI-tool should take over. |
| 92 | +docker run -d \ |
| 93 | + -p 3000:3000 \ |
| 94 | + -e "REACT_APP_API_URL=http://localhost:1609/api" \ |
| 95 | + mabruras/dockwatch-web |
| 96 | +``` |
130 | 97 |
|
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 |
| 98 | +### Environment Variables |
| 99 | +Currently there isn't implemented use of a configuration file, |
| 100 | +but options are available through environment variables. |
| 101 | +Make sure that your deployment includes the necessary values by modifying these. |
138 | 102 |
|
139 | | -Example: |
140 | | -```bash |
141 | | -IMG_REF="${REGISTRY}/${APPLICATION}:${VERSION}" |
| 103 | +| VARIABLE | EXAMPLE | DESCRIPTION | |
| 104 | +| :------: | :-----: | :---------: | |
| 105 | +| DW_PORT | 8080 | What port DownWatch is running on (_default: 1609_) | |
| 106 | +| REACT_APP_API_URL | http://localhost:1609/api | URL for where to access the DockWatch API | |
| 107 | +| REACT_APP_URL_LBL | app.url | What label referring to the applications URL (_default: container.url_) | |
142 | 108 |
|
143 | | -docker run -d \ |
144 | | - --name "${APPLICATION}-${VERSION}" \ |
145 | | - ${IMG_REF} |
146 | | -``` |
147 | 109 |
|
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". |
| 110 | +### Internal Labels |
| 111 | +Internal labels are those who DockWatch uses for execute extra, |
| 112 | +custom or special logic, when detecting on a container. |
151 | 113 |
|
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. |
| 114 | +#### Hidden containers |
| 115 | +It's not everything that should be exposed to the users, |
| 116 | +that's why a container can be hidden from DockWatch. |
| 117 | +Services like DockWatch should by default be hidden, |
| 118 | +and could be labeled with `dockwatch.hidden=true` to achieve this. |
155 | 119 |
|
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 | 120 |
|
161 | | -#### Proxy |
162 | | -With `TræfIk`/traefik, you'll be able to auto detect |
163 | | -your Docker containers, and create routes to each container. |
| 121 | +### Docker Compose |
| 122 | +Instead of running each and every one of the components manually, |
| 123 | +there is created Docker Compose files for handling this. |
| 124 | +These files already are preconfigured with the recommended |
| 125 | +labels and environment variables. |
164 | 126 |
|
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` |
| 127 | +```bash |
| 128 | +docker-compose -f files/docker-compose.yml build |
| 129 | +docker-compose -f files/docker-compose.yml up -d |
| 130 | +``` |
167 | 131 |
|
168 | | -#### DockWatch |
169 | | -DockWatch API will be running on each of the nodes, |
170 | | -with a DockWatch Web container at it's side. |
| 132 | +##### Override default environment variable |
| 133 | +It's important to notice that the docker-compose file contains a |
| 134 | +default to what API the Web instance is connecting towards; localhost. |
| 135 | +To override the APIs default URL, you can set the `DOCK_WATCH_API` |
| 136 | +environment variable being the address to the node running the API. |
171 | 137 |
|
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. |
| 138 | +```bash |
| 139 | +export DOCKWATCH_API="http://api.example.com" |
| 140 | +docker-compose -f files/docker-compose.yml up -d |
| 141 | +``` |
0 commit comments