-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (103 loc) · 3.79 KB
/
build-python-base.yaml
File metadata and controls
117 lines (103 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Build Python Base Image
on:
workflow_dispatch:
inputs:
python_version:
description: "Python version to build"
required: true
default: "3.11.2"
push:
paths:
- "Dockerfile.python-base"
branches:
- main
- development
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/python-base
jobs:
build:
strategy:
matrix:
platform: ["linux/amd64", "linux/arm64"]
runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Python version
id: python
run: |
# Use input if provided, otherwise extract from Dockerfile.python-base
if [ -n "${{ inputs.python_version }}" ]; then
echo "version=${{ inputs.python_version }}" >> $GITHUB_OUTPUT
else
VERSION=$(grep -oP 'ARG PYTHON_VERSION=\K[0-9.]+' Dockerfile.python-base)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
fi
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.python.outputs.version }}-trixie-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
- name: Build and push Python base image for ${{ matrix.platform }}
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.python-base
push: true
provenance: false
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PYTHON_VERSION=${{ steps.python.outputs.version }}
manifest:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Python version
id: python
run: |
if [ -n "${{ inputs.python_version }}" ]; then
echo "version=${{ inputs.python_version }}" >> $GITHUB_OUTPUT
else
VERSION=$(grep -oP 'ARG PYTHON_VERSION=\K[0-9.]+' Dockerfile.python-base)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
fi
- name: Create multi-arch manifest
run: |
LOWER_IMAGE_NAME=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')
PYTHON_VERSION="${{ steps.python.outputs.version }}"
docker manifest create $REGISTRY/${LOWER_IMAGE_NAME}:${PYTHON_VERSION}-trixie \
$REGISTRY/${LOWER_IMAGE_NAME}:${PYTHON_VERSION}-trixie-amd64 \
$REGISTRY/${LOWER_IMAGE_NAME}:${PYTHON_VERSION}-trixie-arm64
docker manifest push $REGISTRY/${LOWER_IMAGE_NAME}:${PYTHON_VERSION}-trixie
# Also tag as latest
docker manifest create $REGISTRY/${LOWER_IMAGE_NAME}:latest \
$REGISTRY/${LOWER_IMAGE_NAME}:${PYTHON_VERSION}-trixie-amd64 \
$REGISTRY/${LOWER_IMAGE_NAME}:${PYTHON_VERSION}-trixie-arm64
docker manifest push $REGISTRY/${LOWER_IMAGE_NAME}:latest