Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nhinze23 authored and cesmarvin committed Aug 31, 2023
2 parents 28a1cd1 + fe3beb5 commit e07ebde
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.2.0] - 2023-08-31
### Added
- [#5] Add helm-chart with dependencies and release the helm-chart in the build-pipeline

## [v0.1.1] - 2023-07-13

### Changed
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN make compile-generic
FROM gcr.io/distroless/static:nonroot
LABEL maintainer="hello@cloudogu.com" \
NAME="k8s-host-change" \
VERSION="0.1.1"
VERSION="0.2.0"

WORKDIR /

Expand Down
27 changes: 22 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!groovy

@Library('github.com/cloudogu/ces-build-lib@1.62.0')
@Library('github.com/cloudogu/ces-build-lib@1.66.0')
import com.cloudogu.ces.cesbuildlib.*

// Creating necessary git objects
Expand All @@ -13,11 +13,14 @@ changelog = new Changelog(this)
Docker docker = new Docker(this)
gpg = new Gpg(this, docker)
goVersion = "1.20"
Makefile makefile = new Makefile(this)

// Configuration of repository
repositoryOwner = "cloudogu"
repositoryName = "k8s-host-change"
project = "github.com/${repositoryOwner}/${repositoryName}"
registry = "registry.cloudogu.com"
registry_namespace = "k8s"

// Configuration of branches
productionReleaseBranch = "main"
Expand Down Expand Up @@ -135,6 +138,7 @@ void stageAutomaticRelease() {
if (gitflow.isReleaseBranch()) {
String releaseVersion = git.getSimpleBranchName()
String dockerReleaseVersion = releaseVersion.split("v")[1]
String controllerVersion = makefile.getVersion()

stage('Build & Push Image') {
def dockerImage = docker.build("cloudogu/${repositoryName}:${dockerReleaseVersion}")
Expand Down Expand Up @@ -162,12 +166,25 @@ void stageAutomaticRelease() {
}

stage('Push to Registry') {
Makefile makefile = new Makefile(this)
String hostChangeVersion = makefile.getVersion()
GString targetOperatorResourceYaml = "target/make/k8s/${repositoryName}_${hostChangeVersion}.yaml"
GString targetOperatorResourceYaml = "target/make/k8s/${repositoryName}_${controllerVersion}.yaml"

DoguRegistry registry = new DoguRegistry(this)
registry.pushK8sYaml(targetOperatorResourceYaml, repositoryName, "k8s", "${hostChangeVersion}")
registry.pushK8sYaml(targetOperatorResourceYaml, repositoryName, "k8s", "${controllerVersion}")
}

stage('Push Helm chart to Harbor') {
new Docker(this)
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/go/src/${project} -w /go/src/${project}")
{
make 'k8s-helm-package-release'

withCredentials([usernamePassword(credentialsId: 'harborhelmchartpush', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
sh ".bin/helm registry login ${registry} --username '${HARBOR_USERNAME}' --password '${HARBOR_PASSWORD}'"
sh ".bin/helm push target/make/k8s/helm/${repositoryName}-${controllerVersion}.tgz oci://${registry}/${registry_namespace}/"
}
}
}

stage('Add Github-Release') {
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Set these to the desired values
ARTIFACT_ID=k8s-host-change
VERSION=0.1.1
VERSION=0.2.0

GOTAG?=1.20.2
MAKEFILES_VERSION=7.5.0
MAKEFILES_VERSION=7.13.0

## Image URL to use all building/pushing image targets
IMAGE_DEV=${K3CES_REGISTRY_URL_PREFIX}/${ARTIFACT_ID}:${VERSION}
Expand Down
4 changes: 2 additions & 2 deletions build/make/k8s-controller.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ K8S_INTEGRATION_TEST_DIR=${TARGET_DIR}/k8s-integration-test
##@ K8s - EcoSystem

.PHONY: build
build: image-import k8s-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem.
build: k8s-helm-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem.

##@ Release

Expand Down Expand Up @@ -83,7 +83,7 @@ k8s-integration-test: $(K8S_INTEGRATION_TEST_DIR) manifests generate envtest ##
CONTROLLER_GEN = $(UTILITY_BIN_PATH)/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.11.3)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.13.0)

KUSTOMIZE = $(UTILITY_BIN_PATH)/kustomize
.PHONY: kustomize
Expand Down
2 changes: 1 addition & 1 deletion build/make/k8s-dogu.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DOGU_JSON_DEV_FILE=${TARGET_DIR}/dogu.json
ARTIFACT_ID=$(shell $(BINARY_YQ) -e ".Name" $(DOGU_JSON_FILE) | sed "s|.*/||g")
# Namespace of the dogu is extracted from the dogu.json
ARTIFACT_NAMESPACE=$(shell $(BINARY_YQ) -e ".Name" $(DOGU_JSON_FILE) | sed "s|/.*||g")
# Namespace of the dogu is extracted from the dogu.json
# Version of the dogu is extracted from the dogu.json
VERSION=$(shell $(BINARY_YQ) -e ".Version" $(DOGU_JSON_FILE))
# Image of the dogu is extracted from the dogu.json
IMAGE=$(shell $(BINARY_YQ) -e ".Image" $(DOGU_JSON_FILE)):$(VERSION)
Expand Down
2 changes: 1 addition & 1 deletion build/make/k8s-dogu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Dogu
metadata:
name: NAME
labels:
dogu: NAME
app: ces
spec:
name: NAMESPACE/NAME
version: VERSION
3 changes: 3 additions & 0 deletions build/make/k8s-helm-temp-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
apiVersion: v2
name: replaceme
version: 0.0.0
94 changes: 92 additions & 2 deletions build/make/k8s.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ endif
## Variables

BINARY_YQ = $(UTILITY_BIN_PATH)/yq
BINARY_HELM = $(UTILITY_BIN_PATH)/helm
BINARY_HELM_VERSION?=v3.12.0-dev.1.0.20230817154107-a749b663101d
BINARY_HELM_ADDITIONAL_PUSH_ARGS?=--plain-http
BINARY_HELM_ADDITIONAL_PACK_ARGS?=
BINARY_HELM_ADDITIONAL_UNINST_ARGS?=
BINARY_HELM_ADDITIONAL_UPGR_ARGS?=

# The productive tag of the image
IMAGE ?=
Expand All @@ -19,6 +25,10 @@ K3CES_REGISTRY_URL_PREFIX="${K3S_CLUSTER_FQDN}:${K3S_LOCAL_REGISTRY_PORT}"
# the current namespace and the dev image.
K8S_RESOURCE_TEMP_FOLDER ?= $(TARGET_DIR)/make/k8s
K8S_RESOURCE_TEMP_YAML ?= $(K8S_RESOURCE_TEMP_FOLDER)/$(ARTIFACT_ID)_$(VERSION).yaml
K8S_HELM_TARGET ?= $(K8S_RESOURCE_TEMP_FOLDER)/helm
K8S_HELM_RESSOURCES ?= k8s/helm
K8S_HELM_RELEASE_TGZ=${K8S_HELM_TARGET}/${ARTIFACT_ID}-${VERSION}.tgz
K8S_HELM_TARGET_DEP_DIR=charts

##@ K8s - Variables

Expand Down Expand Up @@ -75,6 +85,83 @@ k8s-apply: k8s-generate $(K8S_POST_GENERATE_TARGETS) ## Applies all generated K8
@echo "Apply generated K8s resources..."
@kubectl apply -f $(K8S_RESOURCE_TEMP_YAML) --namespace=${NAMESPACE}

##@ K8s - Helm general
.PHONY: k8s-helm-init-chart
k8s-helm-init-chart: ${BINARY_HELM} ## Creates a Chart.yaml-template with zero values
@echo "Initialize ${K8S_HELM_RESSOURCES}/Chart.yaml..."
@mkdir -p ${K8S_HELM_RESSOURCES}/tmp/
@${BINARY_HELM} create ${K8S_HELM_RESSOURCES}/tmp/${ARTIFACT_ID}
@cp ${K8S_HELM_RESSOURCES}/tmp/${ARTIFACT_ID}/Chart.yaml ${K8S_HELM_RESSOURCES}/
@rm -dr ${K8S_HELM_RESSOURCES}/tmp
@sed -i 's/appVersion: ".*"/appVersion: "0.0.0-replaceme"/' ${K8S_HELM_RESSOURCES}/Chart.yaml
@sed -i 's/version: .*/version: 0.0.0-replaceme/' ${K8S_HELM_RESSOURCES}/Chart.yaml

.PHONY: k8s-helm-delete
k8s-helm-delete: ${BINARY_HELM} check-k8s-namespace-env-var ## Uninstalls the current helm chart.
@echo "Uninstall helm chart"
@${BINARY_HELM} uninstall ${ARTIFACT_ID} --namespace=${NAMESPACE} ${BINARY_HELM_ADDITIONAL_UNINST_ARGS} || true

.PHONY: k8s-helm-generate-chart
k8s-helm-generate-chart: ${K8S_HELM_TARGET}/Chart.yaml k8s-helm-create-temp-dependencies ## Generates the final helm chart.

${K8S_HELM_TARGET}/Chart.yaml: $(K8S_RESOURCE_TEMP_FOLDER)
@echo "Generate helm chart..."
@rm -drf ${K8S_HELM_TARGET} # delete folder, so the chart is newly created.
@mkdir -p ${K8S_HELM_TARGET}/templates
@cp $(K8S_RESOURCE_TEMP_YAML) ${K8S_HELM_TARGET}/templates
@cp -r ${K8S_HELM_RESSOURCES}/** ${K8S_HELM_TARGET}
@sed -i 's/appVersion: "0.0.0-replaceme"/appVersion: "${VERSION}"/' ${K8S_HELM_TARGET}/Chart.yaml
@sed -i 's/version: 0.0.0-replaceme/version: ${VERSION}/' ${K8S_HELM_TARGET}/Chart.yaml

##@ K8s - Helm dev targets

.PHONY: k8s-helm-generate
k8s-helm-generate: k8s-generate k8s-helm-generate-chart ## Generates the final helm chart with dev-urls.

.PHONY: k8s-helm-apply
k8s-helm-apply: ${BINARY_HELM} check-k8s-namespace-env-var image-import k8s-helm-generate $(K8S_POST_GENERATE_TARGETS) ## Generates and installs the helm chart.
@echo "Apply generated helm chart"
@${BINARY_HELM} upgrade -i ${ARTIFACT_ID} ${K8S_HELM_TARGET} ${BINARY_HELM_ADDITIONAL_UPGR_ARGS} --namespace ${NAMESPACE}

.PHONY: k8s-helm-reinstall
k8s-helm-reinstall: k8s-helm-delete k8s-helm-apply ## Uninstalls the current helm chart and reinstalls it.

##@ K8s - Helm release targets

.PHONY: k8s-helm-generate-release
k8s-helm-generate-release: ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml ## Generates the final helm chart with release urls.

${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml: $(K8S_PRE_GENERATE_TARGETS) ${K8S_HELM_TARGET}/Chart.yaml
@sed -i "s/'{{ .Namespace }}'/'{{ .Release.Namespace }}'/" ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml

.PHONY: k8s-helm-package-release
k8s-helm-package-release: ${BINARY_HELM} k8s-helm-delete-existing-tgz ${K8S_HELM_RELEASE_TGZ} ## Generates and packages the helm chart with release urls.

.PHONY: k8s-helm-delete-existing-tgz
k8s-helm-delete-existing-tgz: ## Remove an existing Helm package.
# remove
@rm -f ${K8S_HELM_RELEASE_TGZ}*

${K8S_HELM_RELEASE_TGZ}: ${BINARY_HELM} ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml k8s-helm-generate-chart $(K8S_POST_GENERATE_TARGETS) ## Generates and packages the helm chart with release urls.
@echo "Package generated helm chart"
@${BINARY_HELM} package ${K8S_HELM_TARGET} -d ${K8S_HELM_TARGET} ${BINARY_HELM_ADDITIONAL_PACK_ARGS}

.PHONY: k8s-helm-create-temp-dependencies
k8s-helm-create-temp-dependencies: ${K8S_HELM_TARGET}/Chart.yaml
# we use helm dependencies internally but never use them as "official" dependency because the namespace may differ
# instead we create empty dependencies to satisfy the helm package call and delete the whole directory from the chart.tgz later-on.
@echo "Create helm temp dependencies (if they exist)"
@for dep in `yq -e '.dependencies[].name // ""' ${K8S_HELM_TARGET}/Chart.yaml`; do \
mkdir -p ${K8S_HELM_TARGET}/${K8S_HELM_TARGET_DEP_DIR}/$${dep} ; \
sed "s|replaceme|$${dep}|g" $(BUILD_DIR)/make/k8s-helm-temp-chart.yaml > ${K8S_HELM_TARGET}/${K8S_HELM_TARGET_DEP_DIR}/$${dep}/Chart.yaml ; \
done

.PHONY: chart-import
chart-import: check-all-vars check-k8s-artifact-id k8s-helm-generate-chart k8s-helm-package-release image-import ## Imports the currently available image into the cluster-local registry.
@echo "Import ${K8S_HELM_RELEASE_TGZ} into K8s cluster ${K3CES_REGISTRY_URL_PREFIX}..."
@${BINARY_HELM} push ${K8S_HELM_RELEASE_TGZ} oci://${K3CES_REGISTRY_URL_PREFIX}/k8s ${BINARY_HELM_ADDITIONAL_PUSH_ARGS}
@echo "Done."

##@ K8s - Docker

.PHONY: docker-build
Expand Down Expand Up @@ -115,5 +202,8 @@ __check_defined = \
$(if $(value $1),, \
$(error Undefined $1$(if $2, ($2))))

${BINARY_YQ}: $(UTILITY_BIN_PATH) ## Download controller-gen locally if necessary.
$(call go-get-tool,$(BINARY_YQ),github.com/mikefarah/yq/v4@v4.25.1)
${BINARY_YQ}: $(UTILITY_BIN_PATH) ## Download yq locally if necessary.
$(call go-get-tool,$(BINARY_YQ),github.com/mikefarah/yq/v4@v4.25.1)

${BINARY_HELM}: $(UTILITY_BIN_PATH) ## Download helm locally if necessary.
$(call go-get-tool,$(BINARY_HELM),helm.sh/helm/v3/cmd/helm@${BINARY_HELM_VERSION})
18 changes: 18 additions & 0 deletions build/make/version-sha.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
##@ Version

# This makefile is used to get the sha256sum of a specific github tag-src.tar.gz or .zip.
# You may set any of the following variables before your make call to change the hash url.

SHA_SUM_ORGANISATION?="cloudogu"
SHA_SUM_REPOSITORY?="ecosystem"
SHA_SUM_FILE_TYPE?="tar.gz"
SHA_SUM_VERSION?="v20.04.4-2"
SHA_SUM_URL?="https://github.com/${SHA_SUM_ORGANISATION}/${SHA_SUM_REPOSITORY}/archive/refs/tags/${SHA_SUM_VERSION}.${SHA_SUM_FILE_TYPE}"

.PHONY: sha-sum
sha-sum: ## Print out the version
@echo "Downloading from: ${SHA_SUM_URL}"
@wget -O - -o /dev/null "${SHA_SUM_URL}" > .download.for.hash \
|| (echo "Could not be downloaded" && exit 1) \
&& cat .download.for.hash | sha256sum
@rm -f .download.for.hash
31 changes: 31 additions & 0 deletions k8s/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v2
name: k8s-host-change
description: "Apply changes to FQDN, internal IP and additional hosts in a K8s Cloudogu EcoSystem."

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.0-replaceme

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.0.0-replaceme"

dependencies:
# For k8s-etcd it is important to include "prerelease"-versions like "3.5.7-4", so there must be a "-0" after the patch-version.
# see https://helm.sh/docs/chart_best_practices/dependencies/#prerelease-versions for more information
- name: "k8s-etcd"
version: "^3.5.x-0"
condition: false

0 comments on commit e07ebde

Please sign in to comment.