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

new(ci): push docker images to ghcr. #70

Merged
merged 17 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Push docker images
on:
pull_request:
branches:
- main
paths:
- 'images/**'
push:
branches:
- main
paths:
- 'images/**'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
push-images:
strategy:
fail-fast: false
matrix:
architecture: [amd64, arm64]
runs-on: ${{ (matrix.arch == 'arm64' && 'actuated-arm64-8cpu-16gb') || 'ubuntu-22.04' }}
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Login to Github Packages
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Sets PUSH env var for main push
if: ${{ github.event_name == 'push' }}
run: |
echo "PUSH=true" >> $GITHUB_ENV

- name: Build images
working-directory: ./images
run: |
make build-all



45 changes: 32 additions & 13 deletions images/Makefile
FedeDP marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
DRY_RUN := false
REPOSITORY := falcosecurity/kernel-testing
PUSH := false
REPOSITORY := ghcr.io/falcosecurity/kernel-testing
ARCH ?= $(shell uname -m)
YAML_FILE := images.yaml

.PHONY: build-rootfs build-kernel docker-push generate-yaml build-all initrd-builder modernprobe-builder builder
.PHONY: build-rootfs build-kernel generate-yaml build-all initrd-builder modernprobe-builder builder

builder:
if [ "$(DRY_RUN)" = "true" ]; then \
echo "Dry run: Building builder image: docker build -t $(REPOSITORY)/builder:0.0.1-$(ARCH) builder"; \
else \
echo "Building modernprobe-builder image"; \
docker build -t $(REPOSITORY)/builder:0.0.1-$(ARCH) builder; \
if [ "$(PUSH)" = "true" ]; then \
echo "Pushing image: $(REPOSITORY)/builder:0.0.1-$(ARCH)"; \
docker push $(REPOSITORY)/builder:0.0.1-$(ARCH); \
fi; \
fi

modernprobe-builder:
Expand All @@ -19,6 +24,10 @@ modernprobe-builder:
else \
echo "Building modernprobe-builder image"; \
docker build -t $(REPOSITORY)/modernprobe-builder:0.0.1-$(ARCH) modernprobe-builder; \
if [ "$(PUSH)" = "true" ]; then \
echo "Pushing image: $(REPOSITORY)/modernprobe-builder:0.0.1-$(ARCH)"; \
docker push $(REPOSITORY)/modernprobe-builder:0.0.1-$(ARCH); \
fi; \
fi

initrd-builder:
Expand All @@ -39,6 +48,12 @@ build-rootfs:
else \
echo "Building rootfs image: $$image"; \
docker build -t $$image $$rootfs_dir; \
if [ "$(PUSH)" = "true" ]; then \
echo "Pushing image: $$image"; \
docker push $$image; \
fi; \
docker image rm -f $$image; \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since images are big, we don't want to fill up the runner node disk space; therefore after each build and eventual push, clean up images.

docker builder prune -f -a; \
FedeDP marked this conversation as resolved.
Show resolved Hide resolved
fi; \
done

Expand All @@ -52,16 +67,12 @@ build-kernel: initrd-builder
else \
echo "Building kernel image: $$image"; \
docker build -t $$image -f $$kernel_dir/Dockerfile.kernel $$kernel_dir; \
fi; \
done

docker-push:
@for image in $$(docker images --format "{{.Repository}}:{{.Tag}}" | grep "$(REPOSITORY)" | grep "$(ARCH)"); do \
if [ "$(DRY_RUN)" = "true" ]; then \
echo "Dry run: Pushing image: docker push $$image"; \
else \
echo "Pushing image: $$image"; \
docker push $$image; \
if [ "$(PUSH)" = "true" ]; then \
echo "Pushing image: $$image"; \
docker push $$image; \
fi; \
docker image rm -f $$image; \
docker builder prune -f -a; \
fi; \
done

