Skip to content

Commit

Permalink
Merge branch 'release/v0.3.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jelemux authored and cesmarvin committed Dec 7, 2023
2 parents ece8bb4 + 42e85f0 commit 29f2304
Show file tree
Hide file tree
Showing 29 changed files with 1,142 additions and 362 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.3.1] - 2023-12-07
### Added
- [#9] Add component patch templates used for airgapped environments.
- [#9] Update makefiles to 9.0.1 and hold all yaml resources in a single helm chart.

## [v0.3.0] - 2023-09-15
### Changed
- [#7] Move component-dependencies to helm-annotations
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.3.0"
VERSION="0.3.1"

WORKDIR /

Expand Down
78 changes: 29 additions & 49 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.66.0')
@Library('github.com/cloudogu/ces-build-lib@1.68.0')
import com.cloudogu.ces.cesbuildlib.*

// Creating necessary git objects
Expand All @@ -12,7 +12,8 @@ github = new GitHub(this, git)
changelog = new Changelog(this)
Docker docker = new Docker(this)
gpg = new Gpg(this, docker)
goVersion = "1.20"
goVersion = "1.21"
makefile = new Makefile(this)

// Configuration of repository
repositoryOwner = "cloudogu"
Expand All @@ -26,6 +27,9 @@ productionReleaseBranch = "main"
developmentBranch = "develop"
currentBranch = "${env.BRANCH_NAME}"

helmTargetDir = "target/k8s"
helmChartDir = "${helmTargetDir}/helm"

node('docker') {
timestamps {
stage('Checkout') {
Expand Down Expand Up @@ -59,11 +63,16 @@ node('docker') {
stage("Review dog analysis") {
stageStaticAnalysisReviewDog()
}
}

stage("Lint k8s Resources") {
stageLintK8SResources()
}
stage('Generate k8s Resources') {
make 'helm-generate'
archiveArtifacts "${helmTargetDir}/**/*"
}

stage("Lint helm") {
make 'helm-lint'
}
}

stage('SonarQube') {
stageStaticAnalysisSonarQube()
Expand All @@ -82,16 +91,6 @@ void gitWithCredentials(String command) {
}
}

void stageLintK8SResources() {
String kubevalImage = "cytopia/kubeval:0.13"
docker
.image(kubevalImage)
.inside("-v ${WORKSPACE}/k8s:/data -t --entrypoint=")
{
sh "kubeval /data/${repositoryName}.yaml --ignore-missing-schemas"
}
}

void stageStaticAnalysisReviewDog() {
def commitSha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()

Expand Down Expand Up @@ -137,7 +136,6 @@ void stageAutomaticRelease() {
if (gitflow.isReleaseBranch()) {
String releaseVersion = git.getSimpleBranchName()
String dockerReleaseVersion = releaseVersion.split("v")[1]
Makefile makefile = new Makefile(this)
String controllerVersion = makefile.getVersion()

stage('Build & Push Image') {
Expand All @@ -151,40 +149,22 @@ void stageAutomaticRelease() {
gitflow.finishRelease(releaseVersion, productionReleaseBranch)
}

stage('Sign after Release') {
gpg.createSignature()
}

stage('Regenerate resources for release') {
new Docker(this)
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/go/src/${project} -w /go/src/${project}")
{
make 'k8s-create-temporary-resource'
}
}

stage('Push to Registry') {
GString targetOperatorResourceYaml = "target/make/k8s/${repositoryName}_${controllerVersion}.yaml"
stage('Push Helm chart to Harbor') {
docker
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/go/src/${project} -w /go/src/${project}") {
// Package operator-chart & crd-chart
make 'helm-package'
archiveArtifacts "${helmTargetDir}/**/*"

DoguRegistry registry = new DoguRegistry(this)
registry.pushK8sYaml(targetOperatorResourceYaml, repositoryName, "k8s", "${controllerVersion}")
}
// Push charts
withCredentials([usernamePassword(credentialsId: 'harborhelmchartpush', usernameVariable: 'HARBOR_USERNAME', passwordVariable: 'HARBOR_PASSWORD')]) {
sh ".bin/helm registry login ${registry} --username '${HARBOR_USERNAME}' --password '${HARBOR_PASSWORD}'"

stage('Push Helm chart to Harbor') {
new Docker(this)
.image("golang:${goVersion}")
.mountJenkinsUser()
.inside("--volume ${WORKSPACE}:/go/src/${project} -w /go/src/${project}")
{
make '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}/"
}
}
sh ".bin/helm push ${helmChartDir}/${repositoryName}-${controllerVersion}.tgz oci://${registry}/${registry_namespace}/"
}
}
}

stage('Add Github-Release') {
Expand Down
65 changes: 38 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Set these to the desired values
ARTIFACT_ID=k8s-host-change
VERSION=0.3.0
VERSION=0.3.1

GOTAG?=1.20.2
MAKEFILES_VERSION=8.0.0
MAKEFILES_VERSION=9.0.1

## Image URL to use all building/pushing image targets
IMAGE_DEV=${K3CES_REGISTRY_URL_PREFIX}/${ARTIFACT_ID}:${VERSION}
IMAGE=cloudogu/${ARTIFACT_ID}:${VERSION}

K8S_RESOURCE_DIR=${WORKDIR}/k8s
Expand All @@ -32,19 +30,20 @@ include build/make/clean.mk
include build/make/digital-signature.mk
include build/make/mocks.mk

K8S_POST_GENERATE_TARGETS=k8s-generate-job-resource
K8S_COMPONENT_SOURCE_VALUES = ${HELM_SOURCE_DIR}/values.yaml
K8S_COMPONENT_TARGET_VALUES = ${HELM_TARGET_DIR}/values.yaml
HELM_PRE_APPLY_TARGETS=template-stage template-log-level template-image-pull-policy
HELM_PRE_GENERATE_TARGETS = helm-values-update-image-version
HELM_POST_GENERATE_TARGETS = helm-values-replace-image-repo
CHECK_VAR_TARGETS=check-all-vars
IMAGE_IMPORT_TARGET=image-import

include build/make/k8s-component.mk

##@ EcoSystem

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

.PHONY: k8s-generate-job-resource
k8s-generate-job-resource: ${BINARY_YQ} $(K8S_RESOURCE_TEMP_FOLDER) template-dev-only-image-pull-policy template-stage template-log-level ## Generates the final resource yaml.
@echo "Applying image transformation..."
@$(BINARY_YQ) -i e "(select(.kind == \"Job\").spec.template.spec.containers[]|select(.image == \"*$(ARTIFACT_ID)*\").image)=\"$(IMAGE_DEV)\"" $(K8S_RESOURCE_TEMP_YAML)
@echo "Done."
build: helm-delete image-import helm-apply ## Builds a new version of the setup and deploys it into the K8s-EcoSystem.

##@ Build

Expand All @@ -55,26 +54,38 @@ build-setup: ${SRC} compile ## Builds the setup Go binary.
run: ## Run a setup from your host.
go run ./main.go

.PHONY: k8s-create-temporary-resource
k8s-create-temporary-resource: $(K8S_RESOURCE_TEMP_FOLDER)
@cp $(K8S_HOST_CHANGE_RESOURCE_YAML) $(K8S_RESOURCE_TEMP_YAML)
@sed -i "s/'{{ .Version }}'/$(VERSION)/" $(K8S_RESOURCE_TEMP_YAML)
.PHONY: helm-values-update-image-version
helm-values-update-image-version: $(BINARY_YQ)
@echo "Updating the image version in source values.yaml to ${VERSION}..."
@$(BINARY_YQ) -i e ".job.image.tag = \"${VERSION}\"" ${K8S_COMPONENT_SOURCE_VALUES}

.PHONY: template-dev-only-image-pull-policy
template-dev-only-image-pull-policy: $(BINARY_YQ)
@if [ ${STAGE}"X" = "development""X" ]; \
then echo "Setting pull policy to always for development stage!" && $(BINARY_YQ) -i e "(select(.kind == \"Job\").spec.template.spec.containers[]|select(.image == \"*$(ARTIFACT_ID)*\").imagePullPolicy)=\"Always\"" $(K8S_RESOURCE_TEMP_YAML); \
fi
.PHONY: helm-values-replace-image-repo
helm-values-replace-image-repo: $(BINARY_YQ)
@if [[ ${STAGE} == "development" ]]; then \
echo "Setting dev image repo in target values.yaml!" ;\
$(BINARY_YQ) -i e ".job.image.repository=\"${IMAGE_DEV}\"" "${K8S_COMPONENT_TARGET_VALUES}" ;\
fi

.PHONY: template-stage
template-stage:
@echo "Setting STAGE env in deployment to ${STAGE}!"
@$(BINARY_YQ) -i e "(select(.kind == \"Deployment\").spec.template.spec.containers[]|select(.image == \"*$(ARTIFACT_ID)*\").env[]|select(.name==\"STAGE\").value)=\"${STAGE}\"" $(K8S_RESOURCE_TEMP_YAML)
template-stage: $(BINARY_YQ)
@if [[ ${STAGE} == "development" ]]; then \
echo "Setting STAGE env in deployment to ${STAGE}!" ;\
$(BINARY_YQ) -i e ".job.env.stage=\"${STAGE}\"" ${K8S_COMPONENT_TARGET_VALUES} ;\
fi

.PHONY: template-log-level
template-log-level:
@echo "Setting LOG_LEVEL env in deployment to ${LOG_LEVEL}!"
@$(BINARY_YQ) -i e "(select(.kind == \"Deployment\").spec.template.spec.containers[]|select(.image == \"*$(ARTIFACT_ID)*\").env[]|select(.name==\"LOG_LEVEL\").value)=\"${LOG_LEVEL}\"" $(K8S_RESOURCE_TEMP_YAML)
template-log-level: ${BINARY_YQ}
@if [[ "${STAGE}" == "development" ]]; then \
echo "Setting LOG_LEVEL env in deployment to ${LOG_LEVEL}!" ; \
$(BINARY_YQ) -i e ".job.env.logLevel=\"${LOG_LEVEL}\"" "${K8S_COMPONENT_TARGET_VALUES}" ; \
fi

.PHONY: template-image-pull-policy
template-image-pull-policy: $(BINARY_YQ)
@if [[ "${STAGE}" == "development" ]]; then \
echo "Setting pull policy to always!" ; \
$(BINARY_YQ) -i e ".job.imagePullPolicy=\"Always\"" "${K8S_COMPONENT_TARGET_VALUES}" ; \
fi

##@ Release

Expand Down
2 changes: 1 addition & 1 deletion build/make/bats/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ ARG BATS_TAG
FROM ${BATS_BASE_IMAGE}:${BATS_TAG}

# Make bash more findable by scripts and tests
RUN apk add make git bash
RUN apk add make git bash
Loading

0 comments on commit 29f2304

Please sign in to comment.