-
Notifications
You must be signed in to change notification settings - Fork 4
165 lines (158 loc) Β· 6.22 KB
/
build.yml
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
162
163
164
165
name: Build
on:
push:
branches:
- main
pull_request:
env:
DEFAULT_BASE_IMAGE: ubuntu:jammy
jobs:
version:
name: Check if version changed
runs-on: ubuntu-latest
outputs:
push: ${{ steps.push.outputs.push }}
version-changed: ${{ steps.version-metadata.outputs.changed }}
new-version: ${{ steps.version-metadata.outputs.newVersion }}
steps:
- uses: actions/checkout@v4
- uses: Quantco/ui-actions/version-metadata@v1
id: version-metadata
with:
file: Dockerfile
token: ${{ secrets.GITHUB_TOKEN }}
version-extraction-override: 'regex:ARG PIXI_VERSION=(.*)'
- name: Determine if pushing images
id: push
run: echo push=${{ steps.version-metadata.outputs.changed == 'true' && github.event_name == 'push' && github.ref_name == 'main' }} >> $GITHUB_OUTPUT
build:
needs: version
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
base-image:
- debian:bookworm-slim # 12
- debian:bookworm # 12
- debian:bullseye-slim # 11
- debian:bullseye # 11
- ubuntu:noble # 24.04
- ubuntu:mantic # 23.10
- ubuntu:jammy # 22.04
- ubuntu:focal # 20.04
- nvidia/cuda:12.3.1-base-ubuntu22.04
- nvidia/cuda:12.3.1-base-ubuntu20.04
- nvidia/cuda:12.2.2-base-ubuntu22.04
- nvidia/cuda:12.2.2-base-ubuntu20.04
- nvidia/cuda:12.1.1-base-ubuntu22.04
- nvidia/cuda:12.1.1-base-ubuntu20.04
- nvidia/cuda:11.8.0-base-ubuntu22.04
- nvidia/cuda:11.8.0-base-ubuntu20.04
- nvidia/cuda:11.7.1-base-ubuntu22.04
- nvidia/cuda:11.7.1-base-ubuntu20.04
- nvidia/cuda:11.6.2-base-ubuntu20.04
- nvidia/cuda:11.4.3-base-ubuntu20.04
- nvidia/cuda:11.3.1-base-ubuntu20.04
- nvidia/cuda:11.2.2-base-ubuntu20.04
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set image variables
id: image-variables
env:
IMAGE: ${{ matrix.base-image }}
run: |
import os
base_image = "${{ matrix.base-image }}"
if base_image.startswith("nvidia/cuda"):
code_names = {
"22.04": "jammy",
"20.04": "focal",
"23.10": "mantic",
"24.04": "noble",
}
ubuntu_version_number = base_image.split("-ubuntu")[-1]
base_tag = base_image.split(":")[-1]
cuda_version = base_tag.split("-")[0]
tag = f"{code_names[ubuntu_version_number]}-cuda-{cuda_version}"
platforms = "linux/amd64,linux/arm64"
else:
tag = base_image.split(":")[-1]
platforms = "linux/amd64,linux/arm64"
is_default = "true" if base_image == "${{ env.DEFAULT_BASE_IMAGE }}" else "false"
GITHUB_OUTPUT = os.environ["GITHUB_OUTPUT"]
with open(GITHUB_OUTPUT, "a") as f:
f.write(f"tag={tag}\n")
f.write(f"platforms={platforms}\n")
f.write(f"is-default={is_default}\n")
shell: python
- name: Get docker metadata
id: metadata
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: |-
ghcr.io/prefix-dev/pixi
flavor: latest=false
# latest
# base-image
# major.minor.patch
# major.minor.patch-base-image
tags: |
type=raw,value=latest,priority=1000,enable=${{ steps.image-variables.outputs.is-default }}
type=raw,value=${{ steps.image-variables.outputs.tag }},priority=900
type=semver,pattern={{version}},enable=${{ steps.image-variables.outputs.is-default }},value=${{ needs.version.outputs.new-version }},priority=800
type=semver,pattern={{version}}-${{ steps.image-variables.outputs.tag }},value=${{ needs.version.outputs.new-version }},priority=500
- name: Setup docker buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db
- name: Login to GHCR
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker images
id: build
uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445
with:
# provenance: false is needed to avoid unkown/unknown os/arch on ghcr
# see: https://github.com/docker/build-push-action/issues/820
provenance: false
platforms: ${{ steps.image-variables.outputs.platforms }}
push: ${{ needs.version.outputs.push == 'true' }}
build-args: |-
BASE_IMAGE=${{ matrix.base-image }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.image-variables.outputs.tag }}
path: ${{ steps.metadata.outputs.bake-file }}
- name: Run tests
# buildx does not support outputting the image so we need to pull it and run tests
if: needs.version.outputs.push == 'true'
run: |
docker images
docker run --rm ghcr.io/prefix-dev/pixi:${{ needs.version.outputs.new-version }}-${{ steps.image-variables.outputs.tag }} pixi --version
docker run --rm ghcr.io/prefix-dev/pixi:${{ needs.version.outputs.new-version }}-${{ steps.image-variables.outputs.tag }} sh -c "mkdir /app && cd /app && pixi init && pixi add python && pixi run python --version"
- name: Image digest
run: echo ${{ steps.build.outputs.digest }}
release:
needs: [version, build]
runs-on: ubuntu-22.04
permissions:
contents: write
if: needs.version.outputs.push == 'true'
steps:
- uses: actions/checkout@v4
- name: Push ${{ needs.version.outputs.new-version }} tag
run: |
git tag ${{ needs.version.outputs.new-version }}
git push origin ${{ needs.version.outputs.new-version }}
- name: Create release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
tag_name: ${{ needs.version.outputs.new-version }}