Skip to content

Commit 807696a

Browse files
chore: migrate all files
1 parent 1f50b4b commit 807696a

26 files changed

+1850
-0
lines changed

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Use distroless as minimal base image to package the component binary
2+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
3+
FROM gcr.io/distroless/static-debian12:nonroot
4+
ARG TARGETOS
5+
ARG TARGETARCH
6+
ARG COMPONENT
7+
WORKDIR /
8+
COPY bin/$COMPONENT.$TARGETOS-$TARGETARCH /<component>
9+
USER 65532:65532
10+
11+
# docker doesn't substitue args in ENTRYPOINT, so we replace this during the build script
12+
ENTRYPOINT ["/<component>"]

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%:
2+
@echo "This repository uses task (https://taskfile.dev) instead of make."
3+
@echo "Run 'go install github.com/go-task/task/v3/cmd/task@latest' to install the latest version."
4+
@echo "Then run 'task -l' to list available tasks."

Taskfile_controller.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
version: 3
2+
3+
# This Taskfile is meant to be included for controller repos.
4+
# In addition to the library tasks, it contains tasks for building binaries and images.
5+
6+
run: once
7+
method: checksum
8+
9+
includes:
10+
lib:
11+
taskfile: Taskfile_library.yaml
12+
flatten: true
13+
build:
14+
taskfile: tasks_build.yaml
15+
aliases:
16+
- bld
17+
- b
18+
19+
tasks:
20+
21+
# The following tasks are non-namespaced aliases for the most important namespaced tasks.
22+
# This helps with visibility on 'task -l'.
23+
24+
all:
25+
desc: " Run code generation and validation, build all artifacts and push them to the respective registries."
26+
summary: This is an alias for 'build:all'.
27+
run: once
28+
deps:
29+
- build:all
30+
31+
build:
32+
desc: " Build the binaries. Includes code generation and validation."
33+
summary: This is an alias for 'build:bin:all'.
34+
run: once
35+
deps:
36+
- build:bin:all
37+
38+
build-raw:
39+
desc: " Like 'build', but skips code generation/validation tasks."
40+
summary: This is an alias for 'build:bin:build-multi-raw'.
41+
run: once
42+
deps:
43+
- build:bin:build-multi-raw
44+
45+
image:
46+
desc: " Build and push the images. Includes binary build."
47+
summary: This is an alias for 'build:img:all'.
48+
run: once
49+
deps:
50+
- build:img:all
51+
52+
helm:
53+
desc: " Package and push the helm charts."
54+
summary: This is an alias for 'build:helm:all'.
55+
aliases:
56+
- chart
57+
- helm-chart
58+
run: once
59+
deps:
60+
- build:helm:all
61+
62+
ocm:
63+
desc: " Build and push the OCM component."
64+
summary: This is an alias for 'build:ocm:all'.
65+
run: once
66+
deps:
67+
- build:ocm:all

