Keeps Docker resources in shape based on rules and usage
Project description
Docker Shaper
This is a spin-off package for the docker-shaper tool, which can be used to monitor Docker stuff
like containers, images and volumes and automatically enforce certain cleanup-rules.
Installation
[<PYTHON> -m] pip[3] install [--user] [--upgrade] docker-shaper
Usage
The tool will start an interactive terminal UI (TUI).
poetry run docker-shaper
Attach to build nodes
The application is running in a tmux on the build nodes. The following command can be used to attach to the session:
ssh -t <build node> "su jenkins -Pc 'tmux attach-session -t docker-shaper'"
Development & Contribution
Setup
For active development you need to have poetry and pre-commit installed
python3 -m pip install --upgrade --user poetry pre-commit
git clone ssh://review.lan.tribe29.com:29418/docker_shaper
cd docker_shaper
pre-commit install
# if you need a specific version of Python inside your dev environment
poetry env use ~/.pyenv/versions/3.8.10/bin/python3
poetry install
Workflow
Create a new changelog snippet. If no new snippets is found on a merged change no new release will be built and published.
If the change is based on a Jira ticket, use the Jira ticket name as snippet name otherwise use a unique name.
poetry run \
changelog-generator \
create .snippets/CMK-21130.md
After committing the snippet a changelog can be generated locally. For CI usage
the --in-place flag is recommended to use as it will update the existing
changelog with the collected snippets. For local usage remember to reset the
changelog file before a second run, as the version would be updated recursively
due to the way the changelog generator is working. It extracts the latest
version from the changelog file and puts the found snippets on top.
Future changes to the changelog are ignored by
git update-index --assume-unchanged changelog.md
poetry run \
changelog-generator \
changelog changelog.md \
--snippets=.snippets \
--in-place \
--version-reference="https://review.lan.tribe29.com/gitweb?p=docker_shaper.git;a=tag;h=refs/tags/"
Update the version of the project in all required files by calling
poetry run \
changelog2version \
--changelog_file changelog.md \
--version_file cmk_dev/version.py \
--version_file_type py \
--additional_version_info="-rc42+$(git rev-parse HEAD)" \
--print \
| jq -r .info.version
-
modify and check commits via
pre-commit run --all-files -
after work is done locally:
- update dependencies before/with a new release
poetry lock
- build and check package locally
poetry build && \
twine check dist/* &&
python3 -m pip uninstall -y docker-shaper && \
python3 -m pip install --user dist/docker_shaper-$(grep -E "^version.?=" pyproject.toml | cut -d '"' -f 2)-py3-none-any.whl
- commit, push, review and merge the changes, see
docker_shaper/+/92759/
git add ...
git commit -m "bump version, update dependencies"
# merge
- test deployed packages from
test.pypi.org. The extra index URL is required to get those dependencies frompypi.orgwhich are not available fromtest.pypi.org
pip install --no-cache-dir \
-i https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
docker-shaper==<VERSION_WITH_RC>
- finally merge the changes and let Jenkins create the release tag and deployment
Troubleshooting
Publishing fails with HTTP Error 403
As a workaround which uses the token directly, you can do something like this:
poetry publish --username __token__ --password=<token here>
Todo
-
Fix: stuck auto-reload: was: postpone=True + monitoring log
-
Fix: crawl-images should fix parents not having them listed
-
[-] Fix: stuck crawl images (too many async requests, does not happen in production)
-
Fix:
'677aff0727' could not be removed: DockerError(404, 'No such image: 677aff0727:latest') -
Fix:
tried to remove container 4f5fb0848c unknown to us -
Fix: Crashes (see runlog)
-
Image update message only if needed
-
New TUI
- make ongoing progress visible
-
review log levels (too verbose)
-
installable via
pip install -
Quart interface (instead of
flask) -
auto-apply changes to source and configuration files
-
outsourced config file
-
bring in features of former
dgcd -
bring in features of former
dockermon -
untag certain tags
-
container cleanup
-
Fix
noneimage lookup -
Exceptions to messages
-
Clip
-
Increase/decrease logging via web / signal
-
Link: cleanup (images/containers) now
-
Add volumes list (with recent owners)
-
Containers: Store CPU / Memory usage over time
-
Containers: store history
-
Persist messages
-
Remove old message/container logs
-
Show different color for unmatched images
-
Warn about use of unpinned / upstream images
-
Handle 'build cache objects' (found on system prune)
-
Bring in volume monitoring: which volumes have been created and used by which containers?
-
Containers: show total CPU usage
-
Containers: list volumes
-
Images: list parents / children
-
Volumes: list usage
-
Instructions to readme
-
List unmatched / overmatched tags
-
Links to
delete/remove -
Links to jobs
-
Link: inspect
-
Graph: cpu / containers (idle/up)
-
Authenticate (at least if we can modify behavior, like stopping/removing images/containers)
Knowledge
(just misc links to articles that helped me out)
- How to delete docker images from Nexus Repository 3
- Showing Text Box On Hover (In Table)
- Beautiful Interactive Tables for your Flask Templates
- https://github.com/torfsen/python-systemd-tutorial
- https://www.digitalocean.com/community/tutorials/how-to-use-templates-in-a-flask-application
- https://stackoverflow.com/questions/49957034/live-updating-dynamic-variable-on-html-with-flask
- https://pgjones.gitlab.io/quart/how_to_guides/templating.html
Logging
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docker_shaper-2.1.0.tar.gz.
File metadata
- Download URL: docker_shaper-2.1.0.tar.gz
- Upload date:
- Size: 35.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.11.6 Linux/5.15.0-130-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3ce0be766bc90e495b471d662bbc29ccd023d0ea24ed766a9f8a698af884ed4
|
|
| MD5 |
4ccb6dcf67f37a83156673774fa1bf8c
|
|
| BLAKE2b-256 |
20c6d38852e82621b50409170916386f5d6eb9ca071fc9454e5faa58b36c8457
|
File details
Details for the file docker_shaper-2.1.0-py3-none-any.whl.
File metadata
- Download URL: docker_shaper-2.1.0-py3-none-any.whl
- Upload date:
- Size: 37.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.11.6 Linux/5.15.0-130-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb70a28662fe2b3f742373be733153aea5c66b33c84cff385e20507f26917258
|
|
| MD5 |
1c116f4c1b66228a742c5c55a31aecf1
|
|
| BLAKE2b-256 |
50c623cda8888753165abee43cafc07750ac23478419deb3e85525b0b00aec9e
|