Skip to content

Commit 1b7f76a

Browse files
author
PythonCoderAS
committed
Add docker support
1 parent 3f2c277 commit 1b7f76a

2 files changed

Lines changed: 138 additions & 0 deletions

File tree

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
6+
env:
7+
REGISTRY: ghcr.io
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
platform:
19+
- linux/amd64
20+
- linux/arm64/v8
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v5
24+
25+
- name: Convert image name to lowercase
26+
run: |
27+
GITHUB_REPOSITORY="${{ github.repository }}"
28+
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> "${GITHUB_ENV}"
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3 # v3.0.0
32+
33+
- name: "Log into registry ${{ env.REGISTRY }}"
34+
uses: docker/login-action@v3 # v3.0.0
35+
with:
36+
registry: "${{ env.REGISTRY }}"
37+
username: "${{ github.actor }}"
38+
password: "${{ secrets.GITHUB_TOKEN }}"
39+
40+
- name: Extract Docker metadata
41+
id: meta
42+
uses: docker/metadata-action@v5 # v5.0.0
43+
with:
44+
images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
45+
46+
- name: Build and push Docker image
47+
id: build
48+
uses: docker/build-push-action@v6 # v5.0.0
49+
with:
50+
context: .
51+
labels: "${{ steps.meta.outputs.labels }}"
52+
cache-from: type=gha
53+
cache-to: type=gha,mode=max
54+
platforms: "${{ matrix.platform }}"
55+
provenance: true
56+
sbom: true
57+
outputs: "type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true"
58+
59+
- name: Export digest
60+
run: |
61+
mkdir -p "/tmp/digests/"
62+
digest="${{ steps.build.outputs.digest }}"
63+
touch "/tmp/digests/${digest#sha256:}"
64+
65+
- name: "Get arch name (compatible with docker manifest)"
66+
id: get_arch_name
67+
run: |
68+
SAFENAME="$(echo "${{ matrix.platform }}" | sed 's/\//_/g')"
69+
echo "ARCH_NAME=${SAFENAME}" >> "${GITHUB_OUTPUT}"
70+
71+
- name: Upload digest
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: "digests-plat-${{ steps.get_arch_name.outputs.ARCH_NAME }}"
75+
path: "/tmp/digests/*"
76+
if-no-files-found: error
77+
retention-days: 1
78+
79+
merge:
80+
runs-on: ubuntu-latest
81+
needs:
82+
- build
83+
permissions:
84+
packages: write
85+
steps:
86+
- name: Convert image name to lowercase
87+
run: |
88+
GITHUB_REPOSITORY="${{ github.repository }}"
89+
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> "${GITHUB_ENV}"
90+
91+
- name: Download digests
92+
uses: actions/download-artifact@v5
93+
with:
94+
path: "/tmp/digests/"
95+
pattern: "digests-plat-*"
96+
97+
- name: Move to one directory
98+
run: |
99+
mkdir -p /tmp/digests-all
100+
mv /tmp/digests/*/* /tmp/digests-all
101+
102+
- name: Set up Docker Buildx
103+
uses: docker/setup-buildx-action@v3
104+
105+
- name: Checkout repository
106+
uses: actions/checkout@v5
107+
108+
- name: Docker meta
109+
id: meta
110+
uses: docker/metadata-action@v5
111+
with:
112+
images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
113+
114+
- name: "Log into registry ${{ env.REGISTRY }}"
115+
uses: docker/login-action@v3
116+
with:
117+
registry: "${{ env.REGISTRY }}"
118+
username: "${{ github.actor }}"
119+
password: "${{ secrets.GITHUB_TOKEN }}"
120+
121+
- name: Create manifest list and push
122+
working-directory: "/tmp/digests-all"
123+
run: |
124+
# shellcheck disable=SC2046
125+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ghcr.io/astral-sh/uv:0.8.15-python3.13-alpine
2+
3+
WORKDIR /app
4+
COPY ./.python-version ./.python-version
5+
COPY ./pyproject.toml ./pyproject.toml
6+
COPY uv.lock uv.lock
7+
8+
RUN uv sync --locked --no-install-project
9+
10+
COPY ./src ./src
11+
COPY ./main.py ./main.py
12+
13+
ENTRYPOINT [ "uv", "run", "./main.py" ]

0 commit comments

Comments
 (0)