Skip to content

Commit 0512e1f

Browse files
authored
Merge pull request #1 from embtom/embtom/feature/build
Embtom/feature/build
2 parents 0fad7cf + f6f1c18 commit 0512e1f

31 files changed

Lines changed: 1234 additions & 84 deletions

.devcontainer/devcontainer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "vsc-python-apt",
3+
"dockerComposeFile": "../docker-compose.yml",
4+
"service": "devcontainer",
5+
"runServices": ["devcontainer"],
6+
"workspaceFolder": "/src",
7+
"containerEnv": {
8+
"NODE_EXTRA_CA_CERTS": "/etc/ssl/certs/ca-certificates.crt"
9+
},
10+
"features": {
11+
"ghcr.io/devcontainers/features/node:1": {
12+
"version": "20"
13+
}
14+
},
15+
"customizations": {
16+
"vscode": {
17+
"extensions": [
18+
"alefragnani.bookmarks",
19+
"cheshirekow.cmake-format",
20+
"davidanson.vscode-markdownlint",
21+
"EditorConfig.EditorConfig",
22+
"foxundermoon.shell-format",
23+
"huizhou.githd",
24+
"mhutchie.git-graph",
25+
"ms-azuretools.vscode-docker",
26+
"ms-python.autopep8",
27+
"ms-python.flake8",
28+
"ms-python.python",
29+
"ms-vscode.cmake-tools",
30+
"ms-vscode.cpptools",
31+
"redhat.vscode-yaml",
32+
"sonarsource.sonarlint-vscode",
33+
"streetsidesoftware.code-spell-checker",
34+
"tamasfe.even-better-toml",
35+
"timonwong.shellcheck",
36+
"yzhang.markdown-all-in-one"
37+
],
38+
"settings": {
39+
"terminal.integrated.profiles.linux": {
40+
"bash": null,
41+
"zsh": {
42+
"path": "/usr/bin/zsh"
43+
}
44+
},
45+
"editor.indentSize": 4,
46+
"editor.tabSize": 4,
47+
"editor.insertSpaces": false,
48+
"terminal.integrated.defaultProfile.linux": "zsh"
49+
}
50+
}
51+
}
52+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Get Debian Package Version"
2+
description: "Parse Debian version from a debian/changelog file"
3+
4+
inputs:
5+
path:
6+
description: "Path to the folder containing debian/changelog"
7+
required: false
8+
default: '.'
9+
10+
outputs:
11+
version:
12+
description: "Version extracted from debian/changelog"
13+
value: ${{ steps.parse.outputs.version }}
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Ensure dpkg-parsechangelog is available
19+
shell: bash
20+
run: |
21+
if ! command -v dpkg-parsechangelog >/dev/null 2>&1; then
22+
sudo apt-get update
23+
sudo apt-get install -y dpkg-dev
24+
fi
25+
26+
- name: Parse Debian version
27+
id: parse
28+
shell: bash
29+
working-directory: ${{ inputs.path }}
30+
run: |
31+
set -e
32+
if [ ! -f debian/changelog ]; then
33+
echo "error debian/changelog not found"
34+
exit 1
35+
fi
36+
VERSION=$(dpkg-parsechangelog --show-field Version)
37+
echo "Detected version: $VERSION"
38+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "Prepare builder"
2+
description: "Prepares build environment using Podman with GHCR caching"
3+
author: "embtom"
4+
5+
inputs:
6+
service:
7+
description: "The service in docker-compose.yml"
8+
required: true
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Install Podman and podman-compose
17+
uses: ./.github/actions/setup-podman
18+
19+
- name: Login to GHCR
20+
shell: bash
21+
run: |
22+
echo "${{ github.token }}" | podman login ghcr.io -u "${{ github.actor }}" --password-stdin
23+
24+
- name: Read image name from compose
25+
id: image-name
26+
shell: bash
27+
run: |
28+
IMAGE=$(yq -r '.services."${{ inputs.service }}".image' docker-compose.yml)
29+
BASE_IMAGE="${IMAGE%%:*}"
30+
HASH=$(sha256sum Dockerfile | cut -d " " -f1)
31+
echo "image=${IMAGE}" >> $GITHUB_OUTPUT
32+
33+
CACHE_IMAGE="ghcr.io/${{ github.repository_owner }}/cache-${BASE_IMAGE}:${HASH}"
34+
35+
echo "hash=${HASH}" >> $GITHUB_OUTPUT
36+
echo "cache-image=${CACHE_IMAGE}" >> $GITHUB_OUTPUT
37+
38+
- name: Try pulling cache from GHCR
39+
id: pull-cache
40+
shell: bash
41+
run: |
42+
echo "Trying to pull cache image: ${{ steps.image-name.outputs.cache-image }}"
43+
if podman pull "${{ steps.image-name.outputs.cache-image }}"; then
44+
echo "cache-hit=true" >> $GITHUB_OUTPUT
45+
else
46+
echo "cache-hit=false" >> $GITHUB_OUTPUT
47+
fi
48+
49+
- name: Load cached image tag into local tag
50+
if: steps.pull-cache.outputs.cache-hit == 'true'
51+
shell: bash
52+
run: |
53+
podman tag "${{ steps.image-name.outputs.cache-image }}" \
54+
"${{ steps.image-name.outputs.image }}"
55+
56+
echo "Loaded cached image: ${{ steps.image-name.outputs.image }}"
57+
58+
- name: Build image if cache miss
59+
if: steps.pull-cache.outputs.cache-hit == 'false'
60+
shell: bash
61+
run: |
62+
echo "Cache miss → building image…"
63+
podman-compose -f docker-compose.yml build "${{ inputs.service }}"
64+
65+
- name: Push updated image to GHCR as cache
66+
shell: bash
67+
run: |
68+
podman tag "${{ steps.image-name.outputs.image }}" \
69+
"${{ steps.image-name.outputs.cache-image }}"
70+
71+
podman push "${{ steps.image-name.outputs.cache-image }}"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "Run build"
2+
description: "Run the build based on prepared builder environment"
3+
author: "embtom"
4+
5+
inputs:
6+
service:
7+
description: "The service that was used for built"
8+
required: true
9+
build-target:
10+
description: "The build target to run"
11+
required: true
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
17+
- name: Run build
18+
shell: bash
19+
run: |
20+
SERVICE="${{ inputs.service }}"
21+
BUILD_TARGET="${{ inputs.build-target }}"
22+
if [ -z "$SERVICE" ]; then
23+
echo "ERROR: No service provided."
24+
exit 1
25+
fi
26+
podman-compose -f docker-compose.yml \
27+
run --rm "$SERVICE" "$BUILD_TARGET"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
name: "Setup Podman Environment"
3+
description: "Prepare Podman for rootless builds"
4+
5+
runs:
6+
using: "composite"
7+
steps:
8+
9+
- name: Remove Docker if installed
10+
shell: bash
11+
run: |
12+
if command -v docker >/dev/null 2>&1; then
13+
echo "Docker found removing"
14+
sudo systemctl stop docker docker.socket || true
15+
sudo apt-get purge -y \
16+
docker \
17+
docker.io \
18+
docker-ce \
19+
docker-ce-cli \
20+
containerd runc || true
21+
sudo apt-get autoremove -y
22+
sudo rm -rf /var/lib/docker /var/lib/containerd
23+
else
24+
echo "Docker not installed"
25+
fi
26+
27+
- name: Install dependencies
28+
shell: bash
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y \
32+
podman \
33+
python3-pip \
34+
fuse-overlayfs \
35+
uidmap \
36+
qemu-user-static \
37+
yq
38+
39+
- name: Enable lingering for current user
40+
shell: bash
41+
run: |
42+
sudo loginctl enable-linger $USER || true
43+
44+
- name: Create Podman config directories
45+
shell: bash
46+
run: |
47+
mkdir -p ~/.config/containers
48+
mkdir -p ~/.local/share/containers
49+
50+
- name: Configure rootless Podman storage
51+
shell: bash
52+
run: |
53+
cat <<'EOF' > ~/.config/containers/storage.conf
54+
[storage]
55+
driver = "overlay"
56+
runroot = "/tmp/run-$(id -u)"
57+
graphroot = "$HOME/.local/share/containers/storage"
58+
[storage.options]
59+
mount_program = "/usr/bin/fuse-overlayfs"
60+
EOF
61+
62+
- name: Migrate Podman storage (if needed)
63+
shell: bash
64+
run: |
65+
podman system migrate || true
66+
67+
- name: Install podman-compose from PyPI
68+
shell: bash
69+
run: |
70+
pip install --upgrade pip
71+
pip install podman-compose
72+
73+
- name: Verify Podman and podman-compose
74+
shell: bash
75+
run: |
76+
podman --version
77+
podman-compose version

