Skip to content

Commit 068b57f

Browse files
committed
🌱 init 🌱
0 parents  commit 068b57f

7 files changed

Lines changed: 361 additions & 0 deletions

File tree

27.7 KB
Loading

β€Ž.github/assets/video.gifβ€Ž

78.7 KB
Loading
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- deploy/hub
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
env:
14+
REGISTRY: docker.io
15+
IMAGE_NAME: slim-python3-uv
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: πŸ… Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: πŸ… Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: πŸ… Log in to Docker Hub
28+
uses: docker/login-action@v3
29+
with:
30+
username: ${{ secrets.DOCKERHUB_USERNAME }}
31+
password: ${{ secrets.DOCKERHUB_TOKEN }}
32+
33+
- name: πŸ… Extract image metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
38+
tags: |
39+
type=raw,value=latest
40+
labels: |
41+
org.opencontainers.image.title=slim-python3-uv
42+
org.opencontainers.image.description=Slim Python 3 image with uv, Bash tooling, and a non-root user; Docker Hub overview: https://hub.docker.com/r/mgldvd/slim-python3-uv; source: https://github.com/Mgldvd-Docker/slim-python3-uv
43+
org.opencontainers.image.url=https://github.com/Mgldvd-Docker/slim-python3-uv
44+
org.opencontainers.image.source=https://github.com/Mgldvd-Docker/slim-python3-uv
45+
org.opencontainers.image.documentation=https://hub.docker.com/r/mgldvd/slim-python3-uv
46+
47+
- name: πŸ… Build and push image
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
push: true
52+
platforms: linux/amd64,linux/arm64
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
annotations: ${{ steps.meta.outputs.annotations }}
56+
cache-from: type=gha
57+
cache-to: type=gha,mode=max
58+
59+
- name: πŸ… Update Docker Hub overview
60+
uses: peter-evans/dockerhub-description@v3
61+
with:
62+
username: ${{ secrets.DOCKERHUB_USERNAME }}
63+
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
repository: mgldvd/slim-python3-uv
65+
short-description: Slim Python 3 image with uv, Bash tooling, and sudo-enabled user
66+
readme-filepath: ./README.md
67+
68+
- name: πŸ… Log out from Docker Hub
69+
run: docker logout

