From 830fb7bf38f9172505813d88587923c4b3205bc1 Mon Sep 17 00:00:00 2001 From: Ivy Gooch Date: Mon, 25 Nov 2024 09:30:04 -0800 Subject: [PATCH] Allows the Helm install of the current Agones development build during the upgrade test --- .dockerignore | 3 +++ cloudbuild.yaml | 13 ++--------- test/upgrade/Dockerfile | 30 ++++++++++-------------- test/upgrade/Makefile | 10 ++++---- test/upgrade/go.mod | 51 ----------------------------------------- test/upgrade/main.go | 24 +++++++++++++------ 6 files changed, 39 insertions(+), 92 deletions(-) delete mode 100644 test/upgrade/go.mod diff --git a/.dockerignore b/.dockerignore index d298dcaad3..ea89279094 100644 --- a/.dockerignore +++ b/.dockerignore @@ -28,6 +28,9 @@ bin /site/public /test +# Allow upgrade test directory +!/test/upgrade + # Created by .ignore support plugin (hsz.mobi) ### Go template # Binaries for programs and plugins diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 2151964d21..f2f4e6afcd 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -233,23 +233,14 @@ steps: # End to end tests # - # Build upgrade test - - name: make-docker - id: build-upgrade-test - dir: test/upgrade - env: ['REGISTRY=${_REGISTRY}'] - args: [build] - waitFor: - - push-images - - # Push upgrade test + # Build and Push upgrade test - name: make-docker id: push-upgrade-test dir: test/upgrade env: ['REGISTRY=${_REGISTRY}'] args: [push] waitFor: - - build-upgrade-test + - push-images # Wait for us to be the oldest ongoing build before we run upgrade and e2e tests - name: gcr.io/google.com/cloudsdktool/cloud-sdk diff --git a/test/upgrade/Dockerfile b/test/upgrade/Dockerfile index 5a18afeeac..68583bfae4 100644 --- a/test/upgrade/Dockerfile +++ b/test/upgrade/Dockerfile @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM gcr.io/cloud-builders/gcloud AS builder +FROM golang:1.22.9-alpine AS builder -RUN apt-get update && \ - apt-get install -y curl && \ - apt-get clean +# install curl +RUN apk update && \ + apk upgrade && \ + apk --no-cache add curl WORKDIR /usr/local @@ -35,27 +36,20 @@ RUN curl -L ${HELM_URL} > /tmp/helm.tar.gz \ && chmod go+rx /usr/local/bin/helm \ && rm /tmp/helm.tar.gz && rm -rf /tmp/linux-amd64 -# Build the Go image from source -FROM golang:1.22.6 AS build-stage - +# Copy and build the Go application WORKDIR /agones.dev - -COPY *.go ./ - +COPY test/upgrade/main.go ./ RUN go mod init agones.dev/agones/test/upgrade/testContainer RUN go mod tidy RUN go mod download - RUN CGO_ENABLED=0 GOOS=linux go build -o /upgrade-test -# Copy the above binary into a lean image -FROM gcr.io/distroless/static-debian12:nonroot AS build-release-stage - +# Copy the dev build Agones Helm chart WORKDIR / -COPY --from=build-stage /upgrade-test /upgrade-test -COPY --from=builder /usr/local /usr/local - -USER nonroot:nonroot +# Use a non-root user for security best practices +RUN adduser -D -g '' adduser +USER adduser +COPY --chown=adduser install/helm/agones /install/helm ENTRYPOINT ["/upgrade-test"] diff --git a/test/upgrade/Makefile b/test/upgrade/Makefile index 0c09e69095..e7c014412f 100644 --- a/test/upgrade/Makefile +++ b/test/upgrade/Makefile @@ -24,14 +24,11 @@ # REGISTRY ?= -mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) -project_path := $(dir $(mkfile_path)) -root_path = $(realpath $(project_path)/) base_version = 1.46.0 # Version defaults to the short hash of the latest commit VERSION ?= $(base_version)-dev-$(shell git rev-parse --short=7 HEAD) server_tag := $(REGISTRY)/upgrade-test-controller:$(VERSION) - +cwd:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) # _____ _ # |_ _|_ _ _ __ __ _ ___| |_ ___ # | |/ _` | '__/ _` |/ _ \ __/ __| @@ -39,9 +36,12 @@ server_tag := $(REGISTRY)/upgrade-test-controller:$(VERSION) # |_|\__,_|_| \__, |\___|\__|___/ # |___/ +# Using .ONESHELL allows us to `cd` to the parent directory agones. This gives the Dockerfile the +# context of the agones directory, which allows it to COPY files from any child directory. +.ONESHELL: # Build a docker image for the server, and tag it build: - cd $(root_path) && docker build -f $(project_path)Dockerfile --tag=$(server_tag) . + cd "$(cwd)/../.." && DOCKER_BUILDKIT=1 docker build -f $(cwd)/Dockerfile --tag=$(server_tag) . push: build docker push $(server_tag) diff --git a/test/upgrade/go.mod b/test/upgrade/go.mod deleted file mode 100644 index f7615ef1da..0000000000 --- a/test/upgrade/go.mod +++ /dev/null @@ -1,51 +0,0 @@ -module agones.dev/agones/test/upgrade/testContainer - -go 1.22 - -toolchain go1.22.6 - -require ( - k8s.io/apimachinery v0.31.0 - k8s.io/client-go v0.31.0 -) - -require ( - github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/emicklei/go-restful/v3 v3.11.0 // indirect - github.com/fxamacker/cbor/v2 v2.7.0 // indirect - github.com/go-logr/logr v1.4.2 // indirect - github.com/go-openapi/jsonpointer v0.19.6 // indirect - github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/swag v0.22.4 // indirect - github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.4 // indirect - github.com/google/gnostic-models v0.6.8 // indirect - github.com/google/go-cmp v0.6.0 // indirect - github.com/google/gofuzz v1.2.0 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/mailru/easyjson v0.7.7 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/onsi/gomega v1.33.1 // indirect - github.com/x448/float16 v0.8.4 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/term v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect - golang.org/x/time v0.3.0 // indirect - google.golang.org/protobuf v1.34.2 // indirect - gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/api v0.31.0 // indirect - k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect - k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect - sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect - sigs.k8s.io/yaml v1.4.0 // indirect -) diff --git a/test/upgrade/main.go b/test/upgrade/main.go index 07d2d86134..b993cc81e2 100644 --- a/test/upgrade/main.go +++ b/test/upgrade/main.go @@ -57,10 +57,14 @@ const ( Timeout = 10 * time.Minute // HelmChart is the helm chart for the public Agones releases HelmChart = "agones/agones" + // TestChart is the registry for Agones Helm chart development builds + TestChart = "./install/helm" // AgonesRegistry is the public registry for Agones releases AgonesRegistry = "us-docker.pkg.dev/agones-images/release" - // TestRegistry is the public registry for upgrade test container files - TestRegistry = "us-docker.pkg.dev/agones-images/ci/sdk-client-test" + // TestRegistry is the registry for Agones development builds + TestRegistry = "us-docker.pkg.dev/agones-images/ci/" + // ContainerRegistry is the registry for upgrade test container files + ContainerRegistry = "us-docker.pkg.dev/agones-images/ci/sdk-client-test" ) var ( @@ -300,13 +304,13 @@ func runConfigWalker(ctx context.Context, validConfigs []*configTest) { registry := AgonesRegistry chart := HelmChart if config.agonesVersion == DevVersion { - // TODO: Update to templated value for registry and chart for Dev build - continue + registry = TestRegistry + chart = TestChart } err := installAgonesRelease(config.agonesVersion, registry, config.featureGates, ImagePullPolicy, SidecarPullPolicy, LogLevel, chart) if err != nil { - log.Printf("installAgonesRelease err: %s", err) + log.Fatalf("installAgonesRelease err: %s", err) } // Wait for the helm release to install. Waits the same amount of time as the Helm timeout. @@ -350,6 +354,12 @@ func checkHelmStatus(agonesVersion string) string { log.Fatal("Could not Unmarshal", err) } + // Remove the commit sha from the DevVersion i.e. from 1.46.0-dev-7168dd3 to 1.46.0-dev + if agonesVersion == DevVersion { + r := regexp.MustCompile(`1\.\d+\.\d+-dev`) + agonesVersion = r.FindString(DevVersion) + } + for _, status := range helmStatus { if status.AppVersion == agonesVersion { return status.Status @@ -362,7 +372,7 @@ func checkHelmStatus(agonesVersion string) string { // gameserver yaml is based on the Agones version, i.e. gs1440.yaml for Agones version 1.44.0 // Note: This does not validate the created file. func createGameServerFile(agonesVersion string, countsAndLists bool) string { - gsTmpl := gameServerTemplate{Registry: TestRegistry, AgonesVersion: agonesVersion, CountsAndLists: countsAndLists} + gsTmpl := gameServerTemplate{Registry: ContainerRegistry, AgonesVersion: agonesVersion, CountsAndLists: countsAndLists} gsTemplate, err := template.ParseFiles("gameserver.yaml") if err != nil { @@ -450,7 +460,7 @@ func checkFirstGameServerReady(ctx context.Context, gsReady chan bool, args ...s log.Fatalf("Could not get Gameserver %s state: %s", gsName, err) } if err != nil { - retries += 1 + retries++ return false, nil } // Sample output: Running sdk-client-test-bbvx9