Skip to content

Commit e1c81c9

Browse files
authored
NO-JIRA: refactor(GitHub Actions): extract Podman setup to reusable action and add test workflow (#2775)
1 parent 87e8424 commit e1c81c9

File tree

3 files changed

+144
-85
lines changed

3 files changed

+144
-85
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
name: 'Install Podman'
3+
description: 'Installs Podman from Homebrew'
4+
inputs:
5+
platform:
6+
description: 'Target platform for Podman installation (linux/amd64, linux/s390x, linux/ppc64le, linux/arm64)'
7+
required: true
8+
runs:
9+
using: "composite"
10+
steps:
11+
# https://github.com/containers/buildah/issues/2521#issuecomment-884779112
12+
- name: Workaround https://github.com/containers/podman/issues/22152#issuecomment-2027705598
13+
shell: bash
14+
run: sudo apt-get -qq remove podman crun
15+
16+
- uses: actions/cache@v4
17+
# https://docs.github.com/en/actions/reference/variables-reference#default-environment-variables
18+
# https://docs.github.com/en/actions/how-tos/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables
19+
id: cached-linuxbrew
20+
with:
21+
path: /home/linuxbrew/.linuxbrew
22+
key: linuxbrew-${{ runner.os }}-${{ runner.arch }}
23+
24+
- name: Install podman (linux/amd64, or qemu-user emulation)
25+
if: contains(fromJSON('["linux/amd64", "linux/s390x", "linux/ppc64le"]'), inputs.platform) && steps.cached-linuxbrew.outputs.cache-hit != 'true'
26+
shell: bash
27+
run: |
28+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
29+
/home/linuxbrew/.linuxbrew/bin/brew install podman
30+
31+
# Warning: Your CPU architecture (arm64) is not supported. We only support
32+
# x86_64 CPU architectures. You will be unable to use binary packages (bottles).
33+
#
34+
# This is a Tier 2 configuration:
35+
# https://docs.brew.sh/Support-Tiers#tier-2
36+
# Do not report any issues to Homebrew/* repositories!
37+
# Read the above document instead before opening any issues or PRs.
38+
- name: Install podman (linux/arm64)
39+
if: inputs.platform == 'linux/arm64' && steps.cached-linuxbrew.outputs.cache-hit != 'true'
40+
# Error: podman: no bottle available!
41+
# If you're feeling brave, you can try to install from source with:
42+
shell: bash
43+
run: |
44+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
45+
/home/linuxbrew/.linuxbrew/bin/brew install --build-from-source podman
46+
47+
- name: Add linuxbrew to PATH
48+
shell: bash
49+
run: echo "/home/linuxbrew/.linuxbrew/bin/" >> $GITHUB_PATH
50+
51+
- name: Configure Podman
52+
shell: bash
53+
run: |
54+
set -Eeuxo pipefail
55+
56+
# podman running as service ignores the TMPDIR env var here, let's give it a bind-mount to /var/tmp
57+
mkdir -p $TMPDIR
58+
sudo mount --bind -o rw,noexec,nosuid,nodev,bind $TMPDIR /var/tmp
59+
60+
# podman from brew has its own /etc (was giving me Failed to obtain podman configuration: runroot must be set)
61+
# the (default) config location is also where cri-o gets its storage defaults (that can be overriden in crio.conf)
62+
sudo cp ci/cached-builds/containers.conf /etc/containers.conf
63+
sudo cp ci/cached-builds/containers.conf /home/linuxbrew/.linuxbrew/opt/podman/etc/containers.conf
64+
sudo cp ci/cached-builds/storage.conf /etc/containers/storage.conf
65+
sudo cp ci/cached-builds/storage.conf /home/linuxbrew/.linuxbrew/opt/podman/etc/containers/storage.conf
66+
sudo cp ci/cached-builds/registries.conf /etc/containers/registries.conf
67+
sudo cp ci/cached-builds/registries.conf /home/linuxbrew/.linuxbrew/opt/podman/etc/containers/registries.conf
68+
69+
# should reset storage when changing storage.conf
70+
mkdir -p $HOME/.local/share/containers/storage/tmp
71+
# remote (CONTAINER_HOST) podman does not do reset (and refuses --force option)
72+
sudo /home/linuxbrew/.linuxbrew/opt/podman/bin/podman system reset --force
73+
74+
# https://github.com/containers/podman/pull/25504
75+
# podman 5.5.0: The podman system reset command no longer removes the user's podman.sock API socket
76+
sudo rm -rf /var/run/podman
77+
78+
# https://github.com/containers/podman/blob/main/docs/tutorials/socket_activation.md
79+
# since `brew services start podman` is buggy, let's do our own brew-compatible service
80+
# Regarding directory paths, see https://unix.stackexchange.com/questions/224992/where-do-i-put-my-systemd-unit-file
81+
sudo mkdir -p /usr/local/lib/systemd/system/
82+
sudo cp ci/cached-builds/podman.service /usr/local/lib/systemd/system/podman.service
83+
sudo cp ci/cached-builds/podman.socket /usr/local/lib/systemd/system/podman.socket
84+
sudo systemctl daemon-reload
85+
sudo systemctl unmask --now podman.service podman.socket
86+
sudo systemctl start podman.socket
87+
88+
# needed (much) later for trivy
89+
echo "PODMAN_SOCK=/var/run/podman/podman.sock" >> $GITHUB_ENV
90+
91+
# quick check podman works
92+
podman ps
93+
94+
- name: Show error logs (on failure)
95+
if: ${{ failure() }}
96+
shell: bash
97+
run: |
98+
set -Eeuxo pipefail
99+
100+
journalctl -xe
101+
ls -AlF /var/run/podman/podman.sock || echo "Socket /var/run/podman/podman.sock not found"
102+
sudo ss -xlpn | grep 'podman.sock' || echo "No active listener found for podman.sock via ss"

.github/workflows/build-notebooks-TEMPLATE.yaml

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -157,92 +157,10 @@ jobs:
157157

158158
# region Podman setup
159159

160-
# https://github.com/containers/buildah/issues/2521#issuecomment-884779112
161-
- name: Workaround https://github.com/containers/podman/issues/22152#issuecomment-2027705598
162-
run: sudo apt-get -qq remove podman crun
163-
164-
- uses: actions/cache@v4
165-
# https://docs.github.com/en/actions/reference/variables-reference#default-environment-variables
166-
# https://docs.github.com/en/actions/how-tos/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables
167-
id: cached-linuxbrew
160+
- name: Install Podman
161+
uses: './.github/actions/install-podman-action'
168162
with:
169-
path: /home/linuxbrew/.linuxbrew
170-
key: linuxbrew-${{ runner.os }}-${{ runner.arch }}
171-
172-
- name: Install podman (linux/amd64, or qemu-user emulation)
173-
if: contains(fromJSON('["linux/amd64", "linux/s390x", "linux/ppc64le"]'), inputs.platform) && steps.cached-linuxbrew.outputs.cache-hit != 'true'
174-
run: |
175-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
176-
/home/linuxbrew/.linuxbrew/bin/brew install podman
177-
178-
# Warning: Your CPU architecture (arm64) is not supported. We only support
179-
# x86_64 CPU architectures. You will be unable to use binary packages (bottles).
180-
#
181-
# This is a Tier 2 configuration:
182-
# https://docs.brew.sh/Support-Tiers#tier-2
183-
# Do not report any issues to Homebrew/* repositories!
184-
# Read the above document instead before opening any issues or PRs.
185-
- name: Install podman (linux/arm64)
186-
if: inputs.platform == 'linux/arm64' && steps.cached-linuxbrew.outputs.cache-hit != 'true'
187-
# Error: podman: no bottle available!
188-
# If you're feeling brave, you can try to install from source with:
189-
run: |
190-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
191-
/home/linuxbrew/.linuxbrew/bin/brew install --build-from-source podman
192-
193-
- name: Add linuxbrew to PATH
194-
run: echo "/home/linuxbrew/.linuxbrew/bin/" >> $GITHUB_PATH
195-
196-
- name: Configure Podman
197-
run: |
198-
set -Eeuxo pipefail
199-
200-
# podman running as service ignores the TMPDIR env var here, let's give it a bind-mount to /var/tmp
201-
mkdir -p $TMPDIR
202-
sudo mount --bind -o rw,noexec,nosuid,nodev,bind $TMPDIR /var/tmp
203-
204-
# podman from brew has its own /etc (was giving me Failed to obtain podman configuration: runroot must be set)
205-
# the (default) config location is also where cri-o gets its storage defaults (that can be overriden in crio.conf)
206-
sudo cp ci/cached-builds/containers.conf /etc/containers.conf
207-
sudo cp ci/cached-builds/containers.conf /home/linuxbrew/.linuxbrew/opt/podman/etc/containers.conf
208-
sudo cp ci/cached-builds/storage.conf /etc/containers/storage.conf
209-
sudo cp ci/cached-builds/storage.conf /home/linuxbrew/.linuxbrew/opt/podman/etc/containers/storage.conf
210-
sudo cp ci/cached-builds/registries.conf /etc/containers/registries.conf
211-
sudo cp ci/cached-builds/registries.conf /home/linuxbrew/.linuxbrew/opt/podman/etc/containers/registries.conf
212-
213-
# should reset storage when changing storage.conf
214-
mkdir -p $HOME/.local/share/containers/storage/tmp
215-
# remote (CONTAINER_HOST) podman does not do reset (and refuses --force option)
216-
sudo /home/linuxbrew/.linuxbrew/opt/podman/bin/podman system reset --force
217-
218-
# https://github.com/containers/podman/pull/25504
219-
# podman 5.5.0: The podman system reset command no longer removes the user's podman.sock API socket
220-
sudo rm -rf /var/run/podman
221-
222-
# https://github.com/containers/podman/blob/main/docs/tutorials/socket_activation.md
223-
# since `brew services start podman` is buggy, let's do our own brew-compatible service
224-
# Regarding directory paths, see https://unix.stackexchange.com/questions/224992/where-do-i-put-my-systemd-unit-file
225-
sudo mkdir -p /usr/local/lib/systemd/system/
226-
sudo cp ci/cached-builds/podman.service /usr/local/lib/systemd/system/podman.service
227-
sudo cp ci/cached-builds/podman.socket /usr/local/lib/systemd/system/podman.socket
228-
sudo systemctl daemon-reload
229-
sudo systemctl unmask --now podman.service podman.socket
230-
sudo systemctl start podman.socket
231-
232-
# needed (much) later for trivy
233-
echo "PODMAN_SOCK=/var/run/podman/podman.sock" >> $GITHUB_ENV
234-
235-
# quick check podman works
236-
podman ps
237-
238-
- name: Show error logs (on failure)
239-
if: ${{ failure() }}
240-
run: |
241-
set -Eeuxo pipefail
242-
243-
journalctl -xe
244-
ls -AlF /var/run/podman/podman.sock || echo "Socket /var/run/podman/podman.sock not found"
245-
sudo ss -xlpn | grep 'podman.sock' || echo "No active listener found for podman.sock via ss"
163+
platform: ${{ inputs.platform }}
246164

247165
- name: Calculate image name and tag
248166
id: calculated_vars
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Test Install Podman
3+
4+
"on":
5+
push:
6+
paths:
7+
- 'ci/cached-builds/**'
8+
- '.github/actions/install-podman-action/**'
9+
- '.github/workflows/test-install-podman.yaml'
10+
pull_request:
11+
paths:
12+
- 'ci/cached-builds/**'
13+
- '.github/actions/install-podman-action/**'
14+
- '.github/workflows/test-install-podman.yaml'
15+
workflow_dispatch:
16+
17+
env:
18+
TMPDIR: /home/runner/.local/share/containers/tmpdir
19+
CONTAINER_HOST: unix:///var/run/podman/podman.sock
20+
21+
jobs:
22+
test-install:
23+
runs-on: ubuntu-24.04
24+
steps:
25+
- uses: actions/checkout@v5
26+
27+
- name: Install Podman
28+
uses: './.github/actions/install-podman-action'
29+
with:
30+
platform: linux/amd64
31+
32+
- name: Test Podman installation
33+
run: |
34+
set -Eeuxo pipefail
35+
36+
podman version
37+
38+
# https://github.com/containers/podman/blob/main/docs/tutorials/podman_tutorial.md#running-a-sample-container
39+
podman run --name basic_httpd -dt -p 8080:80/tcp docker.io/nginx

0 commit comments

Comments
 (0)