From bbfcfa77bc9c81450af1f6ebc239d9cd88a6d010 Mon Sep 17 00:00:00 2001 From: Braydon Kains <93549768+braydonk@users.noreply.github.com> Date: Fri, 24 Mar 2023 09:37:19 -0400 Subject: [PATCH] Upgrade Go to 1.20.2 (#1171) * Upgrade Go to 1.20.2 This PR upgrades the version of Go required by the Ops Agent and updates build containers to install go1.20.2. * Use runtime.Version() in integration test Switch to using runtime.Version() in `installGolang` function so we don't always have to manually update the go version in that function. Rewrote the documentation in a way I like better. * Revert ops_agent_test.go, switch to 1.20 Our integration test environment doesn't work the way I thought. go1.20.2 isn't made available in our storage buckets, but go1.20 is so might as well switch to that. * revert changes to ops_agent_test.go --- Dockerfile | 44 +++++++++++------------ Dockerfile.windows | 6 ++-- dev-docs/upgrade-go.md | 15 ++++++++ dockerfiles/template | 4 +-- go.mod | 2 +- integration_test/third_party_apps_test.go | 6 ++-- tasks.mak | 3 ++ 7 files changed, 49 insertions(+), 31 deletions(-) create mode 100644 dev-docs/upgrade-go.md diff --git a/Dockerfile b/Dockerfile index e3aa2658ef..bb42391c64 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,9 +42,9 @@ RUN set -x; yum -y update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -132,9 +132,9 @@ RUN set -x; yum -y update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -225,9 +225,9 @@ RUN set -x; dnf -y update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -313,9 +313,9 @@ RUN set -x; apt-get update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -401,9 +401,9 @@ RUN set -x; apt-get update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -498,9 +498,9 @@ RUN set -x; \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -609,9 +609,9 @@ RUN set -x; \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -711,9 +711,9 @@ RUN set -x; zypper -n install git systemd autoconf automake flex libtool libcurl SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -803,9 +803,9 @@ RUN set -x; apt-get update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -891,9 +891,9 @@ RUN set -x; apt-get update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" @@ -979,9 +979,9 @@ RUN set -x; apt-get update && \ SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" diff --git a/Dockerfile.windows b/Dockerfile.windows index 8ad48d8e52..bdeeb64171 100644 --- a/Dockerfile.windows +++ b/Dockerfile.windows @@ -78,12 +78,12 @@ RUN Expand-Archive /local/win_flex_bison.zip -Destination /WinFlexBison; ` Copy-Item -Path /WinFlexBison/win_flex.exe /WinFlexBison/flex.exe; # -# Install Golang 1.19 +# Install Golang # -ADD https://go.dev/dl/go1.19.windows-amd64.msi /local/go1.19.windows-amd64.msi +ADD https://go.dev/dl/go1.20.2.windows-amd64.msi /local/go1.20.2.windows-amd64.msi RUN Start-Process msiexec.exe ` - -ArgumentList '/i C:\local\go1.19.windows-amd64.msi ', '/quiet ', ` + -ArgumentList '/i C:\local\go1.20.2.windows-amd64.msi ', '/quiet ', ` '/norestart ', 'ALLUSERS=1,INSTALLDIR=C:\Go' -NoNewWindow -Wait; # diff --git a/dev-docs/upgrade-go.md b/dev-docs/upgrade-go.md new file mode 100644 index 0000000000..412440fa97 --- /dev/null +++ b/dev-docs/upgrade-go.md @@ -0,0 +1,15 @@ +# Upgrade Go version + +To upgrade the version of Go that the Ops Agent uses, update the version in the following places: + +* `go.mod` version restriction +* `dockerfiles/template` which downloads and installs Go and is compiled into the main Dockerfile +* `Dockerfile.windows` which downloads and runs the Go MSI + +Once you have updated the Go version in the following places, verify the new version works: + +* Ensure that your local Go version is the same as the new one in `go.mod` +* Run `make test` and verify whether any code updates are required +* Run `make compile_dockerfile` +* Run `make build` to ensure the new Dockerfile will build +* Submit a PR with a title that clearly states the Go upgrade and ensure all Build and Integration Test CI workflows pass \ No newline at end of file diff --git a/dockerfiles/template b/dockerfiles/template index b6af8dc50d..6c3e8fc570 100644 --- a/dockerfiles/template +++ b/dockerfiles/template @@ -9,9 +9,9 @@ FROM {from_image} AS {target_name}-build-base SHELL ["/bin/bash", "-c"] # Install golang -ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz /tmp/go1.19.linux-amd64.tar.gz +ADD https://golang.org/dl/go1.20.2.linux-amd64.tar.gz /tmp/go1.20.2.linux-amd64.tar.gz RUN set -xe; \ - tar -xf /tmp/go1.19.linux-amd64.tar.gz -C /usr/local + tar -xf /tmp/go1.20.2.linux-amd64.tar.gz -C /usr/local ENV PATH="${PATH}:/usr/local/go/bin" diff --git a/go.mod b/go.mod index 7c6b443184..b0cdc54bdd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/GoogleCloudPlatform/ops-agent -go 1.19 +go 1.20 require ( cloud.google.com/go/compute/metadata v0.2.1 diff --git a/integration_test/third_party_apps_test.go b/integration_test/third_party_apps_test.go index 5b8f4ad92f..e5f414a90d 100644 --- a/integration_test/third_party_apps_test.go +++ b/integration_test/third_party_apps_test.go @@ -152,7 +152,7 @@ func runScriptFromScriptsDir(ctx context.Context, logger *logging.DirectoryLogge // stored in the scripts directory. func installUsingScript(ctx context.Context, logger *logging.DirectoryLogger, vm *gce.VM) (bool, error) { environmentVariables := map[string]string{ - "REPO_SUFFIX": os.Getenv("REPO_SUFFIX"), + "REPO_SUFFIX": os.Getenv("REPO_SUFFIX"), "ARTIFACT_REGISTRY_REGION": os.Getenv("ARTIFACT_REGISTRY_REGION"), } if _, err := runScriptFromScriptsDir(ctx, logger, vm, path.Join("agent", gce.PlatformKind(vm.Platform), "install"), environmentVariables); err != nil { @@ -740,7 +740,7 @@ func determineImpactedApps(modifiedFiles []string, allApps map[string]metadata.I for _, f := range modifiedFiles { if isCriticalFile(f) { // Consider all apps as impacted. - for app, _ := range allApps { + for app := range allApps { impactedApps[app] = true } return impactedApps @@ -758,7 +758,7 @@ func determineImpactedApps(modifiedFiles []string, allApps map[string]metadata.I // in allApps to be a match if they have as a prefix. // For example, consider f = "mongodb". Then all of // {mongodb3.6, mongodb} are considered impacted. - for app, _ := range allApps { + for app := range allApps { if strings.HasPrefix(app, f) { impactedApps[app] = true } diff --git a/tasks.mak b/tasks.mak index bc030863a9..e806c7876d 100644 --- a/tasks.mak +++ b/tasks.mak @@ -56,6 +56,9 @@ yaml_format: yaml_lint: yamlfmt -lint +compile_dockerfile: + go run ./dockerfiles + ############ # Unit Tests ############