Expand All @@ -79,6 +90,10 @@ docker-push:
else \
echo "Building rootfs image: $$rootfs_image"; \
docker build -t $$rootfs_image $$rootfs_dir; \
if [ "$(PUSH)" = "true" ]; then \
echo "Pushing image: $$rootfs_image"; \
docker push $$rootfs_image; \
fi; \
fi; \
fi; \
if [ -n "$$kernel_dir" ]; then \
Expand All @@ -87,6 +102,10 @@ docker-push:
else \
echo "Building kernel image: $$kernel_image"; \
docker build -t $$kernel_image -f $$kernel_dir/Dockerfile.kernel $$kernel_dir; \
if [ "$(PUSH)" = "true" ]; then \
echo "Pushing image: $$kernel_image"; \
docker push $$kernel_image; \
fi; \
fi; \
fi;

Expand All @@ -102,4 +121,4 @@ generate-yaml:
fi; \
done

build-all: build-rootfs build-kernel
build-all: build-kernel build-rootfs
9 changes: 5 additions & 4 deletions images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

Makefile present in this directory is specifically designed to generate the static Docker images required by Ignite to run tests on different Linux distributions. The workflow provided by this Makefile is designed to be straightforward, consisting of three main commands:

1. `build-all`: This target builds all the necessary Docker images for the different versions and distributions required for testing with Firecracker.
1. `build-all`: This target builds all the necessary Docker images for the different versions and distributions required for testing with Firecracker.
Optionally, you can set `PUSH=true` env variable to push the resulting Docker images to a Docker Hub registry for easier distribution and access.

2. `docker-push`: Optionally, you can use this target to push the resulting Docker images to a Docker Hub registry for easier distribution and access.

3. `generate-yaml`: This target allows you to generate a YAML file (`images.yaml`) containing the matrix of new image information. The generated YAML file can be conveniently copied to the variables file of Ansible to keep the test environment up to date.
2. `generate-yaml`: This target allows you to generate a YAML file (`images.yaml`) containing the matrix of new image information. The generated YAML file can be conveniently copied to the variables file of Ansible to keep the test environment up to date.

## Prerequisites

Expand Down Expand Up @@ -73,6 +72,8 @@ You can customize the Makefile to suit your specific requirements. The variables

- `DRY_RUN`: Set this variable to `true` for a dry run, where the build commands will be printed but not executed.

- `PUSH`: Set this variable to `true` when executing build to also push built image to remote registry.

- `REPOSITORY`: The Docker repository where the built images will be tagged and pushed.