β€ŽDockerfileβ€Ž

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM python:3.12-slim
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
bash \
5+
sudo \
6+
curl \
7+
ca-certificates \
8+
neovim \
9+
coreutils \
10+
git \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN useradd -m -u 1000 -s /bin/bash master && \
14+
echo 'master ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/master && \
15+
chmod 0440 /etc/sudoers.d/master
16+
17+
USER master
18+
WORKDIR /home/master
19+
20+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
21+
printf 'source "$HOME/.local/bin/env"\n' >> /home/master/.bashrc
22+
23+
ENV PATH="/home/master/.local/bin:${PATH}"
24+
25+
RUN cat << 'EOF' >> /home/master/.bashrc
26+
export PS1="\n\
27+
\[\033[38;2;255;249;143m\] \w\n\
28+
\[\033[38;2;49;94;146m\] ⏹\
29+
\[\033[38;2;255;95;71m\]⏹\
30+
\[\033[38;2;255;182;53m\]⏹\
31+
\[\033[0m\] \
32+
\[\033[38;2;120;150;255m\]python3.12-uv \
33+
\[\033[38;2;140;170;255m\]❱ \
34+
\[\033[0m\] "
35+
36+
alias ll="ls -Xalhv --color=auto --group-directories-first"
37+
alias vim="nvim"
38+
alias py="python"
39+
EOF
40+
41+
USER root
42+
RUN mkdir -p /app && chown -R master:master /app
43+
RUN chown -R master:master /home/master
44+
45+
USER master
46+
WORKDIR /app
47+
48+
CMD ["sleep", "infinity"]

β€ŽDockerfile.python3-11β€Ž

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
FROM python:3.11-slim
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
bash \
5+
sudo \
6+
curl \
7+
ca-certificates \
8+
neovim \
9+
coreutils \
10+
git \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN useradd -m -u 1000 -s /bin/bash master && \
14+
echo 'master ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/master && \
15+
chmod 0440 /etc/sudoers.d/master
16+
17+
USER master
18+
WORKDIR /home/master
19+
20+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
21+
printf 'source "$HOME/.local/bin/env"\n' >> /home/master/.bashrc
22+
23+
ENV PATH="/home/master/.local/bin:${PATH}"
24+
25+
RUN cat << 'EOF' >> /home/master/.bashrc
26+
export PS1="\n\
27+
\[\033[38;2;255;249;143m\] \w\n\
28+
\[\033[38;2;49;94;146m\] ⏹\
29+
\[\033[38;2;255;95;71m\]⏹\
30+
\[\033[38;2;255;182;53m\]⏹\
31+
\[\033[0m\] \
32+
\[\033[38;2;120;150;255m\]python3.12-uv \
33+
\[\033[38;2;140;170;255m\]❱ \
34+
\[\033[0m\] "
35+
36+
alias ll="ls -Xalhv --color=auto --group-directories-first"
37+
alias vim="nvim"
38+
alias py="python"
39+
EOF
40+
41+
USER root
42+
RUN mkdir -p /app && chown -R master:master /app
43+
RUN chown -R master:master /home/master
44+
45+
USER master
46+
WORKDIR /app
47+
48+
CMD ["sleep", "infinity"]

β€ŽREADME.mdβ€Ž

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<!-- markdownlint-disable first-line-heading -->
2+
<p align="center">
3+
<a href="https://hub.docker.com/r/mgldvd/slim-python3-uv" target="_blank"><img src="https://raw.githubusercontent.com/Mgldvd-Docker/slim-python3-uv/refs/heads/master/.github/assets/mgldvd-docker-banner.png" alt="Mgldvd-Docker" height="auto" /></a>
4+
</p>
5+
6+
# slim Python3 + uv Docker Image
7+
8+
<p float="left">
9+
<img src="https://cdn.svgporn.com/logos/docker.svg" height="40" title="docker">
10+
<img src="https://www.svgrepo.com/show/304556/three-dots.svg" height="30" title="dots">
11+
<img src="https://cdn.svglogos.dev/logos/python.svg" height="40" title="python">
12+
</p>
13+
14+
**Docker + Python 3 + uv**
15+
16+
This repo builds the `mgldvd/slim-python3-uv` Docker image on top of `python:3-slim`, adding Bash tooling and uv.
17+
18+
- **GitHub**: https://github.com/Mgldvd-Docker/slim-python3-uv
19+
- **Docker Hub**: https://hub.docker.com/r/mgldvd/slim-python3-uv
20+
21+
## 🧭 Overview
22+
23+
![demo](https://raw.githubusercontent.com/Mgldvd-Docker/slim-python3-uv/refs/heads/master/.github/assets/video.gif)
24+
25+
Single Dockerfile using slim and Python 3 with uv preinstalled, published by the GitHub Actions workflow on `deploy/hub`.
26+
27+
### πŸ“¦ Packages installed via `apk add`
28+
29+
- `bash`
30+
- `sudo`
31+
- `curl`
32+
- `ca-certificates`
33+
- `neovim`
34+
- `coreutils`
35+
- `git`
36+
37+
### πŸ”§ Added tooling
38+
39+
- uv installed via the official installer and linked at `/usr/local/bin/uv`
40+
- Non-root user `master` with passwordless sudo
41+
- Bash profile with a custom prompt, `ll` helper, and `vim` alias to `nvim`
42+
- Working directory `/app` owned by `master`
43+
44+
## 🏷️ Image Tags
45+
46+
| Tag | Description |
47+
| --- | --- |
48+
| `latest` | Most recent successful build on `deploy/hub` |
49+
50+
## ☁️ Docker Hub
51+
52+
### πŸš€ Quick start
53+
54+
```sh
55+
docker run --rm -it -v "$PWD:/app" mgldvd/slim-python3-uv bash
56+
```
57+
58+
### πŸ§ͺ Python requests example
59+
60+
Inside the container:
61+
62+
```sh
63+
uv init requests-demo
64+
65+
cd requests-demo
66+
67+
uv add requests
68+
```
69+
70+
```sh
71+
cat <<'PY' > main.py
72+
import requests
73+
74+
75+
def main() -> None:
76+
response = requests.get("https://httpbin.org/json", timeout=5)
77+
print(response.json()["slideshow"]["title"])
78+
79+
80+
if __name__ == "__main__":
81+
main()
82+
PY
83+
```
84+
85+
```sh
86+
uv run main.py
87+
```
88+
89+
<br>
90+
<br>
91+
92+
## πŸ—οΈ Building Locally
93+
94+
Clone the project and build the image using the provided Dockerfile:
95+
96+
```sh
97+
git clone https://github.com/Mgldvd-Docker/slim-python3-uv.git
98+
99+
cd slim-python3-uv
100+
```
101+
102+
```sh
103+
docker build -t mgldvd/slim-python3-uv:local .
104+
```
105+
106+
Run the container to verify the build:
107+
108+
```sh
109+
docker run --rm -it -v "$PWD:/app" mgldvd/slim-python3-uv:local bash
110+
```
111+
112+
### πŸ—οΈ Building Locally (python 3.11)
113+
114+
```sh
115+
# build
116+
docker build -t mgldvd/slim-python3.11-uv:local -f Dockerfile.python3-11 .
117+
# run
118+
docker run --rm -it -v "$PWD:/app" mgldvd/slim-python3.11-uv:local bash
119+
```
120+
121+
<br>
122+
<br>
123+
124+
### 🐳 Docker Compose
125+
126+
Use the bundled [compose.yml](https://raw.githubusercontent.com/Mgldvd-Docker/slim-python3-uv/refs/heads/master/compose.yml) to launch an interactive shell with your local `app/` directory mounted into the container:
127+
128+
```sh
129+
mkdir app
130+
```
131+
132+
```sh
133+
wget https://raw.githubusercontent.com/Mgldvd-Docker/slim-python3-uv/refs/heads/master/compose.yml
134+
```
135+
136+
or create file: `compose.yml`
137+
138+
```yml
139+
services:
140+
app:
141+
image: mgldvd/slim-python3-uv
142+
command: bash
143+
volumes:
144+
- ./app:/app
145+
stdin_open: true
146+
tty: true
147+
restart: "no"
148+
```
149+
150+
```sh
151+
docker compose run --rm app
152+
```
153+
154+
To keep the container running in the background instead, start it detached and exec into it when needed:
155+
156+
```sh
157+
docker compose up -d
158+
docker compose exec app bash
159+
```
160+
161+
<br>
162+
<br>
163+
164+
## πŸ“€ Publishing Workflow
165+
166+
The GitHub Actions workflow at `.github/workflows/docker-publish.yml` automates image publication. It performs the following steps:
167+
168+
1. Checks out the repository.
169+
2. Prepares Docker Buildx for multi-platform builds.
170+
3. Authenticates against Docker Hub using repository secrets.
171+
4. Generates OCI metadata, including links back to GitHub and Docker Hub.
172+
5. Builds the image and pushes the multi-arch `latest` tag.
173+
174+
### πŸ” Required Secrets
175+
176+
Add the following secrets in the GitHub repository settings before running the workflow:
177+
178+
- `DOCKERHUB_USERNAME`: Docker Hub account name (for example `mgldvd`).
179+
- `DOCKERHUB_TOKEN`: Docker Hub access token with permission to push the repository.
180+
181+
### ▢️ Triggering a Publish
182+
183+
Push commits to the `deploy/hub` branch or run the workflow manually from the GitHub Actions tab to build and publish a new image version.
184+
185+
## 🀝 Contributing
186+
187+
Issues and pull requests are welcome. Please open a discussion in the GitHub repository if you plan substantial changes so proposals can be coordinated with the publishing workflow.

β€Žcompose.ymlβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
app:
3+
image: mgldvd/slim-python3-uv
4+
command: bash
5+
volumes:
6+
- ./app:/app
7+
stdin_open: true
8+
tty: true
9+
restart: "no"

0 commit comments

Comments
Β (0)