.github/workflows/ci-build.yml

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,60 @@ on:
99

1010
jobs:
1111
build:
12-
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
include:
15+
- platform: linux-amd64
16+
arch: amd64
17+
runner: ubuntu-24.04
18+
service: builder
19+
- platform: linux-arm64
20+
arch: arm64
21+
runner: ubuntu-24.04-arm
22+
service: builder-arm64
23+
24+
runs-on: ${{ matrix.runner }}
25+
permissions:
26+
packages: write
1327

1428
steps:
1529
- name: Checkout repository
1630
uses: actions/checkout@v4
1731

18-
- name: hello
19-
shell: bash
20-
run: echo "hello"
21-
32+
- name: Get Debian version
33+
id: changelog
34+
uses: ./.github/actions/get-deb-version
35+
with:
36+
path: "."
37+
38+
- name: Show parsed version
39+
run: echo Version=${{ steps.changelog.outputs.version }}
40+
41+
- name: Prepare build environment
42+
uses: ./.github/actions/prepare-builder
43+
with:
44+
service: ${{ matrix.service }}
45+
46+
- name: Build wheel
47+
uses: ./.github/actions/run-build
48+
with:
49+
service: ${{ matrix.service }}
50+
build-target: all
51+
52+
- name: Build Debian package
53+
uses: ./.github/actions/run-build
54+
with:
55+
service: ${{ matrix.service }}
56+
build-target: build-deb
57+
58+
- name: Upload artifacts
59+
if: success()
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: build-${{ matrix.platform }}-${{ steps.changelog.outputs.version }}
63+
path: |
64+
build/*.deb
65+
build/*.changes
66+
build/*.buildinfo
67+
dist/*.whl
68+
retention-days: 10

0 commit comments

Comments
 (0)