- `ARCH`: The architecture for which the images will be built. By default, it will use the output of `uname -p`.
Expand Down
2 changes: 0 additions & 2 deletions images/aarch64/amazonlinux2022/5.15/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ RUN dnf groupinstall -y 'Development Tools' && \
xargs -I@ curl -Lo headers.rpm ${URL}@ && \
grep -E 'kernel-devel-'${VERSION}'.*.rpm' primary.xml | grep href | cut -d\" -f2 | \
xargs -I@ curl -Lo sources.rpm ${URL}@ && \
grep -E 'bpftool-'${VERSION}'.*.rpm' primary.xml | grep href | cut -d\" -f2 | \
xargs -I@ curl -Lo bpftool.rpm ${URL}@ && \
dnf install -y ./*.rpm && \
rm -f ./*.rpm && \
mkdir -p /lib/modules/5.15.73-45.135.amzn2022.aarch64/ && \
Expand Down
1 change: 0 additions & 1 deletion images/aarch64/fedora/6.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ RUN dnf groupinstall -y 'Development Tools' && \
openssh-server \
rsync \
systemd && \
curl -Lo bpftool.rpm ${URL}/b/bpftool-${HVERSION}.fc38.${ARCH}.rpm && \
curl -Lo sources.rpm ${URL}/k/kernel-devel-${VERSION}.fc38.${ARCH}.rpm && \
curl -Lo headers.rpm ${URL}/k/kernel-headers-${HVERSION}.fc38.${ARCH}.rpm && \
dnf install -y ./*.rpm && \
Expand Down
3 changes: 1 addition & 2 deletions images/aarch64/oraclelinux/5.15/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ RUN yum install -y \
curl -L -o kernel.rpm ${URL}/getPackage/kernel-uek-core-${VERSION}.el9uek.${ARCH}.rpm && \
curl -L -o devel.rpm ${URL}/getPackage/kernel-uek-devel-${VERSION}.el9uek.${ARCH}.rpm && \
curl -L -o modules.rpm ${URL}/getPackage/kernel-uek-modules-${VERSION}.el9uek.${ARCH}.rpm && \
curl -L -o bpftool.rpm ${URL}/getPackage/bpftool-${VERSION}.el9uek.${ARCH}.rpm && \
yum install -y ./kernel.rpm ./devel.rpm ./modules.rpm ./bpftool.rpm && \
yum install -y ./kernel.rpm ./devel.rpm ./modules.rpm && \
sed -i -e 's/^AcceptEnv LANG LC_\*$/#AcceptEnv LANG LC_*/' /etc/ssh/sshd_config && \
echo "root:root" | chpasswd && \
echo 'UseDNS no' >> /etc/ssh/sshd_config && \
Expand Down
1 change: 0 additions & 1 deletion images/aarch64/ubuntu/6.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ RUN apt-get update && apt-get install -y \
xargs -I@ curl -LO ${URL}@ && \
find . -name '*.deb' | xargs -n1 dpkg -i --force-depends && \
rm -f *.deb && \
find /usr/lib/linux-tools/ -name bpftool -exec ln -s {} /usr/bin/bpftool \; && \
sed -ie '/^ConditionVirtualization.*/d' /lib/systemd/system/systemd-timesyncd.service && \
echo "" > /etc/machine-id && echo "" > /var/lib/dbus/machine-id && \
sed -i -e 's/^AcceptEnv LANG LC_\*$/#AcceptEnv LANG LC_*/' /etc/ssh/sshd_config && \
Expand Down
2 changes: 0 additions & 2 deletions images/x86_64/amazonlinux2022/5.15/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ RUN dnf groupinstall -y 'Development Tools' && \
xargs -I@ curl -Lo headers.rpm ${URL}@ && \
grep -E 'kernel-devel-'${VERSION}'.*.rpm' primary.xml | grep href | cut -d\" -f2 | \
xargs -I@ curl -Lo sources.rpm ${URL}@ && \
grep -E 'bpftool-'${VERSION}'.*.rpm' primary.xml | grep href | cut -d\" -f2 | \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bpftool is not needed since scap-open with modern-bpf built in gets built in a specific step with a specific rootfs.