Taskfile_library.yaml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
version: 3
2+
3+
# This Taskfile is meant to be included for library repos.
4+
# It contains tasks for code generation, validation, and release management.
5+
6+
run: once
7+
method: checksum
8+
9+
includes:
10+
generate:
11+
taskfile: tasks_gen.yaml
12+
aliases:
13+
- gen
14+
- g
15+
tools:
16+
taskfile: tasks_tools.yaml
17+
validate:
18+
taskfile: tasks_val.yaml
19+
aliases:
20+
- val
21+
- v
22+
release:
23+
taskfile: tasks_rls.yaml
24+
aliases:
25+
- rls
26+
- r
27+
28+
vars:
29+
# whacky workarounds for incorrect paths in the special variables
30+
# see https://github.com/go-task/task/issues/2056 and https://github.com/go-task/task/issues/2057
31+
ROOT_DIR2: '{{.ROOT_DIR | trimSuffix "/common" | trimSuffix "/hack"}}'
32+
TASKFILE_DIR2:
33+
sh: 'if [[ "{{.TASKFILE_DIR}}" == "{{.ROOT_DIR2}}" ]] || [[ "{{.TASKFILE_DIR}}" == "" ]]; then echo -n "{{.ROOT_DIR2}}/hack/common"; else echo -n "{{.TASKFILE_DIR}}"; fi'
34+
35+
VERSION:
36+
sh: 'PROJECT_ROOT="{{.ROOT_DIR2}}" {{.TASKFILE_DIR2}}/get-version.sh'
37+
OS:
38+
sh: echo ${OS:-$(go env GOOS)}
39+
ARCH:
40+
sh: echo ${ARCH:-$(go env GOARCH)}
41+
MODULE_NAME:
42+
sh: 'cat "{{.ROOT_DIR2}}/go.mod" | grep "module " | sed "s/module //" | sed -E "s/[[:blank:]].*//"'
43+
NESTED_MODULES: '{{.NESTED_MODULES | default "" }}'
44+
45+
LOCALBIN: '{{ .LOCALBIN | default (print .ROOT_DIR2 "/bin") }}'
46+
LOCALTMP: '{{ .LOCALTMP | default (print .ROOT_DIR2 "/tmp") }}'
47+
CONTROLLER_GEN: '{{ .CONTROLLER_GEN | default (print .LOCALBIN "/controller-gen") }}'
48+
CONTROLLER_GEN_VERSION: '{{ .CONTROLLER_GEN_VERSION | default "v0.16.4" }}'
49+
FORMATTER: '{{ .FORMATTER | default (print .LOCALBIN "/goimports") }}'
50+
FORMATTER_VERSION: '{{ .FORMATTER_VERSION | default "v0.26.0" }}'
51+
LINTER: '{{ .LINTER | default (print .LOCALBIN "/golangci-lint") }}'
52+
LINTER_VERSION: '{{ .LINTER_VERSION | default "v1.64.4" }}'
53+
JQ: '{{ .JQ | default (print .LOCALBIN "/jq") }}'
54+
JQ_VERSION: '{{ .JQ_VERSION | default "v1.7.1" }}'
55+
HELM: '{{ .HELM | default (print .LOCALBIN "/helm") }}'
56+
HELM_VERSION: '{{ .HELM_VERSION | default "v3.17.1" }}'
57+
YAML2JSON: '{{ .YAML2JSON | default (print .LOCALBIN "/yaml2json") }}'
58+
YAML2JSON_VERSION: '{{ .YAML2JSON_VERSION | default "v1.3.5" }}'
59+
OCM: '{{ .OCM | default (print .LOCALBIN "/ocm") }}'
60+
OCM_VERSION: '{{ .OCM_VERSION | default "v0.21.0" }}'
61+
62+
DOCKER_BUILDER_NAME: # move to build taskfile later
63+
sh: 'echo -n ${DOCKER_BUILDER_NAME:-"openmcp-multiarch-builder"}'
64+
65+
# separator strings
66+
SEP_MSG: "This is just a separator, what did you expect to happen?"
67+
MAIN_SEP: "MAIN ###########################################################################"
68+
GEN_SEP: "CODE GENERATION ### generate / gen / g #########################################"
69+
VAL_SEP: "CODE VALIDATION ### validate / val / v #########################################"
70+
BLD_SEP: "BUILD ARTIFACTS ### build / bld / b ############################################"
71+
BLD_BIN_SEP: "BINARY BUILD --- bin -----------------------------------------------------------"
72+
BLD_IMG_SEP: "IMAGE BUILD --- img ------------------------------------------------------------"
73+
BLD_HLM_SEP: "HELM CHART BUILD --- helm ------------------------------------------------------"
74+
BLD_OCM_SEP: "OCM COMPONENT BUILD --- ocm ----------------------------------------------------"
75+
RLS_SEP: "RELEASE MANAGEMENT ### release / rls / r #######################################"
76+
77+
tasks:
78+
79+
# This is a dummy task that serves as a separator between task namespaces in the 'task -l' output.
80+
"---":
81+
desc: "{{.MAIN_SEP}}"
82+
cmds:
83+
- cmd: echo "{{.SEP_MSG}}"
84+
silent: true
85+
86+
default: # This is executed if 'task' is called without any arguments.
87+
silent: true
88+
deps:
89+
- help
90+
91+
help:
92+
silent: true
93+
cmds:
94+
- cmd: task -l
95+
silent: true # for some reason, this is not needed here, but let's keep it for consistency
96+
97+
generate:
98+
desc: " Combines all code generation tasks, including formatting."
99+
run: once
100+
deps:
101+
- gen:generate
102+
103+
test:
104+
desc: " Run all tests."
105+
run: once
106+
deps:
107+
- val:test
108+
109+
validate:
110+
desc: " Combines all validation tasks except for tests."
111+
run: once
112+
aliases:
113+
- verify
114+
- check
115+
deps:
116+
- val:validate
117+
118+
version:
119+
desc: " Print the version of the project. Use VERSION_OVERRIDE to make this task print a specific version."
120+
run: once
121+
cmds:
122+
- cmd: 'echo "{{.VERSION}}"'
123+
silent: true
124+

