Skip to content

Commit

Permalink
make: check if docker is using new oci save format
Browse files Browse the repository at this point in the history
Starting from Docker 25.0 , the save command will dump the image
layers in OCI compatible format: moby/moby#44598

This breaks our tarball build that was using the 'layer.tar' file to
contruct the final tarball.

Let's make the target a bit smart so it can handle all variants by
parsing the docker manifest.json file to find the layer and use it.

The 'make tarball' now requires jq for simplicity.

Signed-off-by: Djalal Harouni <[email protected]>
  • Loading branch information
tixxdz committed Feb 28, 2024
1 parent 7fb3e73 commit 5af5487
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,21 @@ images: image image-operator

.PHONY: tarball tarball-release tarball-clean
# Share same build environment as docker image
# Then it uses docker save to dump the layer and use it to
# contruct the tarball.
# Requires 'jq' to be installed
tarball: tarball-clean image
$(CONTAINER_ENGINE) build --build-arg TETRAGON_VERSION=$(VERSION) --build-arg TARGET_ARCH=$(TARGET_ARCH) -f Dockerfile.tarball -t "cilium/tetragon-tarball:${DOCKER_IMAGE_TAG}" --platform=linux/${TARGET_ARCH} .
$(QUIET)mkdir -p $(BUILD_PKG_DIR)
$(CONTAINER_ENGINE) save cilium/tetragon-tarball:$(DOCKER_IMAGE_TAG) -o $(BUILD_PKG_DIR)/tetragon-$(VERSION)-$(TARGET_ARCH).tmp.tar
$(QUIET)mkdir -p $(BUILD_PKG_DIR)/docker/
$(QUIET)mkdir -p $(BUILD_PKG_DIR)/linux-tarball/
tar xC $(BUILD_PKG_DIR)/docker/ -f $(BUILD_PKG_DIR)/tetragon-$(VERSION)-$(TARGET_ARCH).tmp.tar
find $(BUILD_PKG_DIR)/docker/ -name 'layer.tar' -exec cp '{}' $(BUILD_PKG_DIR)/linux-tarball/tetragon-$(VERSION)-$(TARGET_ARCH).tar \;
sync $(BUILD_PKG_DIR)/docker/manifest.json
cat $(BUILD_PKG_DIR)/docker/manifest.json
cp "${BUILD_PKG_DIR}/docker/$$(jq -r '.[].Layers[0]' "${BUILD_PKG_DIR}/docker/manifest.json")" ${BUILD_PKG_DIR}/linux-tarball/tetragon-$(VERSION)-$(TARGET_ARCH).tar
@tar -tf ${BUILD_PKG_DIR}/linux-tarball/tetragon-$(VERSION)-$(TARGET_ARCH).tar | grep "/usr/local/bin/tetragon" - \
|| (echo "make: '$@' Error: could not find tetragon inside generated tarball"; exit 1)
$(QUIET)rm -fr $(BUILD_PKG_DIR)/tetragon-$(VERSION)-$(TARGET_ARCH).tmp.tar
gzip -6 $(BUILD_PKG_DIR)/linux-tarball/tetragon-$(VERSION)-$(TARGET_ARCH).tar
@echo "Tetragon tarball is ready: $(BUILD_PKG_DIR)/linux-tarball/tetragon-$(VERSION)-$(TARGET_ARCH).tar.gz"
Expand Down Expand Up @@ -411,4 +418,4 @@ kind-install-tetragon:
./contrib/localdev/install-tetragon.sh --image cilium/tetragon:latest --operator cilium/tetragon-operator:latest

.PHONY: kind-setup
kind-setup: images kind kind-install-tetragon
kind-setup: images kind kind-install-tetragon

0 comments on commit 5af5487

Please sign in to comment.