Skip to content

Commit

Permalink
Rework pipeline and surrounding scripts (#13)
Browse files Browse the repository at this point in the history
* restructure pipeline and surrounding scripting

* add blueprint to component
  • Loading branch information
Diaphteiros authored Feb 13, 2024
1 parent 0242090 commit 4d0a1f1
Show file tree
Hide file tree
Showing 40 changed files with 821 additions and 267 deletions.
51 changes: 51 additions & 0 deletions .ci/component
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash -eu

PROJECT_ROOT="$(dirname $(realpath $0))/.."
if [[ -z ${LOCALBIN:-} ]]; then
LOCALBIN="$PROJECT_ROOT/bin"
fi
if [[ -z ${HELM:-} ]]; then
HELM="$LOCALBIN/helm"
fi

"$PROJECT_ROOT/.ci/ensure-make"

(
cd "${PROJECT_ROOT}"

echo "Run 'make helm' ..."
make helm

echo "Fetch registry credentials ..."
creds="$(cli.py config attribute --cfg-type container_registry --cfg-name laas-component-descriptor-pipeline --key password)"

echo "Authenticate helm against artifact registry ..."
"$HELM" registry login -u _json_key --password-stdin https://europe-docker.pkg.dev <<< "$creds"

echo "Run 'make helm-chart' ..."
make helm-chart

echo "Authenticate docker against artifact registry ..."
docker login -u _json_key --password-stdin https://europe-docker.pkg.dev <<< "$creds"

echo "Create OCM config ..."
cat << EOF > "$HOME/.ocmconfig"
type: generic.config.ocm.software/v1
configurations:
- type: credentials.config.ocm.software
repositories:
- repository:
type: DockerConfig/v1
dockerConfigFile: "~/.docker/config.json"
propagateConsumerIdentity: true
EOF

echo "Run 'make component-build' ..."
make component-build
echo "Component successfully built."

echo "Run 'make component-push' ..."
export OVERWRITE_COMPONENTS="true"
make component-push
echo "Component successfully pushed."
)
47 changes: 22 additions & 25 deletions .ci/component_descriptor
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
#!/usr/bin/env python3
#!/bin/bash -eu

from pathlib import Path
import os
import yaml
# creates a dummy component descriptor

project_root = Path(__file__).parent.parent
in_path = os.getenv("BASE_DEFINITION_PATH")
out_path = os.getenv("COMPONENT_DESCRIPTOR_PATH")
version = os.getenv("EFFECTIVE_VERSION")
PROJECT_ROOT="$(dirname $(realpath $0))/.."
HACK_DIR="$PROJECT_ROOT/hack"

def read_data(path: str) -> str:
with open(path, "r") as file:
return file.read()
VERSION="$($HACK_DIR/get-version.sh)"
COMPONENT_REGISTRY="$($HACK_DIR/get-registry.sh --component)"

cd = yaml.safe_load(read_data(in_path))
cd["component"]["resources"].append({
"name": "chart",
"type": "helmChart",
"version": version,
"input": {
"type": "helm",
"path": str(project_root.joinpath("charts", "k8syncer")),
"repository": "/charts"
}
})

with open(out_path, "w") as file:
yaml.safe_dump(cd, stream=file, default_flow_style=False)
cat << EOF > "$COMPONENT_DESCRIPTOR_PATH"
component:
componentReferences: []
name: github.com/gardener/dummy
provider: sap.com
repositoryContexts:
- baseUrl: ${COMPONENT_REGISTRY%%/*}
componentNameMapping: urlPath
subPath: ${COMPONENT_REGISTRY#*/}
type: OCIRegistry
resources: []
sources: []
version: v0.0.0-dummy
meta:
schemaVersion: v2
EOF
6 changes: 6 additions & 0 deletions .ci/ensure-make
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -eu

if ! which make 1>/dev/null; then
echo "> Installing make ..."
apk add make 1>/dev/null
fi
18 changes: 18 additions & 0 deletions .ci/image
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -eu

PROJECT_ROOT="$(dirname $(realpath $0))/.."
COMPONENT_NAME="k8syncer"
IMAGE_REPO="$($PROJECT_ROOT/hack/get-registry.sh --image)/${COMPONENT_NAME}"

"${PROJECT_ROOT}/.ci/prepare-docker"
"${PROJECT_ROOT}/.ci/ensure-make"

(
cd "${PROJECT_ROOT}"
if [[ "$EFFECTIVE_VERSION" == *dev* ]]; then
export ADDITIONAL_TAG="dev-$EFFECTIVE_VERSION"
else
export ADDITIONAL_TAG="latest"
fi
make docker-buildx
)
24 changes: 13 additions & 11 deletions .ci/pipeline_definitions
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: Apache-2.0

k8syncer:
template: 'default'
base_definition:
repo: ~

Expand All @@ -13,22 +12,26 @@ k8syncer:
inject_effective_version: true
component_descriptor:
upload: no-upload
publish:
dockerimages:
k8syncer:
registry: 'gcr-readwrite'
target: 'k8syncer'
image: 'eu.gcr.io/gardener-project/k8syncer'
tag_as_latest: true

steps:
verify:
image: 'golang:1.21'
image:
privilege_mode: privileged
trait_depends:
- version
depends:
- verify
component:
trait_depends:
- version
depends:
- verify
- image

jobs:
head-update:
traits:
draft_release: ~
notifications:
default:
on_error:
Expand All @@ -49,5 +52,4 @@ k8syncer:
nextversion: 'bump_minor'
release_callback: '.ci/update-version'
next_version_callback: '.ci/update-version'
git_tags:
- ref_template: 'refs/tags/{VERSION}'
release_notes_policy: disabled
12 changes: 12 additions & 0 deletions .ci/prepare-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -eu

PROJECT_ROOT="$(dirname $(realpath $0))/.."
COMPONENT_NAME="k8syncer"
IMAGE_PREFIX="$($PROJECT_ROOT/hack/get-registry.sh)/${COMPONENT_NAME}"

# start docker daemon
launch-dockerd.sh

# configure credentials
mkdir -p "$HOME/.docker"
gardener-ci docker cfg --image "$IMAGE_PREFIX" > $HOME/.docker/config.json
10 changes: 5 additions & 5 deletions .ci/update-version
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/bin/bash -eu
#
# SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

PROJECT_ROOT="$(dirname $(realpath $0))/.."
COMPONENT_NAME="k8syncer"
IMAGE_REPO="$($PROJECT_ROOT/hack/get-registry.sh --image)/${COMPONENT_NAME}"

CHART_FILE="${PROJECT_ROOT}/charts/${COMPONENT_NAME}/Chart.yaml"
CHART_VALUES_FILE="${PROJECT_ROOT}/charts/${COMPONENT_NAME}/values.yaml"

# update VERSION file
echo "$EFFECTIVE_VERSION" > "$PROJECT_ROOT/VERSION"
echo -n "$EFFECTIVE_VERSION" > "$PROJECT_ROOT/VERSION"

# update version and image tag in helm chart
sed -E -i -e "s@version: [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+.*@version: $EFFECTIVE_VERSION@1" "${CHART_FILE}"
sed -i -e "s@ tag: .*@ tag: ${EFFECTIVE_VERSION}@" "${CHART_VALUES_FILE}"

# update image registry in helm chart (usually doesn't change, but is easily forgotten if it does)
sed -i -e "s@ repository: .*@ repository: ${IMAGE_REPO}@" "${CHART_VALUES_FILE}"

# remove backup files (created by sed on MacOS)
for file in "${CHART_FILE}" "${CHART_VALUES_FILE}"; do
rm -f "${file}-e"
Expand Down
21 changes: 7 additions & 14 deletions .ci/verify
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#!/bin/bash
#!/bin/bash -eu

# SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
PROJECT_ROOT="$(dirname $(realpath $0))/.."
(
cd "${PROJECT_ROOT}"

set -o errexit
set -o nounset
set -o pipefail

cd "$(dirname $0)/.."

make install-requirements

make verify
make test
make verify
make test
)
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ coverage.*
.vscode
.DS_Store

tmp
tmp/
bin/
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ run:
deadline: 10m
go: '1.21'

skip-files:
- "tmp/.*"

issues:
exclude:
- "Error return value of `.(.*)..Append` is not checked"
Loading

0 comments on commit 4d0a1f1

Please sign in to comment.