components.yaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Usage:
2+
#
3+
# Feed arguments into ocm CLI like this:
4+
# ocm add componentversions ... -- CHART_REGISTRY=... IMG_REGISTRY=...
5+
#
6+
# Required values:
7+
# - VERSION (set via the ocm CLI's --version flag)
8+
# - Used as version for the source element pointing to this repo.
9+
# - Used as referenced GitHub release, if it does not contain a '-dev'.
10+
# - Used as fallback value for other versions.
11+
# - COMMIT
12+
# - Commit hash of the git commit used to generate this component descriptor.
13+
# - Used for the source element pointing to this repo.
14+
# - CHART_REGISTRY
15+
# - URL of the OCI registry used for the helm charts
16+
# - IMG_REGISTRY
17+
# - URL of the OCI registry used for the container images
18+
# - COMPONENTS
19+
# - Comma-separated list of components for which resources should be added to the component descriptor, e.g. "apiserver-controller,managedcontrolplane-controller,landscaper-connector".
20+
# - Not required if all of BP_COMPONENTS, CHART_COMPONENTS, and IMG_COMPONENTS are specified instead.
21+
# - MODULE_NAME
22+
# - Name of the Go module.
23+
# - REPO_URL
24+
# - URL of the git repository.
25+
#
26+
# Optional values:
27+
# - CD_VERSION
28+
# - Version used for the component descriptor.
29+
# - Defaults to VERSION if not specified.
30+
# - CHART_VERSION
31+
# - Default version for referenced helm charts.
32+
# - Defaults to VERSION if not specified.
33+
# - IMG_VERSION
34+
# - Default version for referenced container images.
35+
# - Defaults to VERSION if not specified.
36+
# - BP_PATH
37+
# - Path to the blueprint directory. Must be specified if BP_COMPONENTS is set.
38+
# - BP_COMPONENTS
39+
# - Comma-separated list of components for which the blueprint should be added to the component descriptor, e.g. "apiserver-controller,managedcontrolplane-controller,landscaper-connector"
40+
# - Each element will result in a resource entry of type 'landscaper.gardener.cloud/blueprint' named '<component>-blueprint'. The corresponding blueprint is expected at 'BP_PATH/<component>' (relative to this file).
41+
# - Defaults to COMPONENTS if BP_PATH is set and is empty otherwise.
42+
# - CHART_COMPONENTS
43+
# - Comma-separated list of components for which helm charts should be referenced in the component descriptor, optionally with version (separated by ":").
44+
# - Example: "apiserver-controller:v0.1.0,managedcontrolplane-controller:v0.2.0,landscaper-connector"
45+
# - Each element will result in a resource entry of type 'helmChart' named '<component>-chart'. The chart is expected in the OCI registry at '<CHART_REGISTRY>/<component>:<version>'.
46+
# - Defaults to COMPONENTS if not specified.
47+
# - Each chart's version defaults to CHART_VERSION if not specified.
48+
# - IMG_COMPONENTS
49+
# - Comma-separated list of components for which container images should be referenced in the component descriptor, optionally with version (separated by ":").
50+
# - Example: "apiserver-controller:v0.1.0,managedcontrolplane-controller:v0.2.0,landscaper-connector"
51+
# - Each element will result in a resource entry of type 'ociImage' named '<component>-image'. The image is expected in the OCI registry at '<IMG_REGISTRY>/<component>:<version>'.
52+
# - Defaults to COMPONENTS if not specified.
53+
# - Each image's version defaults to IMG_VERSION if not specified.
54+
55+
56+
name: (( lower(values.MODULE_NAME) ))
57+
version: (( defaults.CD_VERSION ))
58+
provider:
59+
name: sap.com
60+
61+
sources:
62+
- name: (( ( "tmp" = split("/", values.REPO_URL) ) element(tmp, length(tmp) - 1) ))
63+
type: blob
64+
version: (( values.VERSION ))
65+
access:
66+
type: gitHub
67+
repoUrl: (( values.REPO_URL ))
68+
commit: (( values.COMMIT ))
69+
ref: (( contains(values.VERSION, "-dev") ? ~~ :"refs/tags/" values.VERSION ))
70+
resources:
71+
- <<<: (( sum[funcs.splitIgnoreEmpty(",", defaults.BP_COMPONENTS)|[]|s,comp|-> s *templates.blueprint] ))
72+
- <<<: (( sum[funcs.splitIgnoreEmpty(",", defaults.CHART_COMPONENTS)|[]|s,cv|-> ("cvs" = split(":", cv)) ("comp" = cvs[0], "chart_version" = (cvs[1] || defaults.CHART_VERSION)) s *templates.chart] ))
73+
- <<<: (( sum[funcs.splitIgnoreEmpty(",", defaults.IMG_COMPONENTS)|[]|s,cv|-> ("cvs" = split(":", cv)) ("comp" = cvs[0], "img_version" = (cvs[1] || defaults.IMG_VERSION)) s *templates.image] ))
74+
75+
76+
# ##########################################################################
77+
# # Everything below this is temporary stuff only required during rendering and will not be part of the generated component descriptor.
78+
79+
defaults:
80+
<<<: (( &temporary ))
81+
CD_VERSION: (( funcs.notEmpty(values.CD_VERSION || "") ? values.CD_VERSION :values.VERSION ))
82+
CHART_VERSION: (( funcs.notEmpty(values.CHART_VERSION || "") ? values.CHART_VERSION :values.VERSION ))
83+
IMG_VERSION: (( funcs.notEmpty(values.IMG_VERSION || "") ? values.IMG_VERSION :values.VERSION ))
84+
BP_COMPONENTS: (( funcs.notEmpty(values.BP_PATH || "") ? ( funcs.notEmpty(values.BP_COMPONENTS || "") ? values.BP_COMPONENTS :values.COMPONENTS ) :"" ))
85+
CHART_COMPONENTS: (( funcs.notEmpty(values.CHART_COMPONENTS || "") ? values.CHART_COMPONENTS :values.COMPONENTS ))
86+
IMG_COMPONENTS: (( funcs.notEmpty(values.IMG_COMPONENTS || "") ? values.IMG_COMPONENTS :values.COMPONENTS ))
87+
88+
funcs:
89+
<<<: (( &temporary ))
90+
notEmpty: (( |x|-> x != "" )) # returns true if the input is not an empty string
91+
splitIgnoreEmpty: (( |d,s|-> select[split(d, s)|x|-> x != ""] )) # splits a string by a delimiter and removes empty elements
92+
93+
templates:
94+
<<<: (( &temporary ))
95+
blueprint:
96+
<<<: (( &template ))
97+
name: (( comp "-blueprint" ))
98+
type: landscaper.gardener.cloud/blueprint
99+
input:
100+
path: (( "../blueprints/" comp ))
101+
type: dir
102+
chart:
103+
<<<: (( &template ))
104+
name: (( comp "-chart" ))
105+
type: helmChart
106+
version: (( chart_version ))
107+
access:
108+
type: ociArtifact
109+
imageReference: (( values.CHART_REGISTRY "/" comp ":" chart_version ))
110+
image:
111+
<<<: (( &template ))
112+
name: (( comp "-image" ))
113+
type: ociImage
114+
version: (( img_version ))
115+
access:
116+
imageReference: (( values.IMG_REGISTRY "/" comp ":" img_version ))
117+
type: ociArtifact
118+
119+
120+

