Skip to content

Commit

Permalink
K8s - Allow crane binary to be set (#2834)
Browse files Browse the repository at this point in the history
* K8s - Allow crane binary to be set

* chore: decrease tests timeout to trigger wordpress tests

* chore: add verbosity to crane download

* chore: add verbosity to crane download

* feat: download crane once for every step

* feat: download crane once for every step

* feat: download crane once for every step

* feat: download crane once for every step
  • Loading branch information
armandomiani authored Jan 9, 2025
1 parent 012ff0d commit 36cd182
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
18 changes: 18 additions & 0 deletions cloudbuild-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ steps:
docker pull "gcr.io/cloud-marketplace-tools/k8s/dev:$$TAG"
docker tag "gcr.io/cloud-marketplace-tools/k8s/dev:$$TAG" "gcr.io/cloud-marketplace-tools/k8s/dev:local"
- id: Setup Crane
name: gcr.io/cloud-builders/curl
entrypoint: sh
args:
- '-c'
- |
curl -L -o /workspace/crane.tar.gz "https://github.com/google/go-containerregistry/releases/download/v0.20.2/go-containerregistry_Linux_x86_64.tar.gz" \
&& tar -zxvf /workspace/crane.tar.gz crane \
&& chmod 755 /workspace/crane \
&& chmod +x /workspace/crane \
&& rm /workspace/crane.tar.gz \
&& echo "crane successfully installed"
- id: Initialize Credentials
name: gcr.io/cloud-builders/gcloud
waitFor:
Expand All @@ -56,6 +69,7 @@ steps:
# Use local Docker network named cloudbuild as described here:
# https://cloud.google.com/cloud-build/docs/overview#build_configuration_and_build_steps
- 'DOCKER_NETWORK=cloudbuild'
- 'CRANE_BIN=/workspace/crane'
dir: k8s/${_SOLUTION_NAME}
entrypoint: bash
args:
Expand All @@ -72,6 +86,7 @@ steps:
- 'KUBE_CONFIG=/workspace/.kube'
- 'GCLOUD_CONFIG=/workspace/.config/gcloud'
- 'VERIFICATION_LOGS_PATH=/workspace/k8s/${_SOLUTION_NAME}/.mpdev_logs'
- 'CRANE_BIN=/workspace/crane'
# Use local Docker network named cloudbuild as described here:
# https://cloud.google.com/cloud-build/docs/overview#build_configuration_and_build_steps
- 'DOCKER_NETWORK=cloudbuild'
Expand All @@ -88,6 +103,7 @@ steps:
- 'KUBE_CONFIG=/workspace/.kube'
- 'GCLOUD_CONFIG=/workspace/.config/gcloud'
- 'VERIFICATION_LOGS_PATH=/workspace/k8s/${_SOLUTION_NAME}/.mpdev_logs'
- 'CRANE_BIN=/workspace/crane'
# Use local Docker network named cloudbuild as described here:
# https://cloud.google.com/cloud-build/docs/overview#build_configuration_and_build_steps
- 'DOCKER_NETWORK=cloudbuild'
Expand All @@ -105,6 +121,7 @@ steps:
- 'KUBE_CONFIG=/workspace/.kube'
- 'GCLOUD_CONFIG=/workspace/.config/gcloud'
- 'VERIFICATION_LOGS_PATH=/workspace/k8s/${_SOLUTION_NAME}/.mpdev_logs'
- 'CRANE_BIN=/workspace/crane'
# Use local Docker network named cloudbuild as described here:
# https://cloud.google.com/cloud-build/docs/overview#build_configuration_and_build_steps
- 'DOCKER_NETWORK=cloudbuild'
Expand All @@ -125,6 +142,7 @@ steps:
# Use local Docker network named cloudbuild as described here:
# https://cloud.google.com/cloud-build/docs/overview#build_configuration_and_build_steps
- 'DOCKER_NETWORK=cloudbuild'
- 'CRANE_BIN=/workspace/crane'
dir: k8s/${_SOLUTION_NAME}
entrypoint: bash
args:
Expand Down
27 changes: 20 additions & 7 deletions k8s/c2d_deployer.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif

$(info ---- image-$(CHART_NAME) = $(image-$(CHART_NAME)))

SHELL := /bin/bash

##### Common variables #####

Expand Down Expand Up @@ -54,15 +55,27 @@ app/build:: .build/setup_crane \
.build/$(CHART_NAME)/images \
.build/$(CHART_NAME)/deployer

CRANE_BIN ?=
CRANE_AUTOINSTALL := false

ifeq ($(CRANE_BIN),)
CRANE_BIN := /usr/local/bin/crane
CRANE_AUTOINSTALL := true
else
CRANE_AUTOINSTALL := false
endif

.build/setup_crane:
@if ! command -v crane &>/dev/null; then \
@echo "Using Crane Bin at: $(CRANE_BIN)"
@echo "Install Crane? $(CRANE_AUTOINSTALL)"

@if ! command -v crane &>/dev/null && "$(CRANE_AUTOINSTALL)" == "true"; then \
set -x; \
VERSION=v0.20.2; \
OS=Linux; \
ARCH=x86_64; \
echo "Downloading crane version $$VERSION..."; \
curl -L -o go-containerregistry.tar.gz "https://github.com/google/go-containerregistry/releases/download/$$VERSION/go-containerregistry_$${OS}_$${ARCH}.tar.gz" \
curl -v -L -o go-containerregistry.tar.gz "https://github.com/google/go-containerregistry/releases/download/$$VERSION/go-containerregistry_$${OS}_$${ARCH}.tar.gz" \
&& tar -zxvf go-containerregistry.tar.gz crane \
&& mv crane /usr/local/bin/crane \
&& chmod 755 /usr/local/bin/crane \
Expand All @@ -72,7 +85,7 @@ app/build:: .build/setup_crane \
else \
echo "crane is already installed"; \
fi; \
crane version
"$(CRANE_BIN)" version


.build/$(CHART_NAME)/deployer: .build/setup_crane \
Expand Down Expand Up @@ -114,8 +127,8 @@ app/build:: .build/setup_crane \
| .build/$(CHART_NAME)
$(call print_target,$@)

crane copy "$(image-$(CHART_NAME))" "$(REGISTRY)/$(APP_ID):$(TRACK)"
crane copy "$(image-$(CHART_NAME))" "$(REGISTRY)/$(APP_ID):$(RELEASE)"
"$(CRANE_BIN)" copy "$(image-$(CHART_NAME))" "$(REGISTRY)/$(APP_ID):$(TRACK)"
"$(CRANE_BIN)" copy "$(image-$(CHART_NAME))" "$(REGISTRY)/$(APP_ID):$(RELEASE)"
@touch "$@"


Expand All @@ -134,8 +147,8 @@ $(IMAGE_TARGETS_LIST): .build/$(CHART_NAME)/%: .build/setup_crane \
| .build/$(CHART_NAME)
$(call print_target,$*)

crane copy "$(image-$*)" "$(REGISTRY)/$(APP_ID)/$*:$(TRACK)"
crane copy "$(image-$*)" "$(REGISTRY)/$(APP_ID)/$*:$(RELEASE)"
"$(CRANE_BIN)" copy "$(image-$*)" "$(REGISTRY)/$(APP_ID)/$*:$(TRACK)"
"$(CRANE_BIN)" copy "$(image-$*)" "$(REGISTRY)/$(APP_ID)/$*:$(RELEASE)"
@touch "$@"


Expand Down
2 changes: 1 addition & 1 deletion k8s/wordpress/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include ../images.Makefile

CHART_NAME := wordpress
APP_ID ?= $(CHART_NAME)
VERIFY_WAIT_TIMEOUT = 1800
VERIFY_WAIT_TIMEOUT = 1700

SERVICE_NAME := services/d60f6935-b4e7-46b3-8f96-eece88c7cd42.cloudpartnerservices.goog
TRACK ?= 6.6
Expand Down

0 comments on commit 36cd182

Please sign in to comment.