Skip to content

Commit

Permalink
Merge branch 'master' into miani-k8s-add-all-annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
armandomiani authored Jan 10, 2025
2 parents 7878b7e + 36cd182 commit 3621474
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 34 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
1 change: 1 addition & 0 deletions k8s/app_v2.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ app/uninstall: .build/var/APP_DEPLOYER_IMAGE \
app/verify: app/publish \
.build/var/APP_DEPLOYER_IMAGE \
.build/var/MARKETPLACE_TOOLS_TAG \
.build/setup_crane \
| .build/app/dev
$(call print_target)
.build/app/dev verify \
Expand Down
111 changes: 79 additions & 32 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 All @@ -48,14 +49,47 @@ $(info ---- RELEASE = $(RELEASE))
.build/$(CHART_NAME): | .build
mkdir -p "$@"


app/build:: .build/$(CHART_NAME)/VERSION \
app/build:: .build/setup_crane \
.build/$(CHART_NAME)/VERSION \
.build/$(CHART_NAME)/$(CHART_NAME) \
.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/$(CHART_NAME)/deployer: deployer/* \
.build/setup_crane:
@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 -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 \
&& chmod +x /usr/local/bin/crane \
&& rm go-containerregistry.tar.gz \
&& echo "crane successfully installed"; \
else \
echo "crane is already installed"; \
fi; \
"$(CRANE_BIN)" version


.build/$(CHART_NAME)/deployer: .build/setup_crane \
deployer/* \
chart/$(CHART_NAME)/* \
chart/$(CHART_NAME)/templates/* \
schema.yaml \
Expand All @@ -67,68 +101,81 @@ app/build:: .build/$(CHART_NAME)/VERSION \
.build/var/RELEASE \
| .build/$(CHART_NAME)
$(call print_target,$@)
docker build \
--build-arg REGISTRY="$(REGISTRY)/$(APP_ID)" \
--build-arg TAG="$(RELEASE)" \
--build-arg CHART_NAME="$(CHART_NAME)" \
--build-arg MARKETPLACE_TOOLS_TAG="$(MARKETPLACE_TOOLS_TAG)" \
--tag "$(APP_DEPLOYER_IMAGE)" \
-f deployer/Dockerfile \
.
docker tag "$(APP_DEPLOYER_IMAGE)" "$(APP_DEPLOYER_IMAGE_TRACK_TAG)"
docker push "$(APP_DEPLOYER_IMAGE)"
docker push "$(APP_DEPLOYER_IMAGE_TRACK_TAG)"

DEPLOYER_BUILDER="deployer-builder-$$(openssl rand -base64 12 | tr -dc 'a-z0-9' | head -c 8)"; \
docker buildx create --name "$$DEPLOYER_BUILDER" --use \
&& docker buildx inspect "$$DEPLOYER_BUILDER" --bootstrap \
&& docker buildx build \
--push \
--annotation="index,manifest:cloudmarketplace.googleapis.com/service=$(SERVICE_NAME)" \
--build-arg REGISTRY="$(REGISTRY)/$(APP_ID)" \
--build-arg TAG="$(RELEASE)" \
--build-arg CHART_NAME="$(CHART_NAME)" \
--build-arg MARKETPLACE_TOOLS_TAG="$(MARKETPLACE_TOOLS_TAG)" \
--tag "$(APP_DEPLOYER_IMAGE)" \
--tag "$(APP_DEPLOYER_IMAGE_TRACK_TAG)" \
-f deployer/Dockerfile \
. \
&& docker buildx rm "$$DEPLOYER_BUILDER"
@touch "$@"


.build/$(CHART_NAME)/$(CHART_NAME): .build/var/REGISTRY \
.build/$(CHART_NAME)/$(CHART_NAME): .build/setup_crane \
.build/var/REGISTRY \
.build/var/TRACK \
.build/var/RELEASE \
| .build/$(CHART_NAME)
$(call print_target,$@)
docker pull $(image-$(CHART_NAME))
docker tag $(image-$(CHART_NAME)) "$(REGISTRY)/$(APP_ID):$(TRACK)"
docker tag $(image-$(CHART_NAME)) "$(REGISTRY)/$(APP_ID):$(RELEASE)"
docker push "$(REGISTRY)/$(APP_ID):$(TRACK)"
docker push "$(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 "$@"


# map every element of ADDITIONAL_IMAGES list
# from [image-name] to .build/$(CHART_NAME)/[image-name] format
IMAGE_TARGETS_LIST = $(patsubst %,.build/$(CHART_NAME)/%,$(ADDITIONAL_IMAGES))
.build/$(CHART_NAME)/images: $(IMAGE_TARGETS_LIST)
.build/$(CHART_NAME)/images: .build/setup_crane \
$(IMAGE_TARGETS_LIST)

# extract image name from rule with .build/$(CHART_NAME)/%
# and use % match as $* in recipe
$(IMAGE_TARGETS_LIST): .build/$(CHART_NAME)/%: .build/var/REGISTRY \
$(IMAGE_TARGETS_LIST): .build/$(CHART_NAME)/%: .build/setup_crane \
.build/var/REGISTRY \
.build/var/TRACK \
.build/var/RELEASE \
| .build/$(CHART_NAME)
$(call print_target,$*)
docker pull $(image-$*)
docker tag $(image-$*) "$(REGISTRY)/$(APP_ID)/$*:$(TRACK)"
docker tag $(image-$*) "$(REGISTRY)/$(APP_ID)/$*:$(RELEASE)"
docker push "$(REGISTRY)/$(APP_ID)/$*:$(TRACK)"
docker push "$(REGISTRY)/$(APP_ID)/$*:$(RELEASE)"

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


.build/$(CHART_NAME)/tester: .build/var/APP_TESTER_IMAGE \
.build/$(CHART_NAME)/tester: .build/setup_crane \
.build/var/APP_TESTER_IMAGE \
$(shell find apptest -type f) \
| .build/$(CHART_NAME)
$(call print_target,$@)
cd apptest/tester \
&& docker build --tag "$(APP_TESTER_IMAGE)" .
docker push "$(APP_TESTER_IMAGE)"

TESTER_BUILDER="tester-builder-$$(openssl rand -base64 12 | tr -dc 'a-z0-9' | head -c 8)"; \
docker buildx create --name "$$TESTER_BUILDER" --use \
&& docker buildx inspect "$$TESTER_BUILDER" --bootstrap \
&& cd apptest/tester \
&& docker buildx build \
--push \
--annotation="index,manifest:cloudmarketplace.googleapis.com/service=$(SERVICE_NAME)" \
--tag "$(APP_TESTER_IMAGE)" . \
&& docker buildx rm "$$TESTER_BUILDER"
@touch "$@"


########### Main targets ###########


.PHONY: .build/$(CHART_NAME)/VERSION
.build/$(CHART_NAME)/VERSION:
.build/$(CHART_NAME)/VERSION: .build/setup_crane \
| .build/$(CHART_NAME)
$(call print_target,$@)
@echo "$(C2D_CONTAINER_RELEASE)" | grep -qE "^$(TRACK)\.[0-9]+(\.[0-9]+)?$$" || \
( echo "C2D_RELEASE doesn't start with TRACK or doesn't match TRACK exactly"; exit 1 )
Expand Down
3 changes: 2 additions & 1 deletion k8s/wordpress/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ 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

METRICS_EXPORTER_TAG ?= v0.5.1
Expand Down
2 changes: 1 addition & 1 deletion k8s/wordpress/apptest/tester/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gcr.io/cloud-marketplace-tools/testrunner:0.1.5
FROM gcr.io/cloud-marketplace-tools/testrunner:0.1.8

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
Expand Down

0 comments on commit 3621474

Please sign in to comment.