Skip to content

Commit

Permalink
fix: CI, add brew support, migrate to justfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Nov 25, 2024
1 parent 82a29b1 commit 06b67d7
Show file tree
Hide file tree
Showing 24 changed files with 494 additions and 183 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: integration testing
on:
pull_request:
merge_group:
push:
branches:
- main
workflow_dispatch:

jobs:
push-ghcr:
name: Build and test image
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false
matrix:
major_version: [40, 41]
include:
- major_version: 40
is_latest_version: false
is_stable_version: true
- major_version: 41
is_latest_version: true
is_stable_version: false
steps:
# Checkout push-to-registry action GitHub repository
- name: Checkout Push to Registry action
uses: actions/checkout@v4

- name: Install Deps
run: |
sudo apt-get install just podman
- name: Build Image
id: build_image
env:
FEDORA_MAJOR_VERSION: ${{ matrix.major_version }}
run: |
just container-build
- name: Test Image
id: test_image
run: |
just container-test
7 changes: 2 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ jobs:
strategy:
fail-fast: false
matrix:
major_version: [39, 40, 41]
major_version: [40, 41]
include:
- major_version: 39
is_latest_version: false
is_stable_version: true
- major_version: 40
is_latest_version: true
is_stable_version: false
Expand Down Expand Up @@ -84,7 +81,7 @@ jobs:
uses: redhat-actions/buildah-build@v2
with:
containerfiles: |
./Containerfile
./Containerfile.builder
image: ${{ env.IMAGE_NAME }}
tags: |
${{ steps.generate-tags.outputs.alias_tags }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
tag: ${{ steps.release-please.outputs.tag_name }}
upload_url: ${{ steps.release-please.outputs.upload_url }}
steps:
- uses: google-github-actions/release-please-action@v4
- uses: googleapis/release-please-action@v4
id: release-please
with:
release-type: simple
package-name: release-please-action

build-release:
name: Build and push rpm package
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
permissions:
contents: write
packages: write
Expand Down
85 changes: 55 additions & 30 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-39}"
ARG TEST_IMAGE="${TEST_IMAGE:-ghcr.io/ublue-os/base-main:41}"
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-41}"

FROM registry.fedoraproject.org/fedora:${FEDORA_MAJOR_VERSION} AS builder

Expand All @@ -8,35 +9,59 @@ WORKDIR /app

ADD . /app

RUN dnf install \
--disablerepo='*' \
--enablerepo='fedora,updates' \
--setopt install_weak_deps=0 \
--nodocs \
--assumeyes \
'dnf-command(builddep)' \
rpkg \
rpm-build && \
mkdir -p "$UBLUE_ROOT" && \
rpkg spec --outdir "$UBLUE_ROOT" && \
dnf builddep -y output/ublue-update.spec && \
make build-rpm

# Dump a file list for each RPM for easier consumption
RUN \
for RPM in ${UBLUE_ROOT}/noarch/*.rpm; do \
NAME="$(rpm -q $RPM --queryformat='%{NAME}')"; \
mkdir -p "${UBLUE_ROOT}/ublue-os/files/${NAME}"; \
rpm2cpio "${RPM}" | cpio -idmv --directory "${UBLUE_ROOT}/ublue-os/files/${NAME}"; \
mkdir -p ${UBLUE_ROOT}/ublue-os/rpms/; \
cp "${RPM}" "${UBLUE_ROOT}/ublue-os/rpms/$(rpm -q "${RPM}" --queryformat='%{NAME}.%{ARCH}.rpm')"; \
done

FROM scratch
RUN dnf install -y just

RUN just container-rpm-build

FROM ${TEST_IMAGE}

ENV UBLUE_ROOT=/app/output

# Copy RPMs
COPY --from=builder ${UBLUE_ROOT}/ublue-os/rpms /rpms
# Copy dumped contents
COPY --from=builder ${UBLUE_ROOT}/ublue-os/files /files

COPY --from=builder ${UBLUE_ROOT}/ublue-os/rpms /tmp/rpms
RUN rpm-ostree install python3-pip
RUN pip3 install --prefix /usr topgrade && rpm-ostree install /tmp/rpms/ublue-update.noarch.rpm

# FROM: https://github.com/containers/image_build/blob/main/podman/Containerfile, sets up podman to work in the container
RUN useradd -G wheel podman && \
echo -e "podman:1:999\npodman:1001:64535" > /etc/subuid && \
echo -e "podman:1:999\npodman:1001:64535" > /etc/subgid && \
echo "podman:" | chpasswd

ADD ./containers.conf /etc/containers/containers.conf
ADD ./podman-containers.conf /home/podman/.config/containers/containers.conf

RUN mkdir -p /home/podman/.local/share/containers && \
chown podman:podman -R /home/podman && \
chmod 644 /etc/containers/containers.conf

# Copy & modify the defaults to provide reference if runtime changes needed.
# Changes here are required for running with fuse-overlay storage inside container.
RUN sed -e 's|^#mount_program|mount_program|g' \
-e '/additionalimage.*/a "/var/lib/shared",' \
-e 's|^mountopt[[:space:]]*=.*$|mountopt = "nodev,fsync=0"|g' \
/usr/share/containers/storage.conf \
> /etc/containers/storage.conf

# Setup internal Podman to pass subscriptions down from host to internal container
RUN printf '/run/secrets/etc-pki-entitlement:/run/secrets/etc-pki-entitlement\n/run/secrets/rhsm:/run/secrets/rhsm\n' > /etc/containers/mounts.conf

# Note VOLUME options must always happen after the chown call above
# RUN commands can not modify existing volumes
VOLUME /var/lib/containers
VOLUME /home/podman/.local/share/containers

