-
Notifications
You must be signed in to change notification settings - Fork 7
151 lines (135 loc) · 5.32 KB
/
container-release.yml
File metadata and controls
151 lines (135 loc) · 5.32 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
name: Container Release
on:
push:
paths:
- containers/labs344/**
- .github/workflows/container-release.yml # Self-trigger
workflow_dispatch:
inputs:
publish:
description: "Publish to the container registry"
required: false
default: false
type: boolean
env:
REGISTRY: ghcr.io/${{ github.repository_owner }}
IMAGE_NAME: labs344
HOSTARCH: amd64
PLATFORM: linux-amd64
CONTAINER_VERSION: latest
CONTAINER_LATEST_VERSION: latest
CONTAINERS_ROOT: /home/runner/.local/share/containers
TMPDIR: /home/runner/.local/share/containers/tmp
permissions:
contents: read
packages: write
jobs:
buildah-build:
name: Build container images
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, ubuntu-24.04-arm]
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}
cancel-in-progress: true
steps:
- name: Install container tools
run: sudo apt-get install podman buildah jq
- name: Maximize build space
uses: easimon/maximize-build-space@v10
with:
root-reserve-mb: 2048 # Reserve disk space for repository
remove-dotnet: "true"
remove-android: "true"
remove-haskell: "true"
remove-codeql: "true"
remove-docker-images: "true"
build-mount-path: ${{ env.CONTAINERS_ROOT }} # The remaining space only for container build
- run: mkdir -p $TMPDIR
- name: Prepare environment variables
run: |
echo "HOSTARCH=$(podman info --format='{{.Host.Arch}}')" >> $GITHUB_ENV
echo "PLATFORM=$(podman info --format='{{.Version.OsArch}}' | sed 's/\//-/g')" >> $GITHUB_ENV
echo "CONTAINER_VERSION=$(date +'%Y%m%d')" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the GitHub Container registry
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build runtime container image
id: build-runtime
uses: redhat-actions/buildah-build@v2
with:
context: .
image: labs344
tags: ${{ env.CONTAINER_VERSION }}-runtime ${{ env.CONTAINER_VERSION }}-runtime-${{ env.HOSTARCH }}
layers: true
oci: true
build-args: |
CONTAINER_VERSION=${{ env.CONTAINER_VERSION }}
CONTAINER_IMAGE_REGISTRY_REMOTE=${{ env.REGISTRY }}
extra-args: |
--target labs344-runtime
containerfiles: |
./containers/labs344/Dockerfile
- name: Push to GitHub Container Repository
if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish
id: push-runtime-ghcr
uses: redhat-actions/push-to-registry@v2
with:
registry: ${{ env.REGISTRY }}
image: ${{ steps.build-runtime.outputs.image }}
tags: ${{ env.CONTAINER_VERSION }}-runtime-${{ env.HOSTARCH }}
digestfile: ${{ runner.temp }}/digest-labs344-runtime-${{ env.CONTAINER_VERSION }}-${{ env.PLATFORM }}
- name: Upload digests
if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish
uses: actions/upload-artifact@v4
with:
name: digest-labs344-${{ env.CONTAINER_VERSION }}-${{ env.PLATFORM }}
path: ${{ runner.temp }}/digest-*
if-no-files-found: error
retention-days: 1
compression-level: 0 # no compression
buildah-merge:
name: Merge container images
runs-on: ubuntu-24.04
needs: buildah-build
if: always() && github.event_name == 'workflow_dispatch' && github.event.inputs.publish
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digest-*
merge-multiple: true
- name: Log in to the GitHub Container registry
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare environment variables
run: |
if [ "${{ env.CONTAINER_VERSION }}" == "latest" ]; then
echo "CONTAINER_VERSION=$(date +'%Y%m%d')" >> $GITHUB_ENV
fi
echo "CONTAINER_LATEST_VERSION=$(date +'%Y%m%d')" >> $GITHUB_ENV
- name: Create and push manifest list for labs344-runtime
run: |
MANIFEST=labs344-runtime
FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
buildah manifest create $MANIFEST
for digest in ${{ runner.temp }}/digests/digest-labs344-runtime-*; do
echo "Adding $(cat $digest)"
buildah manifest add $MANIFEST $FULL_IMAGE_NAME@$(cat $digest)
done
buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:${{ env.CONTAINER_VERSION }}-runtime
if [ "${{ env.CONTAINER_VERSION }}" == "${{ env.CONTAINER_LATEST_VERSION }}" ]; then
buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:latest
buildah manifest push --all $MANIFEST docker://$FULL_IMAGE_NAME:latest-runtime
fi