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

Airgapped install support #175

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion packages/system/capi-operator/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
NAME=capi-operator
NAMESPACE=cozy-cluster-api
TYPE=system

include ../../../scripts/common-envs.mk
include ../../../scripts/package-system.mk

update:
update: update-charts update-dockerfiles

update-charts:
rm -rf charts
helm repo add capi-operator https://kubernetes-sigs.github.io/cluster-api-operator
helm repo update capi-operator
helm pull capi-operator/cluster-api-operator --untar --untardir charts
rm -rf charts/cluster-api-operator/charts

update-dockerfiles:
../../../scripts/update-dockerfiles.sh with_helm
nbykov0 marked this conversation as resolved.
Show resolved Hide resolved

image:
../../../scripts/build-images.sh $(REGISTRY) $(NAME) $(TYPE) $(PUSH) $(LOAD)
nbykov0 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM registry.k8s.io/capi-operator/cluster-api-operator:v0.8.1
28 changes: 28 additions & 0 deletions scripts/build-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -o pipefail
set -e

REGISTRY=$1
NAME=$2
TYPE=$3
PUSH=$4
LOAD=$5

# an example for packages/system/capi-operator, native image and transformed one
# registry.k8s.io/capi-operator/cluster-api-operator:v0.8.1
# ghcr.io/aenix-io/cozystack/system/capi-operator/cluster-api-operator:v0.8.1

find images -mindepth 1 -maxdepth 1 -type d | \
while read dockerfile_path; do
image_name=$(echo $dockerfile_path | awk -F/ '{print $2}')
tag=$(egrep -o "FROM .*$image_name.*" $dockerfile_path/Dockerfile | awk -F: '{print $NF}')
docker buildx build $dockerfile_path \
--provenance=false \
--tag=$REGISTRY/$TYPE/$image_name:$tag \
--cache-from=type=registry,ref=$REGISTRY/$TYPE/$image_name:latest \
--cache-to=type=inline \
--push=$PUSH \
nbykov0 marked this conversation as resolved.
Show resolved Hide resolved
--load=$LOAD
done

32 changes: 32 additions & 0 deletions scripts/update-dockerfiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -o pipefail
set -e

function update_dockerfile() {
local image=$1
local image_name=$(echo $image | awk -F/ '{print $NF}' | awk -F: '{print $1}')

[[ -z $image_name ]] && { echo "image_name is empty for image: $image">&2; exit 1; }
mkdir -p images/$image_name
if [[ ! -f images/$image_name/Dockerfile ]];
then
echo "FROM $image" > images/$image_name/Dockerfile
else
sed -i "s|FROM .*$image_name.*|FROM $image|" images/$image_name/Dockerfile
fi
}


function with_helm() {
helm template . | awk '/^[ \t"-]*image["]*: [a-zA-Z0-9/:@"\.-]+$/{print $NF}' | sed 's/"//g' | \
Copy link
Member

Choose a reason for hiding this comment

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

This wont work, because we have to replace all the images with ours in the helm chart, the output of helm template . will always return our values. Try parsing upstream helm chart instead

while read image; do
update_dockerfile $image
done
}

function with_grep() {
}

[[ -z $1 ]] && with_helm || $1