RUN mkdir -p /var/lib/shared/overlay-images \
/var/lib/shared/overlay-layers \
/var/lib/shared/vfs-images \
/var/lib/shared/vfs-layers && \
touch /var/lib/shared/overlay-images/images.lock && \
touch /var/lib/shared/overlay-layers/layers.lock && \
touch /var/lib/shared/vfs-images/images.lock && \
touch /var/lib/shared/vfs-layers/layers.lock

ENV _CONTAINERS_USERNS_CONFIGURED="" \
BUILDAH_ISOLATION=chroot
# RUN useradd -m -G wheel user && echo "user:" | chpasswd

CMD [ "/sbin/init" ]
24 changes: 8 additions & 16 deletions Containerfile.builder
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
FROM registry.fedoraproject.org/fedora:latest AS builder
ARG FEDORA_MAJOR_VERSION="${FEDORA_MAJOR_VERSION:-41}"

FROM registry.fedoraproject.org/fedora:${FEDORA_MAJOR_VERSION} AS builder

ENV UBLUE_ROOT=/app/output

WORKDIR /app
ADD . /app

RUN dnf install --assumeyes python3-pip && pip install topgrade
RUN dnf install -y just git

RUN dnf install \
--disablerepo='*' \
--enablerepo='fedora,updates' \
--setopt install_weak_deps=0 \
--nodocs \
--assumeyes \
'dnf-command(builddep)' \
rpkg \
rpm-build && \
mkdir -p "$UBLUE_ROOT" && \
rpkg spec --outdir "$UBLUE_ROOT" && \
dnf builddep -y output/ublue-update.spec
RUN just container-rpm-build

FROM builder AS rpm
FROM scratch

RUN make build-rpm
ENV UBLUE_ROOT=/app/output
COPY --from=builder ${UBLUE_ROOT}/ublue-os/rpms /tmp/rpms
55 changes: 0 additions & 55 deletions Makefile

This file was deleted.

12 changes: 12 additions & 0 deletions containers.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[containers]
netns="host"
userns="host"
ipcns="host"
utsns="host"
cgroupns="host"
cgroups="disabled"
log_driver = "k8s-file"
[engine]
cgroup_manager = "cgroupfs"
events_logger="file"
runtime="crun"
83 changes: 83 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
set shell := ["bash", "-uc"]
export UBLUE_ROOT := env_var_or_default("UBLUE_ROOT", "/app/output")
export TARGET := "ublue-update"
export SOURCE_DIR := UBLUE_ROOT + "/" + TARGET
export RPMBUILD := UBLUE_ROOT + "/rpmbuild"

default:
just --list

venv-create:
/usr/bin/python -m venv venv
source venv/bin/activate && pip3 install .
echo 'Enter: `source venv/bin/activate` to enter the venv'

build: format
python3 -m build

test:
pytest -v

spec: output
rpkg spec --outdir "$PWD/output"

build-rpm:
rpkg local --outdir "$PWD/output"

builddep:
dnf builddep -y output/ublue-update.spec

container-install-deps:
#!/usr/bin/env bash
set -eou pipefail
dnf install \
--disablerepo='*' \
--enablerepo='fedora,updates' \
--setopt install_weak_deps=0 \
--nodocs \
--assumeyes \
'dnf-command(builddep)' \
rpkg \
rpm-build \
git
# Used internally by build containers
container-rpm-build: container-install-deps spec builddep build-rpm
#!/usr/bin/env bash
set -eou pipefail
# clean up files
for RPM in ${UBLUE_ROOT}/noarch/*.rpm; do
NAME="$(rpm -q $RPM --queryformat='%{NAME}')"
mkdir -p "${UBLUE_ROOT}/ublue-os/rpms/"
cp "${RPM}" "${UBLUE_ROOT}/ublue-os/rpms/$(rpm -q "${RPM}" --queryformat='%{NAME}.%{ARCH}.rpm')"
done

output:
mkdir -p output

format:
black src tests
flake8 src tests


dnf-install:
dnf install -y "output/noarch/*.rpm"

container-build:
podman build . -t test-container -f Containerfile

container-test:
#!/usr/bin/env bash
set -eou pipefail
podman run -d --replace --name ublue-update-test --security-opt label=disable --device /dev/fuse:rw --privileged --systemd true test-container
while [[ "$(podman exec ublue-update-test systemctl is-system-running)" != "running" && "$(podman exec ublue-update-test systemctl is-system-running)" != "degraded" ]]; do
echo "Waiting for systemd to finish booting..."
sleep 1
done
# podman exec -t ublue-update-test systemd-run --user --machine podman@ --pipe --quiet sudo /usr/bin/ublue-update --dry-run
podman exec -t ublue-update-test systemd-run --machine 0@ --pipe --quiet /usr/bin/ublue-update --dry-run
podman rm -f ublue-update-test
clean:
rm -rf "$UBLUE_ROOT"
5 changes: 5 additions & 0 deletions podman-containers.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[containers]
volumes = [
"/proc:/proc",
]
default_sysctls = []
2 changes: 1 addition & 1 deletion rpkg.macros
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function ublue_update_version {
if [ "$GITHUB_REF_NAME" = "" ]; then
echo "1.3.1+$(git rev-parse --short HEAD)"
echo "1.3.2+$(git rev-parse --short HEAD)"
else
echo "$GITHUB_REF_NAME"
fi
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ install_requires =

[flake8]
max-line-length = 90
ignore = E501,W503,W504
ignore = E501,W503,W504 E402
Loading

0 comments on commit 06b67d7

Please sign in to comment.