-
Notifications
You must be signed in to change notification settings - Fork 8
95 lines (83 loc) · 3.37 KB
/
Copy pathbuild.yaml
File metadata and controls
95 lines (83 loc) · 3.37 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
name: Build
on:
workflow_call:
inputs:
registry:
type: string
required: true
description: The registry to push the image to.
image-owner:
type: string
required: true
description: The owner of the image.
image-name:
type: string
required: true
description: The name of the image.
image-tag:
type: string
required: true
description: The tag of the image.
secrets:
registry-username:
description: The username for the registry.
registry-password:
description: The password for the registry.
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Prepare
id: prepare
env:
# GitHub Actions doesn't seem to support the secrets
# context in if fields, hence this workaround.
REGISTRY_CREDENTIALS_AVAILABLE: "${{ case(secrets.registry-username != '', 'true', '') }}"
run: echo registry-credentials-available="$REGISTRY_CREDENTIALS_AVAILABLE" >>"$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
with:
platforms: amd64,arm64,arm,riscv64
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0
- name: Build OCI image archive
id: build
uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
with:
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64,linux/arm,linux/riscv64
tags: ${{ format('{0}/{1}/{2}:{3}', inputs.registry, inputs.image-owner, inputs.image-name, inputs.image-tag) }}
outputs: type=oci,dest=oci-image.tar
- name: Upload OCI image archive
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: ${{ format('{0}-{1}.tar', inputs.image-name, inputs.image-tag) }}
path: oci-image.tar
# The layers inside the tar archive are themselves already gzip
# compressed. No need to compress the metadata. Speeds things up a
# bit.
compression-level: 0
- name: Extract OCI image archive
run: mkdir image && tar xf oci-image.tar -C image/
- name: Log in to registry
if: steps.prepare.outputs.registry-credentials-available
uses: redhat-actions/podman-login@4934294ad0449894bcd1e9f191899d7292469603 # v1.7
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.registry-username }}
password: ${{ secrets.registry-password }}
- name: Upload OCI image to registry
env:
IMAGE: ${{ format('{0}/{1}/{2}:{3}', inputs.registry, inputs.image-owner, inputs.image-name, inputs.image-tag) }}
run: |
podmanArgs=(-v "$(realpath oci-image.tar):/image.tar:ro")
skopeoArgs=(--multi-arch all --preserve-digests)
if [ -e "$REGISTRY_AUTH_FILE" ]; then
podmanArgs+=(-v "$REGISTRY_AUTH_FILE:/auth.json:ro")
skopeoArgs+=(--authfile=/auth.json)
fi
set -x
podman run "${podmanArgs[@]}" \
docker://quay.io/skopeo/stable:v1.18.0 copy "${skopeoArgs[@]}" \
oci-archive:/image.tar "docker://$IMAGE"