Skip to content

Commit e264d70

Browse files
committed
update(packaging): modernize Docker image
1 parent fdaccbe commit e264d70

File tree

5 files changed

+81
-26
lines changed

5 files changed

+81
-26
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
**/.pytest_cache
1111
**/.ruff_cache
1212
**/.settings
13+
**/.sonarlint
1314
**/.toolstarget
1415
**/.venv
1516
**/.vs
@@ -35,6 +36,11 @@
3536
# custom project
3637
docs/
3738
build/
39+
builder/
3840
dist/
41+
export/
42+
*.egg-info/
43+
htmlcov/
44+
junit/
3945
tests/
4046
**/*.xml

Dockerfile

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
1-
FROM python:3.11-slim
1+
FROM python:3.13-slim
22

3-
# Write .pyc files only once. See: https://stackoverflow.com/a/60797635/2556577
4-
ENV PYTHONDONTWRITEBYTECODE 1
5-
# Make sure that stdout and stderr are not buffered. See: https://stackoverflow.com/a/59812588/2556577
6-
ENV PYTHONUNBUFFERED 1
7-
# Remove assert statements and any code conditional on __debug__. See: https://docs.python.org/3/using/cmdline.html#cmdoption-O
8-
ENV PYTHONOPTIMIZE 2
3+
# Avoid .pyc bytecode and ensure output is unbuffered for CLI responsiveness
4+
ENV PYTHONDONTWRITEBYTECODE=1 \
5+
PYTHONUNBUFFERED=1 \
6+
PYTHONOPTIMIZE=2
97

10-
WORKDIR /user/app
8+
# Add user's local bin directory to PATH for pip installed packages
9+
ENV PATH="/home/geotribuser/.local/bin:$PATH"
1110

12-
COPY requirements.txt .
13-
COPY requirements/base.txt ./requirements/
11+
# Set locale to French UTF-8
12+
RUN apt update && \
13+
apt install -y --no-install-recommends locales && \
14+
echo "fr_FR.UTF-8 UTF-8" > /etc/locale.gen && \
15+
locale-gen \
16+
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
1417

15-
RUN python -m pip install --no-cache-dir -U pip && \
16-
python -m pip install --no-cache-dir -U setuptools wheel
18+
ENV LANG=fr_FR.UTF-8 \
19+
LANGUAGE=fr_FR:fr \
20+
LC_ALL=fr_FR.UTF-8
1721

18-
COPY . .
22+
# Create non-root group and user dedicated to geotribu usage
23+
RUN groupadd --system geotribu && \
24+
useradd -m -s /bin/bash -g geotribu geotribuser
1925

20-
RUN python -m pip install -U --no-cache-dir -r requirements.txt
26+
USER geotribuser
2127

22-
RUN python -m pip install -U -e .
28+
# Set working directory and proper permissions
29+
WORKDIR /home/geotribuser
2330

24-
CMD ["bash"]
31+
# Custom CLI settings
32+
ENV GEOTRIBU_CACHE_EXPIRATION_HOURS=240 \
33+
GEOTRIBU_COMMENTS_EXPIRATION_HOURS=240 \
34+
GEOTRIBU_RESULTATS_FORMAT=table \
35+
GEOTRIBU_RESULTATS_NOMBRE=20
36+
37+
COPY --chown=geotribuser:geotribu . .
38+
39+
RUN pip install --no-cache-dir .[all] \
40+
&& rm -rf ~/.cache/pip \
41+
&& geotribu sc --no-prompt "qgis" \
42+
&& geotribu si --no-prompt "qgis" \
43+
&& geotribu comments latest
44+
45+
ENTRYPOINT ["geotribu"]
46+
CMD []

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Outil en ligne de commande pour les tâches récurrentes du projet Geotribu.
2020

2121
## Installer
2222

23+
Avec [pipx](https://pipx.pypa.io/) (recommandé) :
24+
25+
```sh
26+
pipx install geotribu[all]
27+
```
28+
2329
Via _pip_ :
2430

2531
```sh
@@ -36,7 +42,7 @@ Via un exécutable pré-compilé : [télécharger pour son système d'exploitati
3642

3743
## Utiliser
3844

39-
Installation locale :
45+
Avec une installation avec un gestionnaire de paquets Python (pipx, pip, uv...) :
4046

4147
```sh
4248
geotribu --help
@@ -45,7 +51,7 @@ geotribu --help
4551
Ou avec l'image Docker :
4652

4753
```sh
48-
docker run --rm ghcr.io/geotribu/cli:latest geotribu --help
54+
docker run --rm -it ghcr.io/geotribu/cli:latest --help
4955
```
5056

5157
Pour plus d'informations, [consulter la documentation](https://cli.geotribu.fr/).

docs/development/packaging.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,46 @@ If you need that, edit the `.dockerignore` file.
5353
### Build
5454

5555
```sh
56-
docker build --pull --rm -f "Dockerfile" -t qdt:latest "."
56+
docker build --pull --rm -f "Dockerfile" -t geotribu-cli:latest "."
57+
```
58+
59+
Plus avancé avec build-kit et du cache :
60+
61+
```sh
62+
docker buildx create --name bldr-geotribu --driver docker-container --use
63+
```
64+
65+
```sh
66+
docker buildx build --pull --rm --file Dockerfile \
67+
--cache-from type=local,src=.cache/docker/geotribu/ \
68+
--cache-from type=registry,ref=ghcr.io/geotribu/ \
69+
--cache-to type=local,dest=.cache/docker/geotribu/,mode=max \
70+
--load \
71+
--platform linux/amd64 \
72+
--progress=plain \
73+
-t geotribu-cli:latest .
5774
```
5875

5976
### Run within the container
6077

6178
Enter into the container and run commands interactively::
6279

6380
```sh
64-
> docker run --rm -it qdt:latest
65-
root@55c5de0191ee:/user/app# qdt --version
81+
> docker run --rm -it geotribu-cli:latest
82+
root@55c5de0191ee:/user/app# geotribu --version
6683
0.23.1
6784
```
6885

69-
Run QDT directly from the container:
86+
Run the CLI directly from the container:
7087

7188
```sh
72-
> docker run --rm qdt:latest qdt --version
89+
> docker run --rm geotribu-cli:latest --version
7390
0.23.1
7491
```
92+
93+
Attention cependant, les commandes aboutissant sur un prompt ne fonctionneront pas dans un conteneur sans l'option interactive (`-it`) puisqu'il n'y pas de terminal tty a
94+
95+
```sh
96+
> docker run -it --rm geotribu-cli:latest sc -f article "title:qgis"
97+
98+
```

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
# Project requirements
2-
# --------------------
3-
-r requirements/base.txt

0 commit comments

Comments
 (0)