Skip to content

Use pipenv, add Dockerfile, add CLI and make graph look nicer #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
303ccd1
Update to python 3
LeoVerto Aug 31, 2018
d2553ae
Add Pipfile
LeoVerto Aug 31, 2018
f715389
Remove makefile and update instructions to use pipenv
LeoVerto Aug 31, 2018
ab88c61
Add command line parameters
LeoVerto Aug 31, 2018
dc950fa
Add Dockerfile and instructions for running container
LeoVerto Aug 31, 2018
ad53549
Update docker command in README
LeoVerto Aug 31, 2018
98b38d1
Use fdp with splines and random network colours
LeoVerto Aug 31, 2018
895f06e
Update README to use fdp instead of dot
LeoVerto Aug 31, 2018
77e2cbe
Prefer pre-generated colours to random ones, close #2
LeoVerto Aug 31, 2018
32d580d
Make network colours temporally consistent
LeoVerto Aug 31, 2018
0829009
Update readme description
LeoVerto Aug 31, 2018
4b47843
Add rm to docker run in README
LeoVerto Aug 31, 2018
74997fb
Add example graph
LeoVerto Aug 31, 2018
58bde04
Code cleanup
LeoVerto Aug 31, 2018
26b979b
Added link to online Graphviz tool
MonkeyDo Aug 31, 2018
b6198ef
Updated online graphviz tool link
MonkeyDo Aug 31, 2018
567ad0b
Fix error when internal networks are present
LeoVerto Aug 31, 2018
23a74a8
Merge pull request #3 from MonkeyDo/patch-1
LeoVerto Aug 31, 2018
ea7ecc2
Merge remote-tracking branch 'upstream/master'
LeoVerto Aug 31, 2018
2a89518
Read network ICC value
LeoVerto Aug 31, 2018
f1b5a11
Use ENTRYPOINT instead of CMD to allow running the container with cus…
LeoVerto Aug 31, 2018
3586b9f
Fix KeyError on unused networks
LeoVerto Sep 10, 2018
4390b6d
Fix IndexError on unconfigured networks
LeoVerto Sep 14, 2018
ba2ca68
Fix error on containerless networks
LeoVerto Nov 8, 2018
fe05ab2
Improve build speed by making intermediaries reusable
LeoVerto Nov 8, 2018
25eb494
Add editorconfig
LeoVerto Nov 27, 2018
b84d30e
Style cleanup, use f-strings
LeoVerto Nov 27, 2018
bd07965
Update docker-py version, use MVC pattern, automatically select file …
LeoVerto Nov 27, 2018
59ea5ea
Update and clarify README
LeoVerto Nov 27, 2018
267bed9
Update dependencies, pin docker library to 3.7
LeoVerto Jun 4, 2020
7f20305
Add docker-compose file for testing different network configurations …
LeoVerto Jun 4, 2020
0544246
Fix KeyError when containers are attached to no or host network
LeoVerto Jun 4, 2020
23112d8
Show interface aliases above IPs
LeoVerto Jun 4, 2020
8c5cc44
Fix KeyError when networks with no gateway exist
LeoVerto Jul 1, 2020
8791d20
Update requirements for Python 3.9
LeoVerto Apr 27, 2021
3374d5b
Add GH Action for building and pushing docker image
LeoVerto Apr 27, 2021
4f2289b
Use correct image name in action
LeoVerto Apr 28, 2021
6f41241
Bump crazy-max/ghaction-docker-meta from v2 to v3
dependabot[bot] May 11, 2021
fe1d965
Update docker metadata action path
LeoVerto May 11, 2021
fca31d8
Merge pull request #13 from LeoVerto/dependabot/github_actions/crazy-…
LeoVerto May 11, 2021
148df41
Bump urllib3 from 1.26.4 to 1.26.5
dependabot[bot] Jun 2, 2021
d8bcd1a
Ignore minor and patch updates of Action dependencies
LeoVerto Jun 16, 2021
12c71f2
Merge pull request #19 from LeoVerto/dependabot/pip/urllib3-1.26.5
LeoVerto Jun 16, 2021
5dd0a04
Bump actions/checkout from 2 to 3
dependabot[bot] Mar 2, 2022
d2bab00
Bump actions/cache from 2 to 3
dependabot[bot] Mar 21, 2022
0632c86
Merge pull request #21 from LeoVerto/dependabot/github_actions/action…
LeoVerto Mar 22, 2022
ca07144
Merge pull request #22 from LeoVerto/dependabot/github_actions/action…
LeoVerto Mar 22, 2022
1e4f435
Bump docker/metadata-action from 3 to 4
dependabot[bot] May 5, 2022
0ba6f32
Merge pull request #23 from LeoVerto/dependabot/github_actions/docker…
LeoVerto May 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
test/
example.png
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true

[*.py]
charset = utf-8
indent_style = space
indent_size = 4
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-patch"]
- dependency-name: "*"
update-types: ["version-update:semver-minor"]
60 changes: 60 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Publish Docker image
on:
push:
branches:
- '**'
tags:
- 'v*'
jobs:
push_to_registry:
name: Build and push docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/docker-network-graph,ghcr.io/${{ github.repository_owner }}/docker-network-graph
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
if: github.event_name != 'pull_request'
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64
push: True
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/sandbox
/*.gv
/*.pdf
*.gv
*.pdf
*.png
*.svg
.idea
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3-alpine

WORKDIR /usr/src/app

COPY Pipfile Pipfile.lock ./

RUN pip install pipenv
RUN pipenv install --system --deploy

COPY docker-net-graph.py ./

ENTRYPOINT ["python", "docker-net-graph.py"]
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
docker = "~=3.7"
graphviz = "*"

[dev-packages]

[requires]
python_version = "3.9"
94 changes: 94 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 51 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,55 @@
Docker Network Graph
--------------------
# Docker Network Graph

Sample python script to draw graph of Docker networks and containers
Visualize the relationship between Docker networks and containers
as a neat graphviz graph.


Install/run
===========
## Example
![example graph](https://raw.githubusercontent.com/LeoVerto/docker-network-graph/master/example.png)

#> git clone --recursive https://github.com/eagafonov/docker-network-graph-poc.git
#> make install-requirements
#> make build-graph
## Usage
usage: docker-net-graph.py [-h] [-v] [-o OUT]

Visualize docker networks.

optional arguments:
-h, --help show this help message and exit
-v, --verbose Verbose output
-o OUT, --out OUT Write output to file

In most cases what you want to run are the following couple commands:

git clone https://github.com/LeoVerto/docker-network-graph.git
cd docker-network-graph
pipenv install
pipenv run python docker-net-graph.py -o output.svg

This will generate an .svg file containing the graph.

## Running inside docker
If you want to generate a graph for a remote system you can also easily
run this script inside a pre-built docker container:

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock leoverto/docker-network-graph

This will just generate and output the graph in the [DOT Language][dot].
You can then paste that code into [GraphvizOnline][gvonline]
to render it. The recommended rendering engine is `fdp`.

Alternatively, if you prefer to render locally, you can run
`fdp -Tpng -o out.png` on a system with graphviz installed,
paste the previous output there, press enter and finally CTRL+C to
generate the file.


For more advanced use cases you can append arguments to the `docker run`
command as if you were running it in a local shell.

[dot]: https://www.graphviz.org/doc/info/lang.html
[gvonline]: https://dreampuf.github.io/GraphvizOnline/

## Development
If you'd like to contribute to this project, there is a sample docker-compose file
using dummy containers in `test`.

You can deploy it using `docker-compose -f test/docker-compose.yml up -d`.
Loading