compute-next-release-version.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
source "$(realpath "$(dirname $0)/environment.sh")"
5+
6+
if [[ -z "${VERSION:-}" ]]; then
7+
VERSION=$("$COMMON_SCRIPT_DIR/get-version.sh")
8+
fi
9+
10+
semver=${1:-"minor"}
11+
12+
major=${VERSION%%.*}
13+
major=${major#v}
14+
minor=${VERSION#*.}
15+
minor=${minor%%.*}
16+
patch=${VERSION##*.}
17+
patch=${patch%%-*}
18+
19+
case "$semver" in
20+
("major")
21+
major=$((major + 1))
22+
minor=0
23+
patch=0
24+
;;
25+
("minor")
26+
minor=$((minor + 1))
27+
patch=0
28+
;;
29+
("patch")
30+
patch=$((patch + 1))
31+
;;
32+
(*)
33+
echo "invalid argument: $semver"
34+
exit 1
35+
;;
36+
esac
37+
38+
echo -n "v$major.$minor.$patch"

environment.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
export COMMON_SCRIPT_DIR="$(realpath "$(dirname ${BASH_SOURCE[0]})")"
4+
source "$COMMON_SCRIPT_DIR/lib.sh"
5+
export PROJECT_ROOT="${PROJECT_ROOT:-$(realpath "$COMMON_SCRIPT_DIR/../..")}"
6+
export COMPONENT_DEFINITION_FILE="${COMPONENT_DEFINITION_FILE:-"$PROJECT_ROOT/components/components.yaml"}"
7+
8+
if [[ -f "$COMMON_SCRIPT_DIR/../environment.sh" ]]; then
9+
source "$COMMON_SCRIPT_DIR/../environment.sh"
10+
fi

0 commit comments

Comments
 (0)