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 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
28 changes: 28 additions & 0 deletions hack/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 \
--load=$LOAD
done

32 changes: 32 additions & 0 deletions hack/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' | \
while read image; do
update_dockerfile $image
done
}

function with_grep() {
}

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

33 changes: 32 additions & 1 deletion packages/system/capi-operator/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
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-images

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:
../../../hack/update-dockerfiles.sh with_helm

components := $(subst /,,$(subst images/,,$(dir $(wildcard images/*/Dockerfile))))
img_targets := $(addprefix image-,$(components))

update-images: $(img_targets)

.PHONY: $(img_targets)
$(img_targets):
@$(eval name := $(subst image-,,$@))
@$(eval tag := $(shell egrep -o "FROM .*$(name).*" images/$(name)/Dockerfile | awk -F: '{print $$NF}'))
BUILDX_METADATA_PROVENANCE=0 docker buildx build images/$(name)/ \
--provenance false \
--tag $(subst //,/,$(REGISTRY)/$(TYPE)/$(name):$(tag)) \
--cache-from type=registry,ref=$(subst //,/,$(REGISTRY)/$(TYPE)/$(name):latest) \
--cache-to type=inline \
--metadata-file images/$(name).json \
--push=$(PUSH) \
--load=$(LOAD) && \
img_name=$$(jq -r '."image.name" | split(":")[:-1] | join(":")' images/$(name).json) \
yq -i '.$(name).image.manager.repository = ("$${img_name}"|envsubst(nu,ne))' values.yaml && \
img_tag=$$(jq -r '."image.name" | split(":")[-1]' images/$(name).json) \
img_digest=$$(jq -r '."containerimage.digest"' images/$(name).json) \
yq -i '.$(name).image.manager.tag = ("$${img_tag}@$${img_digest}"|envsubst(nu,ne))' values.yaml

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"buildx.build.ref": "default/default/7nxaun3sgw6z95qhgc4c873qo",
"containerimage.config.digest": "sha256:0ff1e569cc97f686d6c0c9ed6e6396c72eca93df746e7ca469f97124cae1e73d",
"containerimage.digest": "sha256:79282412e0b891630235ecf919c45b0531f25a0926825385a51bb2a7dde880fb",
"image.name": "localhost:5000/aenix-io/cozystack/system/cluster-api-operator:v0.8.1"
}
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
5 changes: 5 additions & 0 deletions packages/system/capi-operator/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cluster-api-operator:
image:
manager:
repository: "localhost:5000/aenix-io/cozystack/system/cluster-api-operator"
tag: "v0.8.1@sha256:79282412e0b891630235ecf919c45b0531f25a0926825385a51bb2a7dde880fb"