xargs -I@ curl -Lo bpftool.rpm ${URL}@ && \
dnf install -y ./*.rpm && \
rm -vf ./*.rpm && \
dnf clean all && \
Expand Down
6 changes: 2 additions & 4 deletions images/x86_64/amazonlinux2023/6.1/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ RUN dnf groupinstall -y 'Development Tools' && \
xargs -I@ curl -Lo headers.rpm ${URL}@ && \
grep -E 'kernel-devel-'${VERSION}'.*.rpm' primary.xml | grep href | cut -d\" -f2 | \
xargs -I@ curl -Lo sources.rpm ${URL}@ && \
grep -E 'bpftool-'${VERSION}'.*.rpm' primary.xml | grep href | cut -d\" -f2 | \
xargs -I@ curl -Lo bpftool.rpm ${URL}@ && \
dnf install -y ./headers.rpm ./bpftool.rpm ./sources.rpm && \
rm -vf ./headers.rpm ./bpftool.rpm ./sources.rpm && \
dnf install -y ./headers.rpm ./sources.rpm && \
rm -vf ./headers.rpm ./sources.rpm && \
dnf clean all && \
rm -rf /var/cache/yum && \
mkdir -p /lib/modules/6.1.34-58.102.amzn2023.x86_64/ && \
Expand Down
1 change: 0 additions & 1 deletion images/x86_64/archlinux/5.18/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ WORKDIR /home/ubuntu
RUN echo 'Server=https://archive.archlinux.org/repos/2022/08/04/$repo/os/$arch' > /etc/pacman.d/mirrorlist && \
pacman -Syyu --noconfirm && \
pacman -S --noconfirm \
bpf \
clang \
cmake \
gcc \
Expand Down
4 changes: 1 addition & 3 deletions images/x86_64/archlinux/6.0/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ RUN pacman -Syyu --noconfirm && \
wget && \
yes | pacman -Scc && \
curl -Lo headers.tar.zst ${URL}/l/linux-headers/linux-headers-${VERSION}-x86_64.pkg.tar.zst && \
curl -Lo bpf.tar.zst ${URL}/b/bpf/bpf-6.0-2-x86_64.pkg.tar.zst && \
pacman -U --noconfirm ./headers.tar.zst && \
pacman -U --noconfirm ./bpf.tar.zst && \
rm -v ./headers.tar.zst ./bpf.tar.zst && \
rm -v ./headers.tar.zst && \
ln -sf /usr/share/zoneinfo/US/Eastern /etc/localtime && \
echo 'LANG=en_US.UTF-8' > /etc/locale.gen && \
locale-gen && \
Expand Down
1 change: 0 additions & 1 deletion images/x86_64/centos/5.14/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ RUN dnf groupinstall -y 'Development Tools' && \
rsync \
systemd && \
curl -Lo headers.rpm ${APPSTR_URL}/kernel-devel-${VERSION}.el9.x86_64.rpm && \
curl -Lo bpftool.rpm ${BASEOS_URL}/bpftool-7.1.0-325.el9.x86_64.rpm && \
dnf install -y ./*.rpm && \
rm -v ./*.rpm && \
mkdir -p /lib/modules/${VERSION}.el9.x86_64/ && \
Expand Down
1 change: 0 additions & 1 deletion images/x86_64/fedora/5.17/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN dnf groupinstall -y 'Development Tools' && \
openssh-server \
rsync \
systemd && \
curl -Lo bpftool.rpm ${URL}/b/bpftool-${HVERSION}.fc36.x86_64.rpm && \
curl -Lo sources.rpm ${URL}/k/kernel-devel-${VERSION}.fc36.x86_64.rpm && \
curl -Lo headers.rpm ${URL}/k/kernel-headers-${HVERSION}.fc36.x86_64.rpm && \
dnf install -y ./*.rpm && \
Expand Down
1 change: 0 additions & 1 deletion images/x86_64/fedora/5.8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN dnf groupinstall -y 'Development Tools' && \
openssh-server \
rsync \
systemd && \
curl -Lo bpftool.rpm ${URL}/b/bpftool-${HVERSION}.fc33.x86_64.rpm && \
curl -Lo sources.rpm ${URL}/k/kernel-devel-${VERSION}.fc33.x86_64.rpm && \
curl -Lo headers.rpm ${URL}/k/kernel-headers-${HVERSION}.fc33.x86_64.rpm && \
dnf install -y ./*.rpm && \
Expand Down
1 change: 0 additions & 1 deletion images/x86_64/fedora/6.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN dnf groupinstall -y 'Development Tools' && \
openssh-server \
rsync \
systemd && \
curl -Lo bpftool.rpm ${URL}/b/bpftool-${HVERSION}.fc38.x86_64.rpm && \
curl -Lo sources.rpm ${URL}/k/kernel-devel-${VERSION}.fc38.x86_64.rpm && \
curl -Lo headers.rpm ${URL}/k/kernel-headers-${HVERSION}.fc38.x86_64.rpm && \
dnf install -y ./*.rpm && \
Expand Down
1 change: 0 additions & 1 deletion images/x86_64/oraclelinux/5.15/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ RUN yum install -y \
curl -Lo kernel.rpm ${URL}/getPackage/kernel-uek-core-${VERSION}.el9uek.x86_64.rpm && \
curl -Lo devel.rpm ${URL}/getPackage/kernel-uek-devel-${VERSION}.el9uek.x86_64.rpm && \
curl -Lo modules.rpm ${URL}/getPackage/kernel-uek-modules-${VERSION}.el9uek.x86_64.rpm && \
curl -Lo bpftool.rpm ${URL}/getPackage/bpftool-${VERSION}.el9uek.x86_64.rpm && \
yum install -y ./*.rpm && \
rm -f ./*.rpm && \
sed -i -e 's/^AcceptEnv LANG LC_\*$/#AcceptEnv LANG LC_*/' /etc/ssh/sshd_config && \
Expand Down
Loading