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

[cherry pick] [v3.29] [release tool] Allow building and publishing image in hashrelease #9534

Merged
merged 13 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ node/windows-packaging/nssm.exe
_output
builder.coverprofile
*.log
.release-*.*

/* Created by local kind cluster */
hack/test/kind/kind
Expand Down
45 changes: 31 additions & 14 deletions .semaphore/release/hashrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,67 @@ version: v1.0
name: Publish hashrelease
agent:
machine:
type: f1-standard-2
type: f1-standard-4
os_image: ubuntu2004
execution_time_limit:
hours: 4

global_job_config:
secrets:
- name: oss-release-secrets
# Github SSH secret for pulling private repositories.
- name: private-repo
# Secret for GitHub API access.
- name: marvin-github-token
# Secret for pushing to the docs box.
- name: docs-ssh
# Secret for pulling images from GCR.
- name: gcloud-registry-access
# Secret for the docker auth
- name: hashrelease-docker-auth
# Secret for Image Scanning Service
# Secret for image registries
- name: quay-hashrelease
- name: docker
- name: iss-image-scanning
# Secrets for Slack notifications
- name: releasebot-slack
prologue:
commands:
- chmod 0600 ~/.keys/*
- ssh-add ~/.keys/*
- export GOOGLE_APPLICATION_CREDENTIALS=${HOME}/keys/.registry-viewer-serviceaccount.json
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}
- docker login
# For some reason, /mnt is 100 GB and has a qemu-nbd image file.
# Let's delete it and use it for our own purposes (building calico
# without running out of space)
- sudo killall qemu-nbd || true
- sudo rm -f /mnt/docker.qcow2
- sudo chown $(id -u):$(id -g) /mnt/
- mkdir calico
- sudo mount --bind /mnt calico
# Checkout the code and unshallow it.
# (this is going to throw an error because it can't remove
# the `calico` directory, which is a mount, but it will
# continue anyway)
- checkout
# Unshallow the git repository to get latest tags
- retry git fetch --quiet --unshallow
# Semaphore mounts a copy-on-write FS as /var/lib/docker in order to provide a pre-loaded cache of
# some images. However, the cache is not useful to us and the copy-on-write FS is a big problem given
# how much we churn docker containers during the build. Disable it.
- sudo systemctl stop docker
- sudo umount /var/lib/docker && sudo killall qemu-nbd || true
- sudo systemctl start docker
# Log in to container registries needed for release.
- echo $DOCKER_TOKEN | docker login --username "$DOCKER_USER" --password-stdin
- echo $QUAY_TOKEN | docker login --username "$QUAY_USER" --password-stdin quay.io
# Credentials for accessing gcloud, needed to push images to gcr
- export GOOGLE_APPLICATION_CREDENTIALS=$HOME/secrets/gcr-credentials.json
- gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}
- gcloud auth configure-docker --quiet

blocks:
- name: Publish hashrelease
task:
jobs:
- name: Build and publish hashrelease
commands:
- if [[ ${SEMAPHORE_WORKFLOW_TRIGGERED_BY_SCHEDULE} == "true" ]]; then export BUILD_CONTAINER_IMAGES=true; export SKIP_PUBLISH_IMAGES=false; fi
- make hashrelease
prologue:
commands:
- export GITHUB_TOKEN=${MARVIN_GITHUB_TOKEN}
- cd release
- make build
env_vars:
- name: OPERATOR_BRANCH
value: release-v1.36
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ check-language:

generate:
$(MAKE) gen-semaphore-yaml
$(MAKE) get-operator-crds
$(MAKE) -C api gen-files
$(MAKE) -C libcalico-go gen-files
$(MAKE) -C felix gen-files
Expand All @@ -65,8 +64,13 @@ gen-manifests: bin/helm

# Get operator CRDs from the operator repo, OPERATOR_BRANCH must be set
get-operator-crds: var-require-all-OPERATOR_BRANCH
@echo ================================================================
@echo === Pulling new operator CRDs from branch $(OPERATOR_BRANCH) ===
@echo ================================================================
cd ./charts/tigera-operator/crds/ && \
for file in operator.tigera.io_*.yaml; do echo "downloading $$file from operator repo" && curl -fsSL https://raw.githubusercontent.com/tigera/operator/$(OPERATOR_BRANCH)/pkg/crds/operator/$${file%_crd.yaml}.yaml -o $${file}; done
cd ./manifests/ocp/ && \
for file in operator.tigera.io_*.yaml; do echo "downloading $$file from operator repo" && curl -fsSL https://raw.githubusercontent.com/tigera/operator/$(OPERATOR_BRANCH)/pkg/crds/operator/$${file%_crd.yaml}.yaml -o $${file}; done
Copy link
Member

Choose a reason for hiding this comment

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

we don't need this anymore since the operator will bootstrap the CRDs for OpenShift (#9547)


gen-semaphore-yaml:
cd .semaphore && ./generate-semaphore-yaml.sh
Expand Down
10 changes: 0 additions & 10 deletions apiserver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,6 @@ release-build: .release-$(VERSION).created
$(MAKE) FIPS=true retag-build-images-with-registries IMAGETAG=latest-fips RELEASE=true LATEST_IMAGE_TAG=latest-fips
touch $@

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run calico/apiserver | grep 'Version:\s*$(VERSION)$$'; then \
echo "Reported version:" `docker run calico/apiserver` "\nExpected version: $(VERSION)"; \
false; \
else \
echo "Version check passed\n"; \
fi

## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs .release-$(VERSION).published
.release-$(VERSION).published:
Expand Down
14 changes: 2 additions & 12 deletions app-policy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ build-all: $(VALIDARCHES)

.PHONY: build
## Build the binary for the current architecture and platform
build:
build:
$(MAKE) $(BINDIR)/dikastes-$(ARCH) ARCH=$(ARCH)
$(MAKE) $(BINDIR)/healthz-$(ARCH) ARCH=$(ARCH)

Expand Down Expand Up @@ -103,7 +103,7 @@ endif


###############################################################################
# Protobufs,
# Protobufs,
#
# 1. defer to felix's makefile for felixbackend stuff
# 2. build proto for healthz
Expand Down Expand Up @@ -202,16 +202,6 @@ release-build: .release-$(VERSION).created
$(MAKE) FIPS=true retag-build-images-with-registries IMAGETAG=latest-fips RELEASE=true LATEST_IMAGE_TAG=latest-fips
touch $@

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run $(DIKASTES_IMAGE):$(VERSION)-$(ARCH) /dikastes --version | grep '^$(VERSION)$$'; then \
echo "Reported version:" `docker run $(DIKASTES_IMAGE):$(VERSION)-$(ARCH) /dikastes --version` "\nExpected version: $(VERSION)"; \
false; \
else \
echo "Version check passed\n"; \
fi

## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs .release-$(VERSION).published
.release-$(VERSION).published:
Expand Down
10 changes: 0 additions & 10 deletions calicoctl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,6 @@ release-build: .release-$(VERSION).created
$(MAKE) retag-build-images-with-registries IMAGETAG=latest RELEASE=true
touch $@

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run $(CALICOCTL_IMAGE):$(VERSION)-$(ARCH) version | grep 'Version:\s*$(VERSION)$$'; then \
echo "Reported version:" `docker run $(CALICOCTL_IMAGE):$(VERSION)-$(ARCH) version` "\nExpected version: $(VERSION)"; \
false; \
else \
echo "Version check passed\n"; \
fi

## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs .release-$(VERSION).published
.release-$(VERSION).published:
Expand Down
22 changes: 0 additions & 22 deletions cni-plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,28 +283,6 @@ release-build: .release-$(VERSION).created
$(MAKE) release-verify
touch $@

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
$(MAKE) release-verify-version IMAGE=calico/cni:$(VERSION)-$(ARCH)
$(MAKE) release-verify-version IMAGE=calico/cni:$(VERSION)-fips-$(ARCH)
$(MAKE) release-verify-version IMAGE=quay.io/calico/cni:$(VERSION)-$(ARCH)
$(MAKE) release-verify-version IMAGE=quay.io/calico/cni:$(VERSION)-fips-$(ARCH)
# Check that the FIPS binaries have the correct symbols.
$(MAKE) release-verify-fips IMAGE=calico/cni:$(VERSION)-fips-$(ARCH)
$(MAKE) release-verify-fips IMAGE=quay.io/calico/cni:$(VERSION)-fips-$(ARCH)

release-verify-version:
docker run --rm $(IMAGE) calico -v | grep -x $(VERSION) || ( echo "Reported version does not match" && exit 1 )
docker run --rm $(IMAGE) calico-ipam -v | grep -x $(VERSION) || ( echo "Reported version does not match" && exit 1 )

release-verify-fips:
rm -rf .tmp && mkdir -p .tmp
# Copy binaries from the image so we can analyze them.
sh -c "docker create --name calico-cni-verify $(IMAGE); docker cp calico-cni-verify:/opt/cni/bin/install .tmp/calico; docker rm -f calico-cni-verify"
go tool nm .tmp/calico | grep '_Cfunc__goboringcrypto_' 1> /dev/null || echo "ERROR: Binary in image '$(IMAGE)' is missing expected goboring symbols"
rm -rf .tmp

release-publish: release-prereqs .release-$(VERSION).published
.release-$(VERSION).published:
$(MAKE) push-images-to-registries push-manifests IMAGETAG=$(VERSION) RELEASE=$(RELEASE) CONFIRM=$(CONFIRM)
Expand Down
3 changes: 3 additions & 0 deletions key-cert-provisioner/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ KEY_CERT_PROVISIONER_CREATED=.key-cert-provisioner.created-$(ARCH)-fips
VALIDARCHES=amd64
BINDIR=bin/$(ARCH)-fips
LATEST_TAG=latest-fips
BUILD_IMAGES=$(KEY_CERT_PROVISIONER_IMAGE)
PUSH_IMAGES= $(foreach registry,$(DEV_REGISTRIES),$(addprefix $(registry)/,$(BUILD_IMAGES)))
RELEASE_IMAGES= $(foreach registry,$(RELEASE_REGISTRIES),$(addprefix $(registry)/,$(BUILD_IMAGES)))
else
KEY_CERT_PROVISIONER_CREATED=.key-cert-provisioner.created-$(ARCH)
BINDIR=bin
Expand Down
28 changes: 0 additions & 28 deletions kube-controllers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,41 +179,13 @@ release-build: .release-$(VERSION).created
$(MAKE) FIPS=true retag-build-images-with-registries RELEASE=true IMAGETAG=latest-fips LATEST_IMAGE_TAG=latest-fips
touch $@

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run $(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version | grep '^$(VERSION)$$'; then echo "Reported version:" `docker run $(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi
if ! docker run quay.io/$(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version | grep '^$(VERSION)$$'; then echo "Reported version:" `docker run quay.io/$(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi

## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs .release-$(VERSION).published
.release-$(VERSION).published:
$(MAKE) push-images-to-registries push-manifests IMAGETAG=$(VERSION) RELEASE=$(RELEASE) CONFIRM=$(CONFIRM)
$(MAKE) FIPS=true push-images-to-registries push-manifests IMAGETAG=$(VERSION)-fips RELEASE=$(RELEASE) CONFIRM=$(CONFIRM)
touch $@


# WARNING: Only run this target if this release is the latest stable release. Do NOT
# run this target for alpha / beta / release candidate builds, or patches to earlier Calico versions.
## Pushes `latest` release images. WARNING: Only run this for latest stable releases.
release-publish-latest: release-prereqs
# Check latest versions match.
touch $@

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run $(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version | grep '^$(VERSION)$$'; then echo "Reported version:" `docker run $(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi
if ! docker run quay.io/$(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version | grep '^$(VERSION)$$'; then echo "Reported version:" `docker run quay.io/$(KUBE_CONTROLLERS_IMAGE):$(VERSION)-$(ARCH) --version` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi

## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs .release-$(VERSION).published
.release-$(VERSION).published:
$(MAKE) push-images-to-registries push-manifests IMAGETAG=$(VERSION) RELEASE=$(RELEASE) CONFIRM=$(CONFIRM)
$(MAKE) FIPS=true push-images-to-registries push-manifests IMAGETAG=$(VERSION)-fips RELEASE=$(RELEASE) CONFIRM=$(CONFIRM)
touch $@


# WARNING: Only run this target if this release is the latest stable release. Do NOT
# run this target for alpha / beta / release candidate builds, or patches to earlier Calico versions.
## Pushes `latest` release images. WARNING: Only run this for latest stable releases.
Expand Down
22 changes: 11 additions & 11 deletions lib.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1340,15 +1340,15 @@ help:
###############################################################################

# When running on semaphore, just copy the docker config, otherwise run
# 'docker-credential-gcr configure-docker' as well.
# 'docker-credential-gcloud configure-docker' as well.
ifdef SEMAPHORE
DOCKER_CREDENTIAL_CMD = cp /root/.docker/config.json_host /root/.docker/config.json
else
DOCKER_CREDENTIAL_CMD = cp /root/.docker/config.json_host /root/.docker/config.json && \
docker-credential-gcr configure-docker
docker-credential-gcloud configure-docker
endif

# This needs the $(WINDOWS_DIST)/bin/docker-credential-gcr binary in $PATH and
# This needs the $(WINDOWS_DIST)/bin/docker-credential-gcloud binary in $PATH and
# also the local ~/.config/gcloud dir to be able to push to gcr.io. It mounts
# $(DOCKER_CONFIG) and copies it so that it can be written to on the container,
# but not have any effect on the host config.
Expand Down Expand Up @@ -1438,17 +1438,17 @@ setup-windows-builder: clean-windows-builder

$(WINDOWS_DIST)/$(WINDOWS_IMAGE)-$(GIT_VERSION)-%.tar: windows-sub-image-$*

DOCKER_CREDENTIAL_VERSION="2.1.18"

DOCKER_CREDENTIAL_OS="linux"
DOCKER_CREDENTIAL_ARCH="amd64"
$(WINDOWS_DIST)/bin/docker-credential-gcr:
$(WINDOWS_DIST)/bin/docker-credential-gcloud:
-mkdir -p $(WINDOWS_DIST)/bin
curl -fsSL "https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v$(DOCKER_CREDENTIAL_VERSION)/docker-credential-gcr_$(DOCKER_CREDENTIAL_OS)_$(DOCKER_CREDENTIAL_ARCH)-$(DOCKER_CREDENTIAL_VERSION).tar.gz" \
| tar xz --to-stdout docker-credential-gcr \
| tee $(WINDOWS_DIST)/bin/docker-credential-gcr > /dev/null && chmod +x $(WINDOWS_DIST)/bin/docker-credential-gcr
curl -fsSL "https://github.com/GoogleCloudPlatform/docker-credential-gcloud/releases/download/v$(DOCKER_CREDENTIAL_GCLOUD_VERSION)/docker-credential-gcloud_$(DOCKER_CREDENTIAL_OS)_$(DOCKER_CREDENTIAL_ARCH)-$(DOCKER_CREDENTIAL_GCLOUD_VERSION).tar.gz" \
| tar xz --to-stdout docker-credential-gcloud \
| tee $(WINDOWS_DIST)/bin/docker-credential-gcloud > /dev/null && chmod +x $(WINDOWS_DIST)/bin/docker-credential-gcloud

.PHONY: docker-credential-gcr-binary
docker-credential-gcr-binary: var-require-all-WINDOWS_DIST-DOCKER_CREDENTIAL_VERSION-DOCKER_CREDENTIAL_OS-DOCKER_CREDENTIAL_ARCH $(WINDOWS_DIST)/bin/docker-credential-gcr
.PHONY: docker-credential-gcloud-binary
docker-credential-gcloud-binary: var-require-all-WINDOWS_DIST-DOCKER_CREDENTIAL_GCLOUD_VERSION-DOCKER_CREDENTIAL_OS-DOCKER_CREDENTIAL_ARCH $(WINDOWS_DIST)/bin/docker-credential-gcloud
radTuti marked this conversation as resolved.
Show resolved Hide resolved

# NOTE: WINDOWS_IMAGE_REQS must be defined with the requirements to build the windows
# image. These must be added as reqs to 'image-windows' (originally defined in
Expand All @@ -1472,7 +1472,7 @@ image-windows: setup-windows-builder var-require-all-WINDOWS_VERSIONS
$(MAKE) windows-sub-image-$${version}; \
done;

release-windows-with-tag: var-require-one-of-CONFIRM-DRYRUN var-require-all-IMAGETAG-DEV_REGISTRIES image-windows docker-credential-gcr-binary
release-windows-with-tag: var-require-one-of-CONFIRM-DRYRUN var-require-all-IMAGETAG-DEV_REGISTRIES image-windows docker-credential-gcloud-binary
for registry in $(DEV_REGISTRIES); do \
echo Pushing Windows images to $${registry}; \
all_images=""; \
Expand Down
2 changes: 2 additions & 0 deletions metadata.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ DEV_REGISTRIES ?= calico
# The directory for windows image tarballs
WINDOWS_DIST = dist/windows

DOCKER_CREDENTIAL_GCLOUD_VERSION=2.1.26

# FIXME: Use WINDOWS_HPC_VERSION and remove WINDOWS_VERSIONS when containerd v1.6 is EOL'd
# The Windows HPC container version used as base for Calico Windows images
WINDOWS_HPC_VERSION ?= v1.0.0
Expand Down
7 changes: 1 addition & 6 deletions node/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,6 @@ release-build: .release-$(VERSION).created
release-windows-archive: release-prereqs
$(MAKE) build-windows-archive WINDOWS_ARCHIVE_TAG=$(VERSION)

## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run $(NODE_IMAGE):$(VERSION)-$(ARCH) versions | grep '^$(VERSION)$$'; then echo "Reported version:" `docker run $(NODE_IMAGE):$(VERSION)-$(ARCH) versions` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi

## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs .release-$(VERSION).published
.release-$(VERSION).published:
Expand All @@ -490,7 +485,7 @@ release-publish: release-prereqs .release-$(VERSION).published
# WARNING: Only run this target if this release is the latest stable release. Do NOT
# run this target for alpha / beta / release candidate builds, or patches to earlier Calico versions.
## Pushes `latest` release images. WARNING: Only run this for latest stable releases.
release-publish-latest: release-verify
release-publish-latest:
$(MAKE) push-images-to-registries push-manifests IMAGETAG=latest RELEASE=$(RELEASE) CONFIRM=$(CONFIRM)
# Push Windows images.
$(MAKE) release-windows IMAGETAG=latest CONFIRM=$(CONFIRM)
Expand Down
1 change: 1 addition & 0 deletions release/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ When starting development on a new minor release, the first step is to create a

- charts/calico/values.yaml
- charts/tigera-operator/values.yaml
- metadata.mk (OPERATOR_BRANCH)

Then, run manifest generation

Expand Down
Loading
Loading