Skip to content

Commit d0316d8

Browse files
authored
QD-12515: Support testing with Podman in CI (#672)
1 parent 8f52906 commit d0316d8

File tree

5 files changed

+181
-25
lines changed

5 files changed

+181
-25
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Setup Container Engine
2+
description: Install Docker or Podman engine and enable an appropriate Docker CLI context.
3+
inputs:
4+
version:
5+
required: true
6+
default: docker@latest
7+
description: |
8+
Engine version of format [<type>@]<version>, where:
9+
- type: either "docker" or "podman" (default: docker)
10+
- version: either "latest" or "[v]major[.minor[.patch]]" version of the engine.
11+
12+
Default: docker@latest
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Parse version
17+
uses: mathiasvr/[email protected]
18+
id: parse-version
19+
env:
20+
INPUT_VERSION: ${{ inputs.version }}
21+
with:
22+
shell: python
23+
# Note: in VS Code, consider installing `harrydowning.yaml-embedded-languages` to enable code highlighting
24+
# in the embedded python code.
25+
run: | # python
26+
import os
27+
import sys
28+
29+
version_string = os.getenv("INPUT_VERSION") or sys.argv[1]
30+
parts = version_string.lower().split("@", 1)
31+
32+
if len(parts) == 1:
33+
engine = "docker"
34+
version = parts[0]
35+
else:
36+
engine = parts[0]
37+
version = parts[1]
38+
39+
if engine not in {"docker", "podman"}:
40+
print(f"Unrecognized engine type '{engine}'", file=sys.stderr)
41+
sys.exit(1)
42+
43+
print(f"ENGINE_TYPE={engine}")
44+
print(f"ENGINE_VERSION={version}")
45+
46+
- name: Parse version
47+
shell: bash
48+
run: echo "${{ steps.parse-version.outputs.stdout }}" >> "$GITHUB_ENV"
49+
50+
- name: Setup Docker
51+
if: env.ENGINE_TYPE == 'docker'
52+
uses: ./.github/actions/setup-docker
53+
with:
54+
version: ${{ env.ENGINE_VERSION }}
55+
56+
- name: Setup Podman
57+
if: env.ENGINE_TYPE == 'podman'
58+
uses: ./.github/actions/setup-podman
59+
with:
60+
version: ${{ env.ENGINE_VERSION }}

.github/actions/setup-docker/action.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name: Setup Docker
2-
description: |
3-
Install a version of Docker Engine.
4-
5-
This action uses docker/setup-docker-action internally, but accepts major and minor releases without a patch version.
2+
description: Install Docker engine.
63
inputs:
74
version:
85
required: true
96
default: latest
10-
description: Either "latest", or "[v]major[.minor[.patch]]" version for Docker Engine.
7+
description: Either "latest", or "[v]major[.minor[.patch]]" version of the engine.
118
runs:
129
using: composite
1310
steps:
@@ -19,15 +16,13 @@ runs:
1916
shell: bash
2017
run: pip install natsort htmllistparse
2118

22-
- name: Normalize supplied version
19+
- name: Normalize version
2320
uses: mathiasvr/[email protected]
2421
id: normalize-version
2522
env:
2623
QUERY: ${{ inputs.version }}
2724
with:
2825
shell: python
29-
# Note: in VS Code, consider installing `harrydowning.yaml-embedded-languages` to enable code highlighting
30-
# in the embedded python code.
3126
run: | # python
3227
import json
3328
import platform
@@ -98,5 +93,6 @@ runs:
9893
with:
9994
version: ${{ steps.normalize-version.outputs.stdout }}
10095

101-
- run: docker version
102-
shell: bash
96+
- name: Docker version
97+
shell: bash
98+
run: docker version --format '{{.Server.Version}}'
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Setup Podman
2+
description: Install Podman
3+
inputs:
4+
version:
5+
required: true
6+
default: latest
7+
description: Engine version
8+
runs:
9+
using: composite
10+
steps:
11+
- name: Set up Docker APT repository
12+
shell: bash
13+
run: | # shell
14+
set -euo pipefail
15+
16+
# See https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
17+
sudo apt-get update
18+
sudo apt-get install ca-certificates curl
19+
sudo install -m 0755 -d /etc/apt/keyrings
20+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
21+
sudo chmod a+r /etc/apt/keyrings/docker.asc
22+
23+
# Add the repository to Apt sources:
24+
echo \
25+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
26+
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
27+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
28+
sudo apt-get update
29+
30+
- name: Install Docker CLI
31+
shell: bash
32+
run: sudo apt-get install docker-ce-cli
33+
34+
- name: Install Podman Engine
35+
shell: bash
36+
run: | # shell
37+
set -euo pipefail
38+
39+
BASE_URL="https://github.com/mgoltzsche/podman-static/releases/latest/download"
40+
if [[ "${{ inputs.version }}" != "latest" ]]; then
41+
BASE_URL="https://github.com/mgoltzsche/podman-static/releases/download/v${{ inputs.version }}"
42+
fi
43+
44+
ARCHIVE_NAME="podman-linux-$(dpkg --print-architecture)"
45+
46+
cd /tmp
47+
curl -L "${BASE_URL}/${ARCHIVE_NAME}.tar.gz" \
48+
| tar -xz
49+
sudo rsync -av "${ARCHIVE_NAME}/etc/" /etc
50+
sudo rsync -av "${ARCHIVE_NAME}/usr/" /usr
51+
52+
sudo podman version
53+
54+
- shell: bash
55+
name: Start Podman Engine
56+
run: | # shell
57+
podman_version=$(sudo podman version --format="{{.Server.Version}}")
58+
export podman_socket="/var/run/podman-${podman_version}.sock"
59+
60+
export TIMEOUT=$(($(date +%s) + 30)) # 30 seconds in the future
61+
function await() {
62+
exit_code=0
63+
echo "Polling: $@" >&2
64+
while true; do
65+
if (( $(date +%s) >= $TIMEOUT )); then
66+
echo "Timeout reached!" >&2
67+
return 1
68+
fi
69+
70+
"$@" || exit_code=$?
71+
if [[ $exit_code == 0 ]]; then
72+
break
73+
fi
74+
75+
sleep 1
76+
done
77+
}
78+
79+
sudo podman system service --time=0 "unix://${podman_socket}" &
80+
81+
sudo groupadd -f docker
82+
sudo usermod -aG docker $USER
83+
newgrp docker
84+
85+
# Await socket creation
86+
await test -S "${podman_socket}"
87+
sudo chgrp docker "${podman_socket}"
88+
sudo chmod 660 "${podman_socket}"
89+
90+
docker context create --docker "host=unix://${podman_socket}" "podman-${podman_version}"
91+
docker context use "podman-${podman_version}"
92+
93+
# Await start of engine
94+
await docker ps
95+
96+
- name: Podman version
97+
shell: bash
98+
run: docker version --format '{{.Server.Version}}'

.github/workflows/ci.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,25 @@ on:
99
jobs:
1010
# lint: disabled as golangci-lint is not yet ready for Go workspaces
1111
test:
12-
name: "Tests (os: ${{ matrix.os }}, docker: ${{ matrix.docker-version }})"
12+
name: "Test (⚙️ ${{ matrix.os }}, 🐳 ${{ matrix.container-engine }})"
1313
uses: ./.github/workflows/test.yaml
1414
with:
1515
os: ${{ matrix.os }}
16-
docker-version: ${{ matrix.docker-version }}
16+
container-engine: ${{ matrix.container-engine }}
1717
secrets: inherit
1818
strategy:
1919
matrix:
2020
include:
2121
- os: macos-13 # macos-13 is the only macOS github runner supporting Docker.
22-
docker-version: latest
22+
container-engine: docker@latest
2323
- os: windows-latest
24-
docker-version: latest
24+
container-engine: docker@latest
2525
- os: ubuntu-latest
26-
docker-version: latest
26+
container-engine: docker@latest
2727
- os: ubuntu-latest
28-
docker-version: v25.0 # See also: https://endoflife.date/docker-engine
28+
container-engine: podman@latest
29+
- os: ubuntu-latest
30+
container-engine: [email protected] # See also: https://endoflife.date/docker-engine
2931

3032
code-quality:
3133
if: github.repository == 'jetbrains/qodana-cli'

.github/workflows/test.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name: "Tests"
2-
run-name: "Tests (os: ${{ inputs.os }}, docker: ${{ inputs.docker-version }})"
2+
run-name: "Test (⚙️ ${{ inputs.os }}, 🐳 ${{ inputs.container-engine }})"
33
on:
44
workflow_call:
55
inputs: &inputs
66
os:
77
type: string
88
default: ubuntu-latest
9-
description: OS for the runner
10-
docker-version:
9+
description: Runner OS
10+
container-engine:
1111
type: string
12-
default: latest
13-
description: Docker engine version
12+
default: docker@latest
13+
description: Container engine type and version. See .github/actions/setup-container-engine for more info.
1414
secrets:
1515
QODANA_LICENSE_ONLY_TOKEN:
1616
required: true
@@ -19,18 +19,18 @@ on:
1919

2020
jobs:
2121
test:
22-
name: Run tests
22+
name: Test
2323
runs-on: ${{ inputs.os }}
2424
timeout-minutes: 30
2525
steps:
2626
- uses: actions/checkout@v5
2727
with:
2828
fetch-depth: 0
2929

30-
- name: Setup Docker
31-
uses: ./.github/actions/setup-docker
30+
- name: Setup container engine
31+
uses: ./.github/actions/setup-container-engine
3232
with:
33-
version: ${{ inputs.docker-version }}
33+
version: ${{ inputs.container-engine }}
3434

3535
- name: Setup Go
3636
uses: actions/setup-go@v5

0 commit comments

Comments
 (0)