diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 93110a4d189..4f02604b76b 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -32,8 +32,13 @@ RUN if [ "${ARCH}" == "amd64" ]; then \ curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/spectrometer/master/install.sh | sh; \ fi -# install controller-tools for crd generation -RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.12.0 +# Tool for CRD generation. +ENV CONTROLLER_GEN_VERSION v0.12.0 +RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION} + +# YAML processor for release configuration. +ENV YQ_VERSION v4.40.2 +RUN wget -q https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${ARCH}.tar.gz -O - | tar xz && mv yq_linux_${ARCH} /usr/bin/yq ENV HELM_URL_V2_amd64=https://github.com/rancher/helm/releases/download/${CATTLE_HELM_VERSION}/rancher-helm \ HELM_URL_V2_arm64=https://github.com/rancher/helm/releases/download/${CATTLE_HELM_VERSION}/rancher-helm-arm64 \ diff --git a/README-template.md b/README-template.md index b2dfeb0a6d7..ea09f0e705b 100644 --- a/README-template.md +++ b/README-template.md @@ -39,6 +39,10 @@ This repo is a meta-repo used for packaging and contains the majority of Rancher Rancher also includes other open source libraries and projects, [see go.mod](https://github.com/rancher/rancher/blob/release/v2.8/go.mod) for the full list. +## Build configuration + +Refer to the [build docs](docs/build.md) on how to customize the building and packaging of Rancher. + ## Support, Discussion, and Community If you need any help with Rancher, please join us at either our [Rancher forums](http://forums.rancher.com/) or [Slack](https://slack.rancher.io/) where most of our team hangs out at. diff --git a/build.yaml b/build.yaml new file mode 100644 index 00000000000..992b31c3b4d --- /dev/null +++ b/build.yaml @@ -0,0 +1,4 @@ +webhookVersion: 103.0.1+up0.4.2 +cspAdapterMinVersion: 103.0.0+up3.0.0 +defaultShellVersion: rancher/shell:v0.1.22 +fleetVersion: 103.1.0+up0.9.0 diff --git a/dev-scripts/build-local.sh b/dev-scripts/build-local.sh index 9e64f9db1c0..e5778b49814 100755 --- a/dev-scripts/build-local.sh +++ b/dev-scripts/build-local.sh @@ -7,6 +7,7 @@ set -eo pipefail set -x SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)" +source "$SCRIPT_DIR/../scripts/export-config" TARGET_OS="${TARGET_OS:-linux}" GO_BINARY="${GO_BINARY:-$(which go)}" @@ -56,4 +57,9 @@ cp "${K3S_AIRGAP_IMAGES_TARBALL}" "${PACKAGE_FOLDER}" DOCKERFILE="${SCRIPT_DIR}/../package/Dockerfile" # Always use buildx to make sure the image & the binary architectures match -docker buildx build -t "${TARGET_REPO}" -f "${DOCKERFILE}" "${PACKAGE_FOLDER}" --platform="${TARGET_OS}/${TARGET_ARCH}" +docker buildx build -t "${TARGET_REPO}" -f "${DOCKERFILE}" \ + --build-arg CATTLE_RANCHER_WEBHOOK_VERSION="${CATTLE_RANCHER_WEBHOOK_VERSION}" \ + --build-arg CATTLE_CSP_ADAPTER_MIN_VERSION="${CATTLE_CSP_ADAPTER_MIN_VERSION}" \ + --build-arg CATTLE_FLEET_VERSION="${CATTLE_FLEET_VERSION}" \ + --build-arg ARCH="${TARGET_ARCH}" \ + "${PACKAGE_FOLDER}" --platform="${TARGET_OS}/${TARGET_ARCH}" diff --git a/docs/build.md b/docs/build.md new file mode 100644 index 00000000000..eb3c964b8be --- /dev/null +++ b/docs/build.md @@ -0,0 +1,69 @@ +## Build and package configuration + +Build variables should be defined in a single file, +so that anyone who wants to build Rancher needs to only edit this file to change configuration and dependency versions. + +Rancher relies on various subcomponents, such as the webhook. +These typically need to have set versions for Rancher to build and run properly. +Build variables can be used in different places and supplied to the applications in a variety of ways, +including as environment variables in Dockerfiles, constants in Go code, and so on. + +The [build.yaml](../build.yaml) file is the single source of truth. It lists all values by name and value. +Changes to it should be committed to source control. + +### Update an existing value + +Edit the [build.yaml](../build.yaml) file and update the desired value. Run `go generate`. Commit any changes to source +control. To test locally, re-build Rancher with `make build` or re-package it with `make package`. + +### Add a new value + +To add a new value, do the following once. + +Add it to [build.yaml](../build.yaml). For example: + +``` +webhookVersion: 2.0.6+up0.3.6-rc1 +``` + +Then update the [export-config](../scripts/export-config) script. + +``` +CATTLE_RANCHER_WEBHOOK_VERSION=$(yq -e '.webhookVersion' "$file") +export CATTLE_RANCHER_WEBHOOK_VERSION +``` + +Run `go generate` from the root of the repo. + +Now you can refer to the value wherever you need it. + +#### Refer to the new value + +If a new configuration value is an environment variable for a Dockerfile, capture it as an `ARG` and `ENV`. For example: + +``` +ARG CATTLE_FLEET_VERSION +ENV CATTLE_FLEET_VERSION=$CATTLE_FLEET_VERSION +``` + +Then pass it as via `docker build --build-arg MYVAR="$MYVAR" ...` + +If a new configuration value is a regular string outside Dockerfiles, refer to the corresponding constant found in the +generated Go [file](../pkg/buildconfig/constants.go). For example: + +```NewSetting("shell-image", buildconfig.DefaultShellVersion)``` + +The following are examples of files that often refer to newly added configuration values: + +- [build-server](../scripts/build-server) +- [build-agent](../scripts/build-agent) +- [build-local.sh](../dev-scripts/build-local.sh) +- [Dockerfile](../package/Dockerfile) +- [Dockerfile.agent](../package/Dockerfile.agent) +- [pkg/settings/setting.go](../pkg/settings/setting.go) + +### The build.yaml file + +It's better to follow the standard Kubernetes convention of preferring camelCase keys in the YAML file. + +The exported resulting environment variables should be like standard ENV_VARS. \ No newline at end of file diff --git a/generate.go b/generate.go index 4f61407f545..6e986ab5223 100644 --- a/generate.go +++ b/generate.go @@ -1,3 +1,4 @@ +//go:generate go run pkg/codegen/buildconfig/writer.go pkg/codegen/buildconfig/main.go //go:generate go run pkg/codegen/generator/cleanup/main.go //go:generate go run pkg/codegen/main.go //go:generate scripts/build-crds diff --git a/go.mod b/go.mod index e2075588e05..c67a23d6361 100644 --- a/go.mod +++ b/go.mod @@ -137,7 +137,7 @@ require ( golang.org/x/net v0.14.0 golang.org/x/oauth2 v0.11.0 golang.org/x/sync v0.3.0 - golang.org/x/text v0.12.0 // indirect + golang.org/x/text v0.12.0 golang.org/x/tools v0.12.0 // indirect google.golang.org/api v0.138.0 google.golang.org/grpc v1.57.0 @@ -402,7 +402,7 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect + gopkg.in/yaml.v3 v3.0.1 k8s.io/cluster-bootstrap v0.27.2 // indirect k8s.io/code-generator v0.27.5 // indirect k8s.io/component-base v0.27.6 // indirect diff --git a/package/Dockerfile b/package/Dockerfile index 386ba47e845..ee65773acad 100644 --- a/package/Dockerfile +++ b/package/Dockerfile @@ -57,9 +57,12 @@ ENV CATTLE_SYSTEM_UPGRADE_CONTROLLER_CHART_VERSION 103.0.0+up0.6.0 # System charts minimal version # Deprecated in favor of CATTLE_FLEET_VERSION. ENV CATTLE_FLEET_MIN_VERSION="" -ENV CATTLE_FLEET_VERSION=103.1.0+up0.9.0 -ENV CATTLE_RANCHER_WEBHOOK_VERSION=103.0.1+up0.4.2 -ENV CATTLE_CSP_ADAPTER_MIN_VERSION=103.0.0+up3.0.0 +ARG CATTLE_FLEET_VERSION +ENV CATTLE_FLEET_VERSION=$CATTLE_FLEET_VERSION +ARG CATTLE_RANCHER_WEBHOOK_VERSION +ENV CATTLE_RANCHER_WEBHOOK_VERSION=$CATTLE_RANCHER_WEBHOOK_VERSION +ARG CATTLE_CSP_ADAPTER_MIN_VERSION +ENV CATTLE_CSP_ADAPTER_MIN_VERSION=$CATTLE_CSP_ADAPTER_MIN_VERSION RUN mkdir -p /var/lib/rancher-data/local-catalogs/system-library && \ mkdir -p /var/lib/rancher-data/local-catalogs/library && \ diff --git a/package/Dockerfile.agent b/package/Dockerfile.agent index 620113849da..b9716801c7a 100644 --- a/package/Dockerfile.agent +++ b/package/Dockerfile.agent @@ -20,7 +20,8 @@ ARG VERSION=dev LABEL io.cattle.agent true ENV AGENT_IMAGE rancher/rancher-agent:${VERSION} # For now, this value needs to be manually synced with the one in the main Dockerfile. This pins downstream webhook's version. -ENV CATTLE_RANCHER_WEBHOOK_VERSION=103.0.1+up0.4.2 +ARG CATTLE_RANCHER_WEBHOOK_VERSION +ENV CATTLE_RANCHER_WEBHOOK_VERSION=$CATTLE_RANCHER_WEBHOOK_VERSION ENV SSL_CERT_DIR /etc/kubernetes/ssl/certs COPY --from=rancher /var/lib/rancher-data /var/lib/rancher-data COPY --from=rancher /usr/bin/tini /usr/bin/ diff --git a/pkg/buildconfig/constants.go b/pkg/buildconfig/constants.go new file mode 100644 index 00000000000..740833933f8 --- /dev/null +++ b/pkg/buildconfig/constants.go @@ -0,0 +1,10 @@ +// 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 ( + CspAdapterMinVersion = "103.0.0+up3.0.0" + DefaultShellVersion = "rancher/shell:v0.1.22" + FleetVersion = "103.1.0+up0.9.0" + WebhookVersion = "103.0.1+up0.4.2" +) diff --git a/pkg/codegen/buildconfig/main.go b/pkg/codegen/buildconfig/main.go new file mode 100644 index 00000000000..4a4b3e24edd --- /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 00000000000..517f58b90c5 --- /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 00000000000..f7c842c819e --- /dev/null +++ b/pkg/codegen/buildconfig/writer_test.go @@ -0,0 +1,117 @@ +package main_test + +import ( + "bytes" + "io" + "testing" + "text/template" + + "github.com/rancher/rancher/pkg/codegen/buildconfig" + "github.com/stretchr/testify/require" +) + +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 := &main.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 := main.GoConstantsWriter{ + Input: test.input, + Output: test.output, + Tmpl: test.tmpl, + } + require.Error(t, w.Run()) + }) + } +} diff --git a/pkg/settings/setting.go b/pkg/settings/setting.go index ca5540b49f4..04db5fb5cda 100644 --- a/pkg/settings/setting.go +++ b/pkg/settings/setting.go @@ -11,6 +11,7 @@ import ( v32 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" authsettings "github.com/rancher/rancher/pkg/auth/settings" + "github.com/rancher/rancher/pkg/buildconfig" fleetconst "github.com/rancher/rancher/pkg/fleet" "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" @@ -118,7 +119,7 @@ var ( PartnerChartDefaultBranch = NewSetting("partner-chart-default-branch", "main") RKE2ChartDefaultBranch = NewSetting("rke2-chart-default-branch", "main") FleetDefaultWorkspaceName = NewSetting("fleet-default-workspace-name", fleetconst.ClustersDefaultNamespace) // fleetWorkspaceName to assign to clusters with none - ShellImage = NewSetting("shell-image", "rancher/shell:v0.1.22") + ShellImage = NewSetting("shell-image", buildconfig.DefaultShellVersion) IgnoreNodeName = NewSetting("ignore-node-name", "") // nodes to ignore when syncing v1.node to v3.node NoDefaultAdmin = NewSetting("no-default-admin", "") RestrictedDefaultAdmin = NewSetting("restricted-default-admin", "false") // When bootstrapping the admin for the first time, give them the global role restricted-admin diff --git a/scripts/build-server b/scripts/build-server index 3356ac9f9ef..d8e4b764b53 100755 --- a/scripts/build-server +++ b/scripts/build-server @@ -2,6 +2,7 @@ set -ex source $(dirname $0)/version +source $(dirname $0)/export-config cd $(dirname $0)/.. diff --git a/scripts/chart/build b/scripts/chart/build index f9f70717bcc..91eecef1a00 100755 --- a/scripts/chart/build +++ b/scripts/chart/build @@ -6,6 +6,7 @@ echo "-- chart/build --" cd $(dirname $0)/.. . ./version +. ./export-config cd .. mkdir -p build/chart @@ -15,8 +16,7 @@ cp -rf ${1} build/chart/rancher sed -i -e "s/%VERSION%/${CHART_VERSION}/g" build/chart/rancher/Chart.yaml sed -i -e "s/%APP_VERSION%/${APP_VERSION}/g" build/chart/rancher/Chart.yaml -# get the value of shell-image, such as rancher/shell:v0.1.6, from the file pkg/settings/setting.go -post_delete_base=$(grep -i shell-image pkg/settings/setting.go | cut -d "," -f 2 | sed -e 's/"//g' | sed -e 's/)//g' | sed -e 's/ //g') || "" +post_delete_base=$CATTLE_DEFAULT_SHELL_VERSION post_delete_image_name=$(echo "${post_delete_base}" | cut -d ":" -f 1) || "" post_delete_image_tag=$(echo "${post_delete_base}" | cut -d ":" -f 2) || "" if [[ ! ${post_delete_image_name} =~ ^rancher\/.+ ]]; then diff --git a/scripts/export-config b/scripts/export-config new file mode 100755 index 00000000000..9e4fdf2beda --- /dev/null +++ b/scripts/export-config @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -e + +if [ -n "$DEBUG" ]; then + set -x +fi + +file="$(git rev-parse --show-toplevel)/build.yaml" + +CATTLE_RANCHER_WEBHOOK_VERSION=$(yq -e '.webhookVersion' "$file") +CATTLE_CSP_ADAPTER_MIN_VERSION=$(yq -e '.cspAdapterMinVersion' "$file") +CATTLE_DEFAULT_SHELL_VERSION=$(yq -e '.defaultShellVersion' "$file") +CATTLE_FLEET_VERSION=$(yq -e '.fleetVersion' "$file") + +export CATTLE_RANCHER_WEBHOOK_VERSION +export CATTLE_CSP_ADAPTER_MIN_VERSION +export CATTLE_DEFAULT_SHELL_VERSION +export CATTLE_FLEET_VERSION diff --git a/scripts/package b/scripts/package index b47ffc6b94d..edd7871a754 100755 --- a/scripts/package +++ b/scripts/package @@ -2,8 +2,8 @@ set -e source $(dirname $0)/version - -source package-env +source $(dirname $0)/export-config +source $(dirname $0)/package-env cd $(dirname $0)/../package @@ -21,9 +21,25 @@ if [ ${ARCH} == s390x ]; then ETCD_UNSUPPORTED_ARCH=s390x fi -docker build --build-arg VERSION=${TAG} --build-arg ETCD_UNSUPPORTED_ARCH=${ETCD_UNSUPPORTED_ARCH} --build-arg ARCH=${ARCH} --build-arg IMAGE_REPO=${REPO} --build-arg SYSTEM_CHART_DEFAULT_BRANCH=${SYSTEM_CHART_DEFAULT_BRANCH} --build-arg CHART_DEFAULT_BRANCH=${CHART_DEFAULT_BRANCH} -t ${IMAGE} . +docker build \ + --build-arg VERSION=${TAG} \ + --build-arg ETCD_UNSUPPORTED_ARCH=${ETCD_UNSUPPORTED_ARCH} \ + --build-arg ARCH=${ARCH} \ + --build-arg IMAGE_REPO=${REPO} \ + --build-arg SYSTEM_CHART_DEFAULT_BRANCH=${SYSTEM_CHART_DEFAULT_BRANCH} \ + --build-arg CHART_DEFAULT_BRANCH=${CHART_DEFAULT_BRANCH} \ + --build-arg CATTLE_RANCHER_WEBHOOK_VERSION="${CATTLE_RANCHER_WEBHOOK_VERSION}" \ + --build-arg CATTLE_CSP_ADAPTER_MIN_VERSION="${CATTLE_CSP_ADAPTER_MIN_VERSION}" \ + --build-arg CATTLE_FLEET_VERSION="${CATTLE_FLEET_VERSION}" \ + -t ${IMAGE} . -docker build --build-arg VERSION=${TAG} --build-arg ARCH=${ARCH} --build-arg RANCHER_TAG=${TAG} --build-arg RANCHER_REPO=${REPO} -t ${AGENT_IMAGE} -f Dockerfile.agent . +docker build \ + --build-arg VERSION=${TAG} \ + --build-arg ARCH=${ARCH} \ + --build-arg RANCHER_TAG=${TAG} \ + --build-arg CATTLE_RANCHER_WEBHOOK_VERSION="${CATTLE_RANCHER_WEBHOOK_VERSION}" \ + --build-arg RANCHER_REPO=${REPO} \ + -t ${AGENT_IMAGE} -f Dockerfile.agent . mkdir -p ../dist echo ${IMAGE} > ../dist/images diff --git a/tests/v2/codecoverage/package/Dockerfile b/tests/v2/codecoverage/package/Dockerfile index 6bfd834efa0..d698f16888c 100644 --- a/tests/v2/codecoverage/package/Dockerfile +++ b/tests/v2/codecoverage/package/Dockerfile @@ -57,9 +57,12 @@ ENV CATTLE_SYSTEM_UPGRADE_CONTROLLER_CHART_VERSION 103.0.0+up0.6.0 # System charts minimal version # Deprecated in favor of CATTLE_FLEET_VERSION ENV CATTLE_FLEET_MIN_VERSION="" -ENV CATTLE_FLEET_VERSION=103.1.0+up0.9.0-rc.4 -ENV CATTLE_RANCHER_WEBHOOK_VERSION=103.0.1+up0.4.2 -ENV CATTLE_CSP_ADAPTER_MIN_VERSION=103.0.0+up3.0.0 +ARG CATTLE_FLEET_VERSION +ENV CATTLE_FLEET_VERSION=$CATTLE_FLEET_VERSION +ARG CATTLE_RANCHER_WEBHOOK_VERSION +ENV CATTLE_RANCHER_WEBHOOK_VERSION=$CATTLE_RANCHER_WEBHOOK_VERSION +ARG CATTLE_CSP_ADAPTER_MIN_VERSION +ENV CATTLE_CSP_ADAPTER_MIN_VERSION=$CATTLE_CSP_ADAPTER_MIN_VERSION RUN mkdir -p /var/lib/rancher-data/local-catalogs/system-library && \ mkdir -p /var/lib/rancher-data/local-catalogs/library && \ diff --git a/tests/v2/codecoverage/package/Dockerfile.agent b/tests/v2/codecoverage/package/Dockerfile.agent index b897f96c82c..dfa8d3cdbd8 100644 --- a/tests/v2/codecoverage/package/Dockerfile.agent +++ b/tests/v2/codecoverage/package/Dockerfile.agent @@ -22,6 +22,8 @@ ENV AGENT_IMAGE ${RANCHER_REPO}/rancher-agent:${VERSION} # For now, this value needs to be manually synced with the one in the main Dockerfile. This pins downstream webhook's version. ENV CATTLE_RANCHER_WEBHOOK_VERSION=103.0.1+up0.4.2 ENV SSL_CERT_DIR /etc/kubernetes/ssl/certs +ARG CATTLE_RANCHER_WEBHOOK_VERSION +ENV CATTLE_RANCHER_WEBHOOK_VERSION=$CATTLE_RANCHER_WEBHOOK_VERSION COPY --from=rancher /var/lib/rancher-data /var/lib/rancher-data COPY --from=rancher /usr/bin/tini /usr/bin/ COPY agent run_agent.sh kubectl-shell.sh shell-setup.sh /usr/bin/ diff --git a/tests/v2/codecoverage/scripts/build-agent.sh b/tests/v2/codecoverage/scripts/build-agent.sh index e9c67fd6704..2be7ead723b 100755 --- a/tests/v2/codecoverage/scripts/build-agent.sh +++ b/tests/v2/codecoverage/scripts/build-agent.sh @@ -4,6 +4,7 @@ set -e cd $(dirname $0)/../../../../ source $(dirname $0)/scripts/version +source $(dirname $0)/scripts/export-config mkdir -p bin diff --git a/tests/v2/codecoverage/scripts/build-rancher.sh b/tests/v2/codecoverage/scripts/build-rancher.sh index c4787cd36d3..37da93dd1f1 100755 --- a/tests/v2/codecoverage/scripts/build-rancher.sh +++ b/tests/v2/codecoverage/scripts/build-rancher.sh @@ -4,6 +4,7 @@ set -ex cd $(dirname $0)/../../../../ source $(dirname $0)/scripts/version +source $(dirname $0)/scripts/export-config CATTLE_KDM_BRANCH=dev-v2.8 diff --git a/tests/v2/codecoverage/scripts/build_docker_images.sh b/tests/v2/codecoverage/scripts/build_docker_images.sh index e4a3ab0f230..6175cc15835 100755 --- a/tests/v2/codecoverage/scripts/build_docker_images.sh +++ b/tests/v2/codecoverage/scripts/build_docker_images.sh @@ -1,6 +1,8 @@ #!/bin/bash set -e +source $(dirname $0)/../../../../scripts/export-config + ARCH=${ARCH:-"amd64"} REPO=ranchertest TAG=v2.7-head @@ -22,10 +24,23 @@ IMAGE=${REPO}/rancher:${TAG} AGENT_IMAGE=${REPO}/rancher-agent:${TAG} echo "building rancher test docker image" -docker build --build-arg VERSION=${TAG} --build-arg ARCH=${ARCH} --build-arg IMAGE_REPO=${REPO} -t ${IMAGE} -f Dockerfile . --no-cache +docker build \ + --build-arg VERSION=${TAG} \ + --build-arg ARCH=${ARCH} \ + --build-arg IMAGE_REPO=${REPO} \ + --build-arg CATTLE_RANCHER_WEBHOOK_VERSION="${CATTLE_RANCHER_WEBHOOK_VERSION}" \ + --build-arg CATTLE_CSP_ADAPTER_MIN_VERSION="${CATTLE_CSP_ADAPTER_MIN_VERSION}" \ + --build-arg CATTLE_FLEET_VERSION="${CATTLE_FLEET_VERSION}" \ + -t ${IMAGE} -f Dockerfile . --no-cache echo "building agent test docker image" -docker build --build-arg VERSION=${TAG} --build-arg ARCH=${ARCH} --build-arg RANCHER_TAG=${TAG} --build-arg RANCHER_REPO=${REPO} -t ${AGENT_IMAGE} -f Dockerfile.agent . --no-cache +docker build \ + --build-arg VERSION=${TAG} \ + --build-arg ARCH=${ARCH} \ + --build-arg RANCHER_TAG=${TAG} \ + --build-arg RANCHER_REPO=${REPO} \ + --build-arg CATTLE_RANCHER_WEBHOOK_VERSION="${CATTLE_RANCHER_WEBHOOK_VERSION}" \ + -t ${AGENT_IMAGE} -f Dockerfile.agent . --no-cache echo ${DOCKERHUB_PASSWORD} | docker login --username ${DOCKERHUB_USERNAME} --password-stdin