From 903bf56f56fc5dff23f7cf4951408633ed3f5b55 Mon Sep 17 00:00:00 2001 From: Kalaiselvim <117940852+Kalaiselvi84@users.noreply.github.com> Date: Wed, 7 Feb 2024 00:02:24 +0000 Subject: [PATCH] Script to bump example images (#3626) * Bump Examples Image * comment update * exclude hard carding * update flag desc --------- Co-authored-by: Mengye (Max) Gong <8364575+gongmax@users.noreply.github.com> --- build/includes/website.mk | 5 + build/scripts/bump-image/main.go | 106 ++++++++++++++++++ examples/cpp-simple/fleet.yaml | 2 +- examples/cpp-simple/gameserver.yaml | 2 +- .../agones/templates/tests/test-runner.yaml | 2 +- test/e2e/examples_test.go | 2 +- 6 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 build/scripts/bump-image/main.go diff --git a/build/includes/website.mk b/build/includes/website.mk index bced4c2377..3993128fa5 100644 --- a/build/includes/website.mk +++ b/build/includes/website.mk @@ -138,3 +138,8 @@ update-navbar-version: FILENAME ?= "" update-navbar-version: ensure-build-image docker run --rm $(common_mounts) --workdir=$(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) \ go run build/scripts/update-navbar-version/main.go -file=$(FILENAME) + +# bump examples image +bump-image: ensure-build-image + docker run --rm $(common_mounts) --workdir=$(mount_path) $(DOCKER_RUN_ARGS) $(build_tag) \ + go run build/scripts/bump-image/main.go -imageName=$(IMAGENAME) -version=$(VERSION) diff --git a/build/scripts/bump-image/main.go b/build/scripts/bump-image/main.go new file mode 100644 index 0000000000..860c562870 --- /dev/null +++ b/build/scripts/bump-image/main.go @@ -0,0 +1,106 @@ +// Copyright 2023 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package main implements a program to increment the new tag for the given examples image. Run this script using `make bump-image IMAGENAME= VERSION=` +package main + +import ( + "flag" + "fmt" + "log" + "os" + "path/filepath" + "regexp" + "strconv" + "strings" +) + +var ( + imageName string + version string + versionPattern *regexp.Regexp + targetedFolders = map[string]bool{ + "build": true, + "examples": true, + "install": true, + "pkg": true, + "site": true, + "test": true, + } +) + +func init() { + flag.StringVar(&imageName, "imageName", "", "Image name to update") + flag.StringVar(&version, "version", "", "Version to update") +} + +func main() { + flag.Parse() + + if imageName == "" || version == "" { + log.Fatal("Provide both an image name and a version using the flags.") + } + + versionPatternString := imageName + `:(\d+)\.(\d+)` + versionPattern = regexp.MustCompile(versionPatternString) + newVersion := incrementVersion(version) + + baseDirectory := "." + for folder := range targetedFolders { + directory := filepath.Join(baseDirectory, folder) + + err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() && filepath.Ext(path) != ".md" { + err = updateFileVersion(path, newVersion) + if err != nil { + log.Printf("Error updating file %s: %v", path, err) + } + } + return nil + }) + + if err != nil { + log.Fatalf("Error processing directory %s: %v", directory, err) + } + } +} + +func incrementVersion(version string) string { + parts := strings.Split(version, ".") + if len(parts) != 2 { + log.Fatalf("Invalid version format: %s", version) + } + + minor, err := strconv.Atoi(parts[1]) + if err != nil { + log.Fatalf("Invalid version number: %v", err) + } + + minor++ + return fmt.Sprintf("%s.%d", parts[0], minor) +} + +func updateFileVersion(filePath, newVersion string) error { + input, err := os.ReadFile(filePath) + if err != nil { + return err + } + + content := versionPattern.ReplaceAllString(string(input), imageName+":"+newVersion) + + return os.WriteFile(filePath, []byte(content), 0o644) +} diff --git a/examples/cpp-simple/fleet.yaml b/examples/cpp-simple/fleet.yaml index e9846ba3b4..4951945715 100644 --- a/examples/cpp-simple/fleet.yaml +++ b/examples/cpp-simple/fleet.yaml @@ -30,5 +30,5 @@ spec: spec: containers: - name: cpp-simple - image: us-docker.pkg.dev/agones-images/examples/cpp-simple-server:0.15 + image: us-docker.pkg.dev/agones-images/examples/cpp-simple-server:0.16 # imagePullPolicy: Always # add for development diff --git a/examples/cpp-simple/gameserver.yaml b/examples/cpp-simple/gameserver.yaml index 7ea90c0c72..2cbaa84342 100644 --- a/examples/cpp-simple/gameserver.yaml +++ b/examples/cpp-simple/gameserver.yaml @@ -27,5 +27,5 @@ spec: spec: containers: - name: cpp-simple - image: us-docker.pkg.dev/agones-images/examples/cpp-simple-server:0.15 + image: us-docker.pkg.dev/agones-images/examples/cpp-simple-server:0.16 imagePullPolicy: Always # add for development diff --git a/install/helm/agones/templates/tests/test-runner.yaml b/install/helm/agones/templates/tests/test-runner.yaml index ab75858400..5831ccc61a 100644 --- a/install/helm/agones/templates/tests/test-runner.yaml +++ b/install/helm/agones/templates/tests/test-runner.yaml @@ -25,7 +25,7 @@ spec: serviceAccountName: agones-controller containers: - name: create-gameserver - image: us-docker.pkg.dev/agones-images/examples/crd-client:0.13 + image: us-docker.pkg.dev/agones-images/examples/crd-client:0.14 imagePullPolicy: Always env: - name: GAMESERVER_IMAGE diff --git a/test/e2e/examples_test.go b/test/e2e/examples_test.go index d15549389b..ee2c74af4b 100644 --- a/test/e2e/examples_test.go +++ b/test/e2e/examples_test.go @@ -119,7 +119,7 @@ func TestCppSimpleGameServerReady(t *testing.T) { Containers: []corev1.Container{ { Name: "cpp-simple", - Image: "us-docker.pkg.dev/agones-images/examples/cpp-simple-server:0.15", + Image: "us-docker.pkg.dev/agones-images/examples/cpp-simple-server:0.16", }, }, },