Skip to content

Commit 9181a8b

Browse files
author
Magnus Brurås
authored
Merge pull request #5 from mabruraas/develop
Release 0.1
2 parents 4860422 + aafff35 commit 9181a8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+13161
-170
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.idea
22
*.iml
33

4+
web/node_modules
5+
web/package-lock.json
6+
47
# Byte-compiled / optimized / DLL files
58
__pycache__/
69
*.py[cod]

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM node:lts-alpine
2+
3+
ENV DW_HOME /opt/dockwatch
4+
5+
6+
# Python
7+
WORKDIR ${DW_HOME}/api
8+
COPY ./api .
9+
10+
RUN apk update \
11+
&& apk add \
12+
--no-cache \
13+
python3 \
14+
&& python3 -m ensurepip \
15+
&& rm -r /usr/lib/python*/ensurepip
16+
17+
RUN pip3 install \
18+
flask-cors \
19+
docker \
20+
Flask \
21+
&& rm -r /root/.cache
22+
23+
24+
# Yarn/NPM
25+
WORKDIR ${DW_HOME}/web
26+
COPY ./web .
27+
RUN yarn install \
28+
&& yarn --prod build \
29+
&& npm install -g react-scripts \
30+
&& react-scripts build
31+
32+
33+
EXPOSE 1609
34+
WORKDIR ${DW_HOME}
35+
CMD [ "python3", "api/app.py" ]

README.md

Lines changed: 97 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,141 @@
11
# 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.
43

54
## Why DockWatch
65
We do all have a full CI/CD setup, so what more do we need?
76

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.
1210

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.
1513

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.
1817

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_
2323

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.
2824

25+
# Technology
26+
DockWatch mainly consist of two components; **API** and **Web**.
2927

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.
3230

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~~
3833

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.
4039

4140
### 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~~.
4744

4845

4946
# Usage
5047

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.
5251
```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
5553
```
5654

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.
5858
```bash
5959
docker run -d \
60-
-p 5000:5000 \
60+
-p 1609:1609 \
61+
-l "dockwatch.hidden=True" \
6162
-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
6764
```
6865

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.
8466

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.
8770

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.
9171

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.
10275
```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
11377

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+
```
12483

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
12791

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+
```
13097

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.
138102

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_) |
142108

143-
docker run -d \
144-
--name "${APPLICATION}-${VERSION}" \
145-
${IMG_REF}
146-
```
147109

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.
151113

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.
155119

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_
160120

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.
164126

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+
```
167131

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.
171137

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+
```

api/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ FROM python:3.7
22

33
MAINTAINER Brurås, Magnus <mabruraas@gmail.com>
44

5-
ENV WRK_DIR /opt/dockwatch
5+
ENV WRK_DIR /opt/dockwatch-api
66

77
RUN pip3 install \
8-
docker \
9-
Flask
8+
flask-cors \
9+
docker \
10+
Flask
1011

11-
COPY ./* ${WRK_DIR}
12+
COPY ./* ${WRK_DIR}/
1213

1314
WORKDIR ${WRK_DIR}
14-
EXPOSE 5000
15+
EXPOSE 1609
1516

1617
CMD [ "python", "app.py" ]

0 commit comments

Comments
 (0)