Skip to content

Commit 1aa70d3

Browse files
committed
chore(docker): add Docker setup with Dockerfile, entrypoint, and .dockerignore
- Created a .dockerignore file to exclude unnecessary files and directories from the Docker build context, such as build artifacts, environment folders, and various IDE configurations. - Added a README section detailing Docker usage, including instructions for running the setup and generate scripts. - Introduced a Dockerfile using a multi-stage build to create Python wheels first, then copy them into a slim image to reduce size and improve efficiency. - Implemented an entrypoint script to handle different commands (`setup` and `generate`) for running Python scripts within the Docker container.
1 parent a8377bf commit 1aa70d3

File tree

4 files changed

+245
-5
lines changed

4 files changed

+245
-5
lines changed

.dockerignore

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Project specific ignores
2+
/compose/
3+
/config.yaml
4+
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
cover/
57+
58+
# Translations
59+
*.mo
60+
*.pot
61+
62+
# Django stuff:
63+
*.log
64+
local_settings.py
65+
db.sqlite3
66+
db.sqlite3-journal
67+
68+
# Flask stuff:
69+
instance/
70+
.webassets-cache
71+
72+
# Scrapy stuff:
73+
.scrapy
74+
75+
# Sphinx documentation
76+
docs/_build/
77+
78+
# PyBuilder
79+
.pybuilder/
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
# For a library or package, you might want to ignore these files since the code is
91+
# intended to run in multiple environments; otherwise, check them in:
92+
# .python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# poetry
102+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103+
# This is especially recommended for binary packages to ensure reproducibility, and is more
104+
# commonly ignored for libraries.
105+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106+
#poetry.lock
107+
108+
# pdm
109+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110+
#pdm.lock
111+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112+
# in version control.
113+
# https://pdm.fming.dev/#use-with-ide
114+
.pdm.toml
115+
116+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117+
__pypackages__/
118+
119+
# Celery stuff
120+
celerybeat-schedule
121+
celerybeat.pid
122+
123+
# SageMath parsed files
124+
*.sage.py
125+
126+
# Environments
127+
.env
128+
.venv
129+
env/
130+
venv/
131+
ENV/
132+
env.bak/
133+
venv.bak/
134+
135+
# Spyder project settings
136+
.spyderproject
137+
.spyproject
138+
139+
# Rope project settings
140+
.ropeproject
141+
142+
# mkdocs documentation
143+
/site
144+
145+
# mypy
146+
.mypy_cache/
147+
.dmypy.json
148+
dmypy.json
149+
150+
# Pyre type checker
151+
.pyre/
152+
153+
# pytype static type analyzer
154+
.pytype/
155+
156+
# Cython debug symbols
157+
cython_debug/
158+
159+
# PyCharm
160+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162+
# and can be added to the global gitignore or merged into this file. For a more nuclear
163+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164+
.idea/
165+
.vscode/
166+
.history/

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ This script will generate a `compose.yaml` file (same as `docker-compose.yml`).
1111
- [Purpose of the Project 🎯](#purpose-of-the-project-)
1212
- [How to Set Up the Project 🛠️](#how-to-set-up-the-project-️)
1313
- [Prerequisites](#prerequisites)
14-
- [Step-by-Step Setup](#step-by-step-setup)
14+
- [Running with Docker](#running-with-docker)
15+
- [Run the Setup Script](#run-the-setup-script)
16+
- [Run the Generate Script](#run-the-generate-script)
17+
- [Running python files](#running-python-files)
18+
- [Step-by-Step Setup](#step-by-step-setup)
1519
- [Configuring Container Runtimes 🔄](#configuring-container-runtimes-)
1620
- [containerd Configuration](#containerd-configuration)
1721
- [nerdctl Configuration](#nerdctl-configuration)
@@ -42,7 +46,29 @@ By using a pull-through cache, you can:
4246
- Access to the internet to pull initial images
4347
- Basic knowledge of Docker, Kubernetes, and container registries
4448

45-
### Step-by-Step Setup
49+
50+
### Running with Docker
51+
52+
#### Run the Setup Script
53+
54+
To execute the `setup.py` script inside the Docker container:
55+
56+
```bash
57+
touch config.yaml
58+
docker run --rm -ti -v "./config.yaml:/app/config.yaml" obeoneorg/multi-registry-cache setup
59+
```
60+
61+
#### Run the Generate Script
62+
63+
To trigger the `generate.py` script:
64+
65+
```bash
66+
docker run --rm -ti -v "./config.yaml:/app/config.yaml" -v "./compose:/app/compose" obeoneorg/multi-registry-cache generate
67+
```
68+
69+
### Running python files
70+
71+
#### Step-by-Step Setup
4672

4773
1. **Clone the Repository**
4874

@@ -117,7 +143,7 @@ sudo systemctl restart containerd
117143

118144
#### nerdctl Configuration
119145

120-
For `nerdctl`, you'll need to create a directory per registry mirror, and push content un a file :
146+
For `nerdctl`, you'll need to create a directory per registry mirror and push content into a file:
121147

122148
```bash
123149
mkdir -p /etc/containerd/certs.d/docker.io/
@@ -155,7 +181,7 @@ sudo systemctl restart docker
155181

156182
#### k3s / RKE2
157183

158-
Edit file `/etc/rancher/(k3s|rke2)/registries.yaml` and add :
184+
Edit file `/etc/rancher/(k3s|rke2)/registries.yaml` and add:
159185

160186
```yaml
161187
mirrors:
@@ -181,4 +207,4 @@ Feel free to contribute to this project by submitting issues or pull requests. F
181207
182208
---
183209
184-
**Keywords**: Docker, container registry, pull through cache, Docker Hub mirror, containerd, dockerd, Kubernetes, k3s, RKE, RKE2, image caching, setup guide, local mirror, container image optimization.
210+
**Keywords**: Docker, container registry, pull-through cache, Docker Hub mirror, containerd, dockerd, Kubernetes, k3s, RKE, RKE2, image caching, setup guide, local mirror, container image optimization.

docker/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Start the build stage for creating wheels
4+
FROM python:3.12 AS wheel
5+
6+
# Set the working directory
7+
WORKDIR /app
8+
9+
# Copy the requirements file to the working directory
10+
COPY requirements.txt .
11+
12+
# Install wheel and create wheel files for the requirements
13+
RUN --mount=type=cache,target=/root/.cache/pip \
14+
pip install wheel && \
15+
pip wheel -r requirements.txt --wheel-dir /root/.cache/wheel
16+
17+
# Start the final image using a slimmer version of Python
18+
FROM python:3.12-slim
19+
20+
# Set the working directory
21+
WORKDIR /app
22+
23+
# Copy the requirements file to the working directory
24+
COPY requirements.txt .
25+
26+
# Install the dependencies from the wheel files created in the previous stage
27+
RUN --mount=type=bind,from=wheel,source=/root/.cache/wheel,dst=/root/.cache/wheel \
28+
pip install --no-index --find-links=/root/.cache/wheel -r requirements.txt
29+
30+
# Copy the entire application code to the working directory
31+
COPY . .
32+
33+
# Copy the entrypoint script and set the appropriate permissions
34+
COPY --chmod=777 docker/entrypoint.sh /
35+
36+
# Specify the entrypoint for the container
37+
ENTRYPOINT [ "/entrypoint.sh" ]

docker/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$1" == "setup" ]; then
4+
shift
5+
exec python setup.py "$@"
6+
elif [ "$1" == "generate" ]; then
7+
shift
8+
exec python generate.py "$@"
9+
else
10+
exec "$@"
11+
fi

0 commit comments

Comments
 (0)