diff --git a/.github/workflows/e2e/scripts/hpo-install-helm-project-operator.sh b/.github/workflows/e2e/scripts/hpo-install-helm-project-operator.sh index 0a18845e..b3bff034 100755 --- a/.github/workflows/e2e/scripts/hpo-install-helm-project-operator.sh +++ b/.github/workflows/e2e/scripts/hpo-install-helm-project-operator.sh @@ -5,9 +5,13 @@ source $(dirname $0)/entry source $(dirname $0)/cluster-args.sh cd $(dirname $0)/../../../.. +source "$(pwd)/scripts/util-team-charts" -latest_chart=./packages/helm-project-operator/charts +NEWEST_CHART_VERSION=$(newest-chart-version "helm-project-operator") +fetch-team-chart "helm-project-operator" "$NEWEST_CHART_VERSION" +LATEST_CHART_PATH="./build/charts/helm-project-operator-${NEWEST_CHART_VERSION}.tgz" +tar -xvzf "$LATEST_CHART_PATH" -C ./build/charts/ -helm upgrade --install --create-namespace -n cattle-helm-system helm-project-operator --set image.registry='',image.repository=${REPO:-rancher}/helm-project-operator,image.tag=${TAG:-dev} ${cluster_args} ${RANCHER_HELM_ARGS} ${latest_chart} +helm upgrade --install --create-namespace -n cattle-helm-system helm-project-operator --set image.registry='',image.repository=${REPO:-rancher}/helm-project-operator,image.tag=${TAG:-dev} ${cluster_args} ${RANCHER_HELM_ARGS} ./build/charts/helm-project-operator echo "PASS: Helm Project Operator has been installed" diff --git a/.github/workflows/e2e/scripts/install-federator.sh b/.github/workflows/e2e/scripts/install-federator.sh index c3b29bc6..51510765 100755 --- a/.github/workflows/e2e/scripts/install-federator.sh +++ b/.github/workflows/e2e/scripts/install-federator.sh @@ -6,9 +6,13 @@ source $(dirname $0)/entry source $(dirname $0)/cluster-args.sh cd $(dirname $0)/../../../.. +source "$(pwd)/scripts/util-team-charts" -latest_chart=$(find ./charts/prometheus-federator -type d -maxdepth 1 -mindepth 1 | tr - \~ | sort -rV | tr \~ - | head -n1) +NEWEST_CHART_VERSION=$(newest-chart-version "prometheus-federator") +fetch-team-chart "prometheus-federator" "$NEWEST_CHART_VERSION" +LATEST_CHART_PATH="./build/charts/prometheus-federator-${NEWEST_CHART_VERSION}.tgz" +tar -xvzf "$LATEST_CHART_PATH" -C ./build/charts/ -helm upgrade --install --create-namespace -n cattle-monitoring-system prometheus-federator --set helmProjectOperator.image.repository=${REPO:-rancher}/prometheus-federator --set helmProjectOperator.image.tag=${TAG:-dev} ${cluster_args} ${RANCHER_HELM_ARGS} ${latest_chart} +helm upgrade --install --create-namespace -n cattle-monitoring-system prometheus-federator --set helmProjectOperator.image.repository=${REPO:-rancher}/prometheus-federator --set helmProjectOperator.image.tag=${TAG:-dev} ${cluster_args} ${RANCHER_HELM_ARGS} ./build/charts/prometheus-federator echo "PASS: Prometheus Federator has been installed" diff --git a/build.yaml b/build.yaml new file mode 100644 index 00000000..b2c5e549 --- /dev/null +++ b/build.yaml @@ -0,0 +1 @@ +rancherProjectMonitoringVersion: 0.3.4 \ No newline at end of file diff --git a/generate.go b/generate.go index 2b15f877..b90c2baf 100644 --- a/generate.go +++ b/generate.go @@ -1,3 +1,5 @@ +//go:generate go run pkg/codegen/buildconfig/writer.go pkg/codegen/buildconfig/main.go + //go:generate go run pkg/helm-locker/codegen/cleanup/main.go //go:generate go run pkg/helm-locker/codegen/main.go //go:generate go run ./pkg/helm-locker/codegen crds ./crds/helm-locker/crds.yaml diff --git a/go.mod b/go.mod index e4e12ebc..4b2b87c9 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,10 @@ require ( github.com/rancher/wrangler-cli v0.0.0-20211112052728-f172e9bf59af github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.4.0 + github.com/stretchr/testify v1.7.0 + golang.org/x/text v0.7.0 gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b helm.sh/helm/v3 v3.8.0 k8s.io/api v0.23.3 k8s.io/apiextensions-apiserver v0.23.1 @@ -60,6 +63,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.12.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect @@ -75,14 +79,12 @@ require ( golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect golang.org/x/sys v0.5.0 // indirect golang.org/x/term v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect golang.org/x/tools v0.1.12 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.27.1 // indirect gopkg.in/gorp.v1 v1.7.2 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect k8s.io/code-generator v0.23.3 // indirect k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c // indirect k8s.io/klog v1.0.0 // indirect diff --git a/pkg/buildconfig/constants.go b/pkg/buildconfig/constants.go new file mode 100644 index 00000000..6cb27939 --- /dev/null +++ b/pkg/buildconfig/constants.go @@ -0,0 +1,7 @@ +// Code generated by pkg/codegen/config/main.go. DO NOT EDIT. +// Package buildconfig contains a set of exported constants that represent configuration variables of Rancher at build-time. +package buildconfig + +const ( + RancherProjectMonitoringVersion = "0.3.4" +) diff --git a/pkg/codegen/buildconfig/main.go b/pkg/codegen/buildconfig/main.go new file mode 100644 index 00000000..4a4b3e24 --- /dev/null +++ b/pkg/codegen/buildconfig/main.go @@ -0,0 +1,44 @@ +// This program generates a Go file containing a set of exported constants that represent +// configuration variables of Rancher at build-time. +package main + +import ( + "fmt" + "os" + "text/template" +) + +func main() { + if err := generateGoConstantsFile(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +func generateGoConstantsFile() error { + in, err := os.OpenFile("build.yaml", os.O_RDONLY, 0644) + if err != nil { + return err + } + out, err := os.OpenFile("pkg/buildconfig/constants.go", os.O_TRUNC|os.O_WRONLY, 0644) + if err != nil { + return err + } + const raw = `// Code generated by pkg/codegen/config/main.go. DO NOT EDIT. +// Package buildconfig contains a set of exported constants that represent configuration variables of Rancher at build-time. +package buildconfig + +const ( +{{ . }}) +` + tmpl, err := template.New("").Parse(raw) + if err != nil { + return err + } + writer := GoConstantsWriter{ + Tmpl: tmpl, + Input: in, + Output: out, + } + return writer.Run() +} diff --git a/pkg/codegen/buildconfig/writer.go b/pkg/codegen/buildconfig/writer.go new file mode 100644 index 00000000..517f58b9 --- /dev/null +++ b/pkg/codegen/buildconfig/writer.go @@ -0,0 +1,97 @@ +package main + +import ( + "bytes" + "errors" + "fmt" + "go/format" + "io" + "sort" + "strings" + "text/template" + + "golang.org/x/text/cases" + "golang.org/x/text/language" + "gopkg.in/yaml.v3" +) + +type GoConstantsWriter struct { + Input io.Reader + Output io.Writer + Tmpl *template.Template + buf []byte + cfg map[string]string +} + +// Run loads YAML data from the pre-configured Input source, processes it, and outputs a template with formatted +// Go constants in the pre-configured Output source. This method can only be run once, since the Input source gets fully read. +func (f *GoConstantsWriter) Run() error { + if err := f.load(); err != nil { + return err + } + if err := f.process(); err != nil { + return err + } + if err := f.write(); err != nil { + return err + } + return nil +} + +func (f *GoConstantsWriter) load() error { + if f.Input == nil { + return errors.New("nil input") + } + b, err := io.ReadAll(f.Input) + if err != nil { + return fmt.Errorf("failed to read input: %w", err) + } + if len(b) == 0 { + return errors.New("nothing was read") + } + if err := yaml.Unmarshal(b, &f.cfg); err != nil { + return fmt.Errorf("failed to unmarshal raw YAML from input: %w", err) + } + return nil +} + +func (f *GoConstantsWriter) process() error { + if f.Tmpl == nil { + return errors.New("nil template") + } + // This sorts the keys alphabetically to process the map in a fixed order. + keys := make([]string, 0, len(f.cfg)) + for k := range f.cfg { + keys = append(keys, k) + } + sort.Strings(keys) + + capitalize := cases.Title(language.English, cases.NoLower) + var builder strings.Builder + for _, k := range keys { + v := f.cfg[k] + // Capitalize the key to make the constant exported in the generated Go file. + k = capitalize.String(k) + s := fmt.Sprintf("\t%s = %q\n", k, v) + builder.WriteString(s) + } + + buf := new(bytes.Buffer) + if err := f.Tmpl.Execute(buf, builder.String()); err != nil { + return err + } + f.buf = buf.Bytes() + return nil +} + +func (f *GoConstantsWriter) write() error { + if f.Output == nil { + return errors.New("nil output") + } + formatted, err := format.Source(f.buf) + if err != nil { + return err + } + _, err = f.Output.Write(formatted) + return err +} diff --git a/pkg/codegen/buildconfig/writer_test.go b/pkg/codegen/buildconfig/writer_test.go new file mode 100644 index 00000000..6fcf3021 --- /dev/null +++ b/pkg/codegen/buildconfig/writer_test.go @@ -0,0 +1,118 @@ +package main_test + +import ( + "bytes" + "io" + "testing" + "text/template" + + "github.com/stretchr/testify/require" + + mainpkg "github.com/rancher/prometheus-federator/pkg/codegen/buildconfig" +) + +func TestGoConstantsWriterRun(t *testing.T) { + t.Parallel() + const contents = `b: 3 +a: foo +c: 3.14` + in := bytes.NewBufferString(contents) + out := new(bytes.Buffer) + + const rawTemplate = ` + package buildconfig + + const ( + {{ . }}) + ` + tmpl, err := template.New("").Parse(rawTemplate) + require.NoError(t, err) + w := &mainpkg.GoConstantsWriter{ + Tmpl: tmpl, + Input: in, + Output: out, + } + require.NoError(t, w.Run()) + + want := + `package buildconfig + +const ( + A = "foo" + B = "3" + C = "3.14" +) +` + got := out.String() + require.Equal(t, want, got) + + // Running a second time with the same Input source must fail. + require.Error(t, w.Run()) +} + +func TestGoConstantsWriterFailsWithBadConfiguration(t *testing.T) { + t.Parallel() + const rawTemplate = ` + package buildconfig + + const ( + {{ . }}) + ` + tmpl, err := template.New("").Parse(rawTemplate) + require.NoError(t, err) + const contents = `a: foo +b: 3 +c: 3.14` + output := new(bytes.Buffer) + + tests := []struct { + name string + tmpl *template.Template + input io.Reader + output io.Writer + }{ + { + name: "nil template", + tmpl: nil, + input: bytes.NewBufferString(contents), + output: output, + }, + { + name: "empty template", + tmpl: template.New(""), + input: bytes.NewBufferString(contents), + output: output, + }, + { + name: "nil input", + tmpl: tmpl, + input: nil, + output: output, + }, + { + name: "empty input", + tmpl: tmpl, + input: bytes.NewBufferString(""), + output: output, + }, + { + name: "nil output", + tmpl: tmpl, + input: bytes.NewBufferString(contents), + output: nil, + }, + } + + for _, test := range tests { + test := test + t.Run(test.name, func(t *testing.T) { + t.Parallel() + w := mainpkg.GoConstantsWriter{ + Input: test.input, + Output: test.output, + Tmpl: test.tmpl, + } + require.Error(t, w.Run()) + }) + } +} diff --git a/scripts/build-chart b/scripts/build-chart index cff948b0..4561c373 100755 --- a/scripts/build-chart +++ b/scripts/build-chart @@ -1,8 +1,12 @@ #!/usr/bin/env bash set -e +# This actually prepares a chart for compile time embedding into the resulting binary. +# This is always required even after splitting charts and app code. + source $(dirname $0)/version source $(dirname $0)/util-chart +source $(dirname $0)/util-team-charts # We don't do this for helm-locker if [[ "${BUILD_TARGET}" == "helm-locker" ]]; then @@ -21,10 +25,12 @@ fi CHART=${CHART:-${DEFAULT_CHART_TARGET}} if [ "$BUILD_TARGET" == "prometheus-federator" ]; then - CHART_VERSION=${EMBEDDED_CHART_VERSION:-$(find "./charts/${CHART}" -maxdepth 1 -mindepth 1 -type d | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4)} + # Fetch asset from github OB charts repo + fetch-team-chart "rancher-project-monitoring" "$RANCHER_PROJECT_MONITORING" + CHART_DESTINATION="./build/charts/${CHART}-${CHART_VERSION}.tgz" # Prepare chart for embedding location - base64 -i "assets/${CHART}/${CHART}-${CHART_VERSION}.tgz" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64" + base64 -i "${CHART_DESTINATION}" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64" elif [ "$BUILD_TARGET" == "helm-project-operator" ]; then # Prepare base chart for build clean-old-chart "$CHART" @@ -38,4 +44,4 @@ elif [ "$BUILD_TARGET" == "helm-project-operator" ]; then base64 -i "./build/charts/${CHART}-${HELM_CHART_VERSION}.tgz" > "cmd/${BUILD_TARGET}/fs/${CHART}.tgz.base64" fi -echo "Completed ${CHART} (ver: ${HELM_CHART_VERSION:-"n/a"}) build process." \ No newline at end of file +echo "Completed ${CHART} (ver: ${HELM_CHART_VERSION:-"n/a"}) chart build process." \ No newline at end of file diff --git a/scripts/ci b/scripts/ci index 50e96f58..82ac19fd 100755 --- a/scripts/ci +++ b/scripts/ci @@ -7,7 +7,4 @@ cd $(dirname $0) ./test ./validate ./validate-ci -./validate-packages -./validate-chart -./validate-charts ./package diff --git a/scripts/package-helm b/scripts/package-helm index 69746733..8ef1b7ed 100755 --- a/scripts/package-helm +++ b/scripts/package-helm @@ -9,12 +9,14 @@ fi source "$(dirname "$0")/version" source "$(dirname "$0")/util-chart" +source "$(dirname "$0")/util-team-charts" # We don't do the full process for prometheus-federator if [[ "${BUILD_TARGET}" == "prometheus-federator" ]]; then - mkdir -p ./dist/artifacts/ - CHART_VERSION=${EMBEDDED_CHART_VERSION:-$(find "./charts/${BUILD_TARGET}" -maxdepth 1 -mindepth 1 -type d | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4)} - cp -a "./assets/${BUILD_TARGET}/${BUILD_TARGET}-${CHART_VERSION}.tgz" ./build/charts/ + # Fetch asset from github OB charts repo + fetch-team-chart "rancher-project-monitoring" "$RANCHER_PROJECT_MONITORING" + PROM_FED_CHART=$(newest-chart-version "prometheus-federator") + fetch-team-chart "prometheus-federator" "$PROM_FED_CHART" exit fi diff --git a/scripts/pull-scripts b/scripts/pull-scripts deleted file mode 100755 index eb4c3cd3..00000000 --- a/scripts/pull-scripts +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -set -e - -cd $(dirname $0) - -source ./version - -if ls ../bin/charts-build-scripts 1>/dev/null 2>/dev/null; then - CURRENT_SCRIPT_VERSION="v$(../bin/charts-build-scripts --version | cut -d' ' -f3)" - if [[ "${CURRENT_SCRIPT_VERSION}" == "${CHARTS_BUILD_SCRIPT_VERSION}" ]]; then - exit 0 - fi -fi - -echo "Downloading charts-build-scripts version ${CHARTS_BUILD_SCRIPTS_REPO}@${CHARTS_BUILD_SCRIPT_VERSION}" - -rm -rf ../bin -cd .. - -mkdir -p bin -OS=$(go version | cut -d' ' -f4 | cut -d'/' -f1) -ARCH=$(go version | cut -d' ' -f4 | cut -d'/' -f2) - -if [[ "$OS" == "windows" ]]; then - BINARY_NAME="charts-build-scripts_${OS}_${ARCH}.exe" -else - BINARY_NAME="charts-build-scripts_${OS}_${ARCH}" -fi -response_code=$(curl -s -o bin/charts-build-scripts -w "%{http_code}" -L "${CHARTS_BUILD_SCRIPTS_REPO%.git}/releases/download/${CHARTS_BUILD_SCRIPT_VERSION}/${BINARY_NAME}") - -# Fall back to binary name format from old release scheme -if ! [[ -f bin/charts-build-scripts ]] || [[ "$response_code" == "404" ]]; then - echo "Falling back to old binary name format..." - rm bin/charts-build-scripts; - if [[ ${OS} == "linux" ]]; then - BINARY_NAME=charts-build-scripts - else - BINARY_NAME=charts-build-scripts-${OS} - fi - response_code=$(curl -s -o bin/charts-build-scripts -w "%{http_code}" -L "${CHARTS_BUILD_SCRIPTS_REPO%.git}/releases/download/${CHARTS_BUILD_SCRIPT_VERSION}/${BINARY_NAME}") -fi - -# If falling back to old binary name format did not work, fail -if ! [[ -f bin/charts-build-scripts ]] || [[ "$response_code" == "404" ]]; then - echo "Failed to find charts-build-scripts binary" - rm bin/charts-build-scripts; - exit 1 -fi - -echo "${BINARY_NAME} => ./bin/charts-build-scripts" - -chmod +x ./bin/charts-build-scripts -./bin/charts-build-scripts --version \ No newline at end of file diff --git a/scripts/util-team-charts b/scripts/util-team-charts new file mode 100644 index 00000000..28480b8c --- /dev/null +++ b/scripts/util-team-charts @@ -0,0 +1,89 @@ +#!/usr/bin/env bash + +function fetch-team-charts-index() { + TEAM_INDEX="https://raw.githubusercontent.com/rancher/ob-team-charts/refs/heads/main/index.yaml" + BUILD_DIR="./build" + LOCAL_FILE="$BUILD_DIR/charts-index.yaml" + LOCAL_ETAG_FILE="$BUILD_DIR/charts-index.etag" + + # Ensure the build directory exists + mkdir -p "$BUILD_DIR" + + # Fetch the ETag from the remote file headers + REMOTE_ETAG=$(curl -sI "$TEAM_INDEX" | grep -i "etag" | awk '{print $2}' | tr -d '\r') + + if [[ -z "$REMOTE_ETAG" ]]; then + return 1 + fi + + # Check if a local ETag exists + if [[ -f "$LOCAL_ETAG_FILE" ]]; then + LOCAL_ETAG=$(cat "$LOCAL_ETAG_FILE") + # If the ETag matches, skip the download + if [[ "$REMOTE_ETAG" == "$LOCAL_ETAG" ]]; then + return 0 + fi + fi + + # Download the file as it is either outdated or does not exist + echo "Downloading file..." + if curl -s "$TEAM_INDEX" -o "$LOCAL_FILE"; then + # Save the new ETag + echo "$REMOTE_ETAG" > "$LOCAL_ETAG_FILE" + return 0 + else + return 1 + fi +} + +function newest-chart-version() { + LOCAL_INDEX_FILE="./build/charts-index.yaml" + # Fetch the latest index + fetch-team-charts-index >/dev/null + + CHART_TARGET=$1 + YQ_QUERY=".entries[\"${CHART_TARGET}\"][0].version" + NEWEST_CHART=$(yq "$YQ_QUERY" "$LOCAL_INDEX_FILE") + echo "$NEWEST_CHART" +} + +function fetch-team-chart() { + CHART_TARGET="${1}" + BASE_FETCH_URL="https://raw.githubusercontent.com/rancher/ob-team-charts/refs/heads/main/assets" + CHART_VERSION="${2}" + FETCH_URL="${BASE_FETCH_URL}/${CHART_TARGET}/${CHART_TARGET}-${CHART_VERSION}.tgz" + echo "Fetching version $CHART_VERSION of $CHART_TARGET" + BUILD_DIR="./build/charts" + mkdir -p "$BUILD_DIR" + LOCAL_FILE="$BUILD_DIR/${CHART_TARGET}-${CHART_VERSION}.tgz" + LOCAL_ETAG_FILE="$LOCAL_FILE.etag" + + # Ensure the build directory exists + mkdir -p "$BUILD_DIR" + + # Fetch the ETag from the remote file headers + REMOTE_ETAG=$(curl -sI "$FETCH_URL" | grep -i "etag" | awk '{print $2}' | tr -d '\r') + + if [[ -z "$REMOTE_ETAG" ]]; then + return 1 + fi + + # Check if a local ETag exists + if [[ -f "$LOCAL_ETAG_FILE" ]]; then + LOCAL_ETAG=$(cat "$LOCAL_ETAG_FILE") + # If the ETag matches, skip the download + if [[ "$REMOTE_ETAG" == "$LOCAL_ETAG" ]]; then + return 0 + fi + fi + + # Download the file as it is either outdated or does not exist + echo "Downloading file..." + if curl -s "$FETCH_URL" -o "$LOCAL_FILE"; then + # Save the new ETag + echo "$REMOTE_ETAG" > "$LOCAL_ETAG_FILE" + return 0 + else + return 1 + fi +} \ No newline at end of file diff --git a/scripts/validate-chart b/scripts/validate-chart deleted file mode 100755 index 490205ee..00000000 --- a/scripts/validate-chart +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -set -e - -# We only do this for prometheus-federator -if [[ "${BUILD_TARGET}" != "prometheus-federator" ]]; then - exit -fi - -cd $(dirname $0)/.. - -echo "Validating newest prometheus-federator chart" -CHART=prometheus-federator -VERSION=$(find ./charts/${CHART} -type d -maxdepth 1 -mindepth 1 | tr - \~ | sort -rV | tr \~ - | head -n1 | cut -d'/' -f4) - -app_version="$(yq e '.appVersion' charts/${CHART}/${VERSION}/Chart.yaml)" -image_tag="$(yq e '.helmProjectOperator.image.tag' charts/${CHART}/${VERSION}/values.yaml)" - -if [[ "${image_tag}" != "v${app_version}" ]]; then - echo "ERROR: .helmProjectOperator.image.tag in charts/${CHART}/${VERSION}/values.yaml (found: ${image_tag}) must match appVersion in charts/${CHART}/${VERSION}/Chart.yaml (found ${app_version})" - exit 1 -fi diff --git a/scripts/validate-charts b/scripts/validate-charts deleted file mode 100755 index 0ddd53fe..00000000 --- a/scripts/validate-charts +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -set -e - -cd $(dirname $0)/.. - -echo Running general chart validation - -./scripts/pull-scripts -./bin/charts-build-scripts validate --local \ No newline at end of file diff --git a/scripts/validate-packages b/scripts/validate-packages deleted file mode 100755 index 3d97f1a1..00000000 --- a/scripts/validate-packages +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash -set -e - -echo "Validating packages..." -cd $(dirname $0)/.. - -monitoring_pkg_path=packages/rancher-project-monitoring/package.yaml -monitoring_url="$(yq e '.url' ${monitoring_pkg_path})" -monitoring_subdirectory="$(yq e '.subdirectory' ${monitoring_pkg_path})" -monitoring_commit="$(yq e '.commit' ${monitoring_pkg_path})" - -grafana_pkg_path=packages/rancher-project-monitoring/generated-changes/dependencies/grafana/dependency.yaml -grafana_url="$(yq e '.url' ${grafana_pkg_path})" -grafana_subdirectory="$(yq e '.subdirectory' ${grafana_pkg_path})" -grafana_commit="$(yq e '.commit' ${grafana_pkg_path})" - -if [[ "${monitoring_url}" != "${grafana_url}" ]]; then - echo "ERROR: Expected .url in ${grafana_pkg_path} (found ${grafana_url}) to match .url in ${monitoring_pkg_path} (found ${monitoring_url})" - exit 1 -fi - -if [[ "${monitoring_subdirectory}/charts/grafana" != "${grafana_subdirectory}" ]]; then - echo "ERROR: Expected .subdirectory in ${grafana_pkg_path} (found ${grafana_subdirectory}) to be charts/grafana within the .subdirectory in ${monitoring_pkg_path} (found ${monitoring_subdirectory})" - exit 1 -fi - -if [[ "${monitoring_commit}" != "${grafana_commit}" ]]; then - echo "ERROR: Expected .commit in ${grafana_pkg_path} (found ${grafana_commit}) to match .commit in ${monitoring_pkg_path} (found ${monitoring_commit})" - exit 1 -fi - -echo "Completed validating packages" \ No newline at end of file diff --git a/scripts/version b/scripts/version index 73aa7a8c..769c023d 100755 --- a/scripts/version +++ b/scripts/version @@ -1,8 +1,5 @@ #!/usr/bin/env bash -CHARTS_BUILD_SCRIPTS_REPO=https://github.com/rancher/charts-build-scripts.git -CHARTS_BUILD_SCRIPT_VERSION=v0.9.2 - BUILD_TARGET=${BUILD_TARGET:-"prometheus-federator"} if [ -n "$(git status --porcelain --untracked-files=no)" ]; then @@ -42,6 +39,11 @@ if echo "$TAG" | grep -q dirty; then fi IMAGE=${IMAGE:-"$REPO/${BUILD_TARGET}:${TAG}"} +# Fetch build.yaml path and constant defined in it +ROOT_DIR=$(dirname "$(realpath "$(dirname "$0")")") +BUILD_YAML_PATH="$ROOT_DIR/build.yaml" +RANCHER_PROJECT_MONITORING=${RANCHER_PROJECT_MONITORING:-$(grep 'rancherProjectMonitoringVersion' "$BUILD_YAML_PATH"|cut -d: -f2|tr -d ' ')} + function print_version_debug() { echo "DIRTY: $DIRTY" echo "BUILD_TARGET: $BUILD_TARGET"; @@ -50,5 +52,7 @@ function print_version_debug() { echo "HELM_CHART_VERSION: $HELM_CHART_VERSION"; echo "REPO: $REPO; TAG: $TAG"; echo "IMAGE: $IMAGE"; + echo "BUILD_YAML_PATH: $BUILD_YAML_PATH" + echo "RANCHER PROJECT MONITORING: $RANCHER_PROJECT_MONITORING" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then print_version_debug "$1"; fi \ No newline at end of file