Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added much needed integration testing using containers #138

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ $ pkexec ublue-update --system
```

```
usage: ublue-update [-h] [-f] [-c] [-u] [-w] [--system]
usage: ublue-update [-h] [-f] [--config CONFIG] [--system] [--check] [-u] [-w] [--dry-run]

options:
-h, --help show this help message and exit
-f, --force force manual update, skipping update checks
-c, --check run update checks and exit
-u, --updatecheck check for updates and exit
-w, --wait wait for transactions to complete and exit
--config CONFIG use the specified config file
--system only run system updates (requires root)
--check run update checks and exit
-u, --updatecheck check for updates and exit
-w, --wait wait for transactions to complete and exit
--dry-run dry run ublue-update
```

## Troubleshooting
Expand Down Expand Up @@ -183,10 +184,9 @@ exit(1)

You can build and test this package in a container by using the provided container file.

1. `make builder-image` will create a container image with all dependencies installed
2. `make builder-exec` will execute a shell inside the builder container to allow you easily build the rpm package with `make build-rpm`
3. `make` will trigger the build process and generate a `.whl` package that can be installed
4. `pip install --user -e .` will allow to install an editable version of this package so you quickly edit and test the program
1. `just venv-create` will create a python venv with `ublue-update` installed (installed with `-e` to make it editable)
2. `source venv/bin/activate` to activate the venv
3. `sudo $(which ublue-update)` to run the updater as root (`which ublue-update` makes sure the local `ublue-update` program is run)

# Special Thanks

Expand Down
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"
Loading