Skip to content
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
99 changes: 99 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Docker CI

on:
pull_request:
branches: [main]
push:
branches: [main]

permissions:
contents: read
packages: write

jobs:
detect:
runs-on: [self-hosted]
outputs:
dirs: ${{ steps.setdirs.outputs.dirs }}
core: ${{ steps.setdirs.outputs.core }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Detect changes
id: setdirs
shell: bash
run: |
changed=$(git diff --name-only origin/main...HEAD)

echo "Changed files:"
echo "$changed"

# Rebuild everything if:
# - core/ changed
# - Makefile changed
if echo "$changed" | grep -Eq '^(core/|Makefile$)'; then
rebuild_all=true
dirs='["ALL"]'
else
rebuild_all=false

# Extract only top-level directories that actually had files changed
# Ignore:
# - .github/
# - root files
dirs=$(echo "$changed" \
| grep '/' \
| cut -d/ -f1 \
| sort -u \
| grep -v '^\.github$' \
| jq -R -s -c 'split("\n")[:-1]')
fi

echo "core=$rebuild_all" >> $GITHUB_OUTPUT
echo "dirs=$dirs" >> $GITHUB_OUTPUT

build:
needs: detect
runs-on: [self-hosted]
strategy:
matrix:
dir: ${{ fromJson(needs.detect.outputs.dirs) }}

steps:
- uses: actions/checkout@v4

- uses: docker/setup-buildx-action@v3

- name: Normalize owner
id: vars
shell: bash
run: |
echo "owner_lc=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_OUTPUT

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

- name: Build
shell: bash
run: |
if [ "${{ matrix.dir }}" = "ALL" ]; then
echo "Core changed → building everything"
make all-multi \
REGISTRY=ghcr.io \
IMAGE_NAMESPACE=${{ steps.vars.outputs.owner_lc }} \
PUSH="${{ github.event_name == 'push' && '--push' || '--load' }}"
else
echo "Building ${{ matrix.dir }}"
make -d build_multi_${{ matrix.dir }} \
REGISTRY=ghcr.io \
IMAGE_NAMESPACE=${{ steps.vars.outputs.owner_lc }} \
PUSH="${{ github.event_name == 'push' && '--push' || '--load' }}"
fi
72 changes: 39 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
SHELL := /bin/bash

REGISTRY ?= docker.io
IMAGE_NAMESPACE ?= kathara
IMAGE_PREFIX=$(REGISTRY)/$(IMAGE_NAMESPACE)

PUSH ?= --push

DOCKER=docker
DOCKER_BUILD=$(DOCKER) build
BUILDX=$(DOCKER) buildx
Expand All @@ -12,76 +18,76 @@ versions_scion=0.12.0
retags_openvswitch=sdn
retags_bmv2=p4

all: build_apache build_base build_bind build_bird build_bird2 build_bird3 build_bmv2 build_core build_dnsmasq build_frr build_krill build_openbgpd build_openvswitch build_pox build_quagga build_rift-python build_routinator build_rpki-client build_scion
all-multi: build_multi_apache build_multi_base build_multi_bind build_multi_bird build_multi_bird2 build_multi_bird3 build_multi_bmv2 build_multi_core build_multi_dnsmasq build_multi_frr build_multi_krill build_multi_openbgpd build_multi_openvswitch build_multi_pox build_multi_quagga build_multi_rift-python build_multi_routinator build_multi_rpki-client build_multi_scion
all: build_apache build_base build_bind build_bird build_bird2 build_bird3 build_core build_dnsmasq build_frr build_krill build_openbgpd build_openvswitch build_pox build_quagga build_rift-python build_routinator build_rpki-client build_scion
all-multi: build_multi_apache build_multi_base build_multi_bind build_multi_bird build_multi_bird2 build_multi_bird3 build_multi_core build_multi_dnsmasq build_multi_frr build_multi_krill build_multi_openbgpd build_multi_openvswitch build_multi_pox build_multi_quagga build_multi_rift-python build_multi_routinator build_multi_rpki-client build_multi_scion

build_core:
echo "Building 'kathara/core' with tag 'latest'..."
$(DOCKER_BUILD) -t kathara/core core; \
build_multi_core: create-builder
echo "Building '$(IMAGE_PREFIX)/core' with tag 'latest'..."
$(BUILDX_BUILD) -t $(IMAGE_PREFIX)/core $(PUSH) core

build_%: build_core
build_multi_%:
latest_found=0
if [ -f $*/Dockerfile ]; then \
echo "Building 'kathara/$*' with tag 'latest'..."; \
$(DOCKER_BUILD) -t kathara/$* $*; \
echo "Building '$(IMAGE_PREFIX)/$*' with tag 'latest'..."; \
$(BUILDX_BUILD) -t $(IMAGE_PREFIX)/$* $(PUSH) $*; \
latest_found=1; \
fi; \
if [ -f $*/Dockerfile_version ]; then \
for version in $(versions_$*); do \
echo "Building 'kathara/$*' with version option '$$version'..."; \
$(DOCKER_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$version -t kathara/$*:$$version $*; \
for option in $(versions_$*); do \
echo "Building '$(IMAGE_PREFIX)/$*' with version option '$$version'..."; \
$(BUILDX_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$option -t $(IMAGE_PREFIX)/$*:$$option $(PUSH) $*; \
done; \
if [[ $$latest_found != 1 ]]; then \
echo "Tagging 'kathara/$*:$$version' as 'latest'..."; \
$(DOCKER_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$version -t kathara/$* $*; \
echo "Tagging '$(IMAGE_PREFIX)/$*:$$version' as 'latest'..."; \
$(BUILDX_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$option -t $(IMAGE_PREFIX)/$* $(PUSH) $*; \
fi; \
fi; \
for retag in $(retags_$*); do \
echo "Retagging 'kathara/$*:latest' to 'kathara/$$retag'..."; \
$(DOCKER) tag kathara/$*:latest kathara/$$retag; \
echo "Retagging '$(IMAGE_PREFIX)/$*:latest' to '$(IMAGE_PREFIX)/$$retag'..."; \
$(BUILDX) imagetools create -t $(IMAGE_PREFIX)/$$retag $(IMAGE_PREFIX)/$*:latest; \
done; \
for x in $$(find $* -name 'Dockerfile-*'); do \
dockerfile=$$(basename $$x); \
tag=$$(echo $$dockerfile | cut -d '-' -f2); \
echo "Building 'kathara/$*' from version file '$$tag'..."; \
$(DOCKER_BUILD) -f $$x -t kathara/$*:$$tag $*; \
echo "Building '$(IMAGE_PREFIX)/$*' from version file '$$tag'..."; \
$(BUILDX_BUILD) -f $$x -t $(IMAGE_PREFIX)/$*:$$tag $(PUSH) $*; \
done;

build_multi_core: create-builder
echo "Building 'kathara/core' with tag 'latest'..."
$(BUILDX_BUILD) -t kathara/core --push core
build_core:
echo "Building '$(IMAGE_PREFIX)/core' with tag 'latest'..."
$(DOCKER_BUILD) -t $(IMAGE_PREFIX)/core core; \

build_multi_%: build_multi_core
build_%:
latest_found=0
if [ -f $*/Dockerfile ]; then \
echo "Building 'kathara/$*' with tag 'latest'..."; \
$(BUILDX_BUILD) -t kathara/$* --push $*; \
echo "Building '$(IMAGE_PREFIX)/$*' with tag 'latest'..."; \
$(DOCKER_BUILD) -t $(IMAGE_PREFIX)/$* $*; \
latest_found=1; \
fi; \
if [ -f $*/Dockerfile_version ]; then \
for option in $(versions_$*); do \
echo "Building 'kathara/$*' with version option '$$version'..."; \
$(BUILDX_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$option -t kathara/$*:$$option --push $*; \
for version in $(versions_$*); do \
echo "Building '$(IMAGE_PREFIX)/$*' with version option '$$version'..."; \
$(DOCKER_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$version -t $(IMAGE_PREFIX)/$*:$$version $*; \
done; \
if [[ $$latest_found != 1 ]]; then \
echo "Tagging 'kathara/$*:$$version' as 'latest'..."; \
$(BUILDX_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$option -t kathara/$* --push $*; \
echo "Tagging '$(IMAGE_PREFIX)/$*:$$version' as 'latest'..."; \
$(DOCKER_BUILD) -f $*/Dockerfile_version --build-arg VERSION=$$version -t $(IMAGE_PREFIX)/$* $*; \
fi; \
fi; \
for retag in $(retags_$*); do \
echo "Retagging 'kathara/$*:latest' to 'kathara/$$retag'..."; \
$(BUILDX) imagetools create -t kathara/$$retag kathara/$*:latest; \
echo "Retagging 'kathara/$*:latest' to '$(IMAGE_PREFIX)/$$retag'..."; \
$(DOCKER) tag kathara/$*:latest $(IMAGE_PREFIX)/$$retag; \
done; \
for x in $$(find $* -name 'Dockerfile-*'); do \
dockerfile=$$(basename $$x); \
tag=$$(echo $$dockerfile | cut -d '-' -f2); \
echo "Building 'kathara/$*' from version file '$$tag'..."; \
$(BUILDX_BUILD) -f $$x -t kathara/$*:$$tag --push $*; \
echo "Building '$(IMAGE_PREFIX)/$*' from version file '$$tag'..."; \
$(DOCKER_BUILD) -f $$x -t $(IMAGE_PREFIX)/$*:$$tag $*; \
done;

create-builder:
echo "Creating buildx builder..."
$(BUILDX) create --name kat-builder --use
$(BUILDX) use kat-builder || $(BUILDX) create --name kat-builder --use
$(BUILDX) inspect --bootstrap

delete-builder:
Expand Down
8 changes: 4 additions & 4 deletions core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RUN apt update && \
apt-utils \
apt-transport-https \
arping \
arptables \
arptables \
bridge-utils \
curl \
diffutils \
Expand All @@ -56,7 +56,7 @@ RUN apt update && \
iptables \
iputils-ping \
iputils-tracepath \
isc-dhcp-client \
isc-dhcp-client \
less \
libbpf1 \
libelf1 \
Expand All @@ -72,7 +72,7 @@ RUN apt update && \
netbase \
netcat-openbsd \
openssh-client \
openssh-server \
openssh-server \
openssh-sftp-server \
openssl \
procps \
Expand All @@ -88,7 +88,7 @@ RUN apt update && \
tmux \
traceroute \
tree \
vim \
vim \
wget && \
apt-cache show iproute2 | dpkg --merge-avail && \
apt clean && \
Expand Down
Loading