Skip to content

Commit 563faea

Browse files
authored
Merge pull request #730 from justinsb/chore_push_images
chore: create scripts to build and push images
2 parents 26cc96a + 80d4850 commit 563faea

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

Makefile

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,6 @@ build: manifests generate fmt vet ## Build controller binary.
135135
run: manifests generate fmt vet ## Run a controller from your host.
136136
go run ./cmd/controller/main.go
137137

138-
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
139-
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
140-
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
141-
.PHONY: image-build
142-
image-build: ## Build docker image with the manager.
143-
$(CONTAINER_TOOL) build -t ${IMG} .
144-
145-
.PHONY: image-push
146-
image-push: ## Push docker image with the manager.
147-
$(CONTAINER_TOOL) push ${IMG}
148-
149-
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
150-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
151-
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
152-
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
153-
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
154-
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
155-
PLATFORMS ?= linux/arm64,linux/amd64
156-
.PHONY: docker-buildx
157-
image-buildx: ## Build and push docker image for the manager for cross-platform support
158-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
159-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
160-
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
161-
$(CONTAINER_TOOL) buildx use project-v3-builder
162-
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
163-
- $(CONTAINER_TOOL) buildx rm project-v3-builder
164-
rm Dockerfile.cross
165-
166138
##@ Build Dependencies
167139

168140
## Location to install dependencies to
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://cloud.google.com/cloud-build/docs/build-config
2+
options:
3+
substitution_option: ALLOW_LOOSE
4+
machineType: E2_HIGHCPU_32
5+
steps:
6+
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20250116-2a05ea7e3d
7+
entrypoint: dev/tasks/push-images
8+
env:
9+
- IMAGE_PREFIX=us-central1-docker.pkg.dev/k8s-staging-images/kro/

dev/tasks/push-images

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
5+
REPO_ROOT=$(git rev-parse --show-toplevel)
6+
cd "$REPO_ROOT"
7+
8+
if [[ -z ${IMAGE_PREFIX:-} ]]; then
9+
echo "IMAGE_PREFIX is not set"
10+
exit 1
11+
fi
12+
13+
if [[ -z ${IMAGE_TAG:-} ]]; then
14+
# Use a tag if the current commit is a tag, otherwise use a date+git-hash tag
15+
if git describe --exact-match --tags HEAD >/dev/null 2>&1; then
16+
IMAGE_TAG=$(git describe --exact-match --tags HEAD)
17+
else
18+
IMAGE_TAG="$(date +v%Y%m%d)-$(git rev-parse --short HEAD)"
19+
fi
20+
fi
21+
echo "Using IMAGE_TAG=${IMAGE_TAG}"
22+
23+
# build first, technically this is not needed as publish does a build too
24+
RELEASE_VERSION=${IMAGE_TAG} OCI_REPO=${IMAGE_PREFIX%/} make build-image
25+
26+
# Do the actual publish
27+
RELEASE_VERSION=${IMAGE_TAG} OCI_REPO=${IMAGE_PREFIX%/} make publish-image

0 commit comments

Comments
 (0)