-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (139 loc) · 5.23 KB
/
build-python.yaml
File metadata and controls
161 lines (139 loc) · 5.23 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Build and push images (python)
on:
push:
branches:
- main
paths:
- python/**
workflow_dispatch:
concurrency:
group: python
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: python
PLATFORMS: linux/amd64,linux/arm64
CACHE_FROM: |
type=gha,scope=buildkit-amd64
type=gha,scope=buildkit-arm64
jobs:
vars:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: |
set -eux
PYTHON_VERSION="$(grep -oP '(?<=PYTHON_VERSION=)[0-9.]+' "${{ env.IMAGE_NAME }}/Dockerfile")"
DEBIAN_VERSION="$(grep -oP '(?<=DEBIAN_VERSION=)[0-9.]+' "${{ env.IMAGE_NAME }}/Dockerfile")"
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
echo "DEBIAN_VERSION=$DEBIAN_VERSION" >> $GITHUB_ENV
outputs:
tag_base: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tag_end1: ${{ env.PYTHON_VERSION }}
tag_end2: ${{ env.PYTHON_VERSION }}-debian${{ env.DEBIAN_VERSION }}
context: "{{defaultContext}}:${{ env.IMAGE_NAME }}"
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
org.opencontainers.image.revision=${{ github.sha }}
build-images:
strategy:
matrix:
os: [ubuntu-24.04, ubuntu-24.04-arm]
fail-fast: false
runs-on: ${{ matrix.os }}
needs: vars
steps:
- id: vars
run: |
set -eux
echo "scope=buildkit-$(dpkg --print-architecture)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and check image (check)
uses: docker/build-push-action@v7
with:
target: check
context: ${{ needs.vars.outputs.context }}
cache-from: type=gha,"scope=${{ steps.vars.outputs.scope }}"
cache-to: type=gha,mode=max,"scope=${{ steps.vars.outputs.scope }}"
push-images:
runs-on: ubuntu-latest
needs: [vars, build-images]
permissions:
contents: read
packages: write
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to the registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image (latest)
uses: docker/build-push-action@v7
with:
target: latest
context: ${{ needs.vars.outputs.context }}
cache-from: ${{ env.CACHE_FROM }}
platforms: ${{ env.PLATFORMS }}
push: true
provenance: false
labels: ${{ needs.vars.outputs.labels }}
tags: |
${{ needs.vars.outputs.tag_base }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end1 }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end2 }}
- name: Build and push image (debug)
env:
TARGET: debug
uses: docker/build-push-action@v7
with:
target: ${{ env.TARGET }}
context: ${{ needs.vars.outputs.context }}
cache-from: ${{ env.CACHE_FROM }}
platforms: ${{ env.PLATFORMS }}
push: true
provenance: false
labels: ${{ needs.vars.outputs.labels }}
tags: |
${{ needs.vars.outputs.tag_base }}:${{ env.TARGET }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end1 }}-${{ env.TARGET }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end2 }}-${{ env.TARGET }}
- name: Build and push image (nonroot)
env:
TARGET: nonroot
uses: docker/build-push-action@v7
with:
target: ${{ env.TARGET }}
context: ${{ needs.vars.outputs.context }}
cache-from: ${{ env.CACHE_FROM }}
platforms: ${{ env.PLATFORMS }}
push: true
provenance: false
labels: ${{ needs.vars.outputs.labels }}
tags: |
${{ needs.vars.outputs.tag_base }}:${{ env.TARGET }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end1 }}-${{ env.TARGET }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end2 }}-${{ env.TARGET }}
- name: Build and push image (debug-nonroot)
env:
TARGET: debug-nonroot
uses: docker/build-push-action@v7
with:
target: ${{ env.TARGET }}
context: ${{ needs.vars.outputs.context }}
cache-from: ${{ env.CACHE_FROM }}
platforms: ${{ env.PLATFORMS }}
push: true
provenance: false
labels: ${{ needs.vars.outputs.labels }}
tags: |
${{ needs.vars.outputs.tag_base }}:${{ env.TARGET }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end1 }}-${{ env.TARGET }}
${{ needs.vars.outputs.tag_base }}:${{ needs.vars.outputs.tag_end2 }}-${{ env.TARGET }}