-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (82 loc) · 2.81 KB
/
build_python.yml
File metadata and controls
89 lines (82 loc) · 2.81 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
name: Build Python Image
on:
push:
branches:
- main
paths:
- "python/**"
- ".github/workflows/build_python.yml"
pull_request:
paths:
- "python/**"
- ".github/workflows/build_python.yml"
workflow_dispatch:
inputs:
no-cache:
description: "Disable cache for build"
required: false
default: false
type: boolean
repository_dispatch:
types: [trigger-build]
jobs:
build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}-python-${{ matrix.python_version }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.ref_name != github.event.repository.default_branch }}
strategy:
matrix:
python_version: ["3.9", "3.10", "3.11", "3.12"]
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up QEMU
if: github.ref_name == github.event.repository.default_branch
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx (QEMU)
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
flavor: |
suffix=-${{ matrix.python_version }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=${{ matrix.python_version }},suffix=,enable={{is_default_branch}}
type=raw,value=latest,suffix=,enable=${{ github.ref_name == github.event.repository.default_branch && matrix.python_version == '3.12' }}
type=edge,branch=main
images: |
ghcr.io/${{ github.repository }}/python
- name: Build and push
uses: docker/build-push-action@v4
with:
context: python
pull: true
push: ${{ !(github.event_name == 'push' && github.ref_name != github.event.repository.default_branch) }}
platforms: ${{ (github.ref_type == 'tag' || github.ref_name == github.event.repository.default_branch) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
no-cache: ${{ inputs.no-cache || false }}
cache-from: type=gha
cache-to: type=gha,mode=max,ignore-error=true
build-args: |
PYTHON_VERSION=${{ matrix.python_version }}