Skip to content

Commit

Permalink
Upgrade Go to 1.20.2 (#1171)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
braydonk authored Mar 24, 2023
1 parent 5f7c535 commit bbfcfa7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 31 deletions.
44 changes: 22 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down Expand Up @@ -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"


Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -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;

#
Expand Down
15 changes: 15 additions & 0 deletions dev-docs/upgrade-go.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions dockerfiles/template
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions integration_test/third_party_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -758,7 +758,7 @@ func determineImpactedApps(modifiedFiles []string, allApps map[string]metadata.I
// in allApps to be a match if they have <f> 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
}
Expand Down
3 changes: 3 additions & 0 deletions tasks.mak
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ yaml_format:
yaml_lint:
yamlfmt -lint

compile_dockerfile:
go run ./dockerfiles

############
# Unit Tests
############
Expand Down

0 comments on commit bbfcfa7

Please sign in to comment.