Reduce number of places where go version is set (#17762)

Reduce go version references to two: .go_version and @executors.yml.
This commit is contained in:
Nick Cabatoff 2022-11-01 15:37:13 -04:00 committed by GitHub
parent 2945924b2b
commit f1c92200b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 78 additions and 45 deletions

41
.circleci/config.yml generated
View File

@ -77,10 +77,13 @@ jobs:
shell: /usr/bin/env bash -euo pipefail -c shell: /usr/bin/env bash -euo pipefail -c
working_directory: /home/circleci/go/src/github.com/hashicorp/vault working_directory: /home/circleci/go/src/github.com/hashicorp/vault
steps: steps:
- checkout
- run: - run:
command: | command: |
GO_VERSION=$(cat .go-version)
[ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; } [ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; }
# Install Go # Install Go
cd ~
curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz" sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
@ -96,8 +99,6 @@ jobs:
echo "$ go version" echo "$ go version"
go version go version
name: Setup Go name: Setup Go
working_directory: ~/
- checkout
- restore_cache: - restore_cache:
keys: keys:
- v1.5-{{checksum "go.sum"}}-{{checksum "sdk/go.sum"}}-{{checksum "api/go.sum"}} - v1.5-{{checksum "go.sum"}}-{{checksum "sdk/go.sum"}}-{{checksum "api/go.sum"}}
@ -119,8 +120,8 @@ jobs:
root: . root: .
environment: environment:
- CIRCLECI_CLI_VERSION: 0.1.5546 - CIRCLECI_CLI_VERSION: 0.1.5546
- GO_IMAGE: docker.mirror.hashicorp.services/cimg/go:1.19.2
- GO_TAGS: '' - GO_TAGS: ''
- GO_VERSION: 1.19.2
- GOFUMPT_VERSION: 0.3.1 - GOFUMPT_VERSION: 0.3.1
- GOTESTSUM_VERSION: 0.5.2 - GOTESTSUM_VERSION: 0.5.2
test-go-remote-docker: test-go-remote-docker:
@ -261,7 +262,7 @@ jobs:
-e NO_PROXY \ -e NO_PROXY \
-e VAULT_TEST_LOG_DIR=/tmp/testlogs \ -e VAULT_TEST_LOG_DIR=/tmp/testlogs \
--network ${TEST_DOCKER_NETWORK_NAME} \ --network ${TEST_DOCKER_NETWORK_NAME} \
docker.mirror.hashicorp.services/cimg/go:1.19.2 \ $GO_IMAGE \
tail -f /dev/null)" tail -f /dev/null)"
mkdir workspace mkdir workspace
echo ${CONTAINER_ID} > workspace/container_id echo ${CONTAINER_ID} > workspace/container_id
@ -351,17 +352,23 @@ jobs:
path: /tmp/testlogs path: /tmp/testlogs
environment: environment:
- CIRCLECI_CLI_VERSION: 0.1.5546 - CIRCLECI_CLI_VERSION: 0.1.5546
- GO_IMAGE: docker.mirror.hashicorp.services/cimg/go:1.19.2
- GO_TAGS: '' - GO_TAGS: ''
- GOFUMPT_VERSION: 0.3.1
- GOTESTSUM_VERSION: 0.5.2
fmt: fmt:
machine: machine:
image: ubuntu-2004:202201-02 image: ubuntu-2004:202201-02
shell: /usr/bin/env bash -euo pipefail -c shell: /usr/bin/env bash -euo pipefail -c
working_directory: /home/circleci/go/src/github.com/hashicorp/vault working_directory: /home/circleci/go/src/github.com/hashicorp/vault
steps: steps:
- checkout
- run: - run:
command: | command: |
GO_VERSION=$(cat .go-version)
[ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; } [ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; }
# Install Go # Install Go
cd ~
curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz" sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
@ -377,8 +384,6 @@ jobs:
echo "$ go version" echo "$ go version"
go version go version
name: Setup Go name: Setup Go
working_directory: ~/
- checkout
- run: - run:
command: | command: |
echo "Using gofumpt version ${GOFUMPT_VERSION}" echo "Using gofumpt version ${GOFUMPT_VERSION}"
@ -391,8 +396,8 @@ jobs:
name: make fmt name: make fmt
environment: environment:
- CIRCLECI_CLI_VERSION: 0.1.5546 - CIRCLECI_CLI_VERSION: 0.1.5546
- GO_IMAGE: docker.mirror.hashicorp.services/cimg/go:1.19.2
- GO_TAGS: '' - GO_TAGS: ''
- GO_VERSION: 1.19.2
- GOFUMPT_VERSION: 0.3.1 - GOFUMPT_VERSION: 0.3.1
- GOTESTSUM_VERSION: 0.5.2 - GOTESTSUM_VERSION: 0.5.2
test-go-race: test-go-race:
@ -529,7 +534,7 @@ jobs:
-e NO_PROXY \ -e NO_PROXY \
-e VAULT_TEST_LOG_DIR=/tmp/testlogs \ -e VAULT_TEST_LOG_DIR=/tmp/testlogs \
--network ${TEST_DOCKER_NETWORK_NAME} \ --network ${TEST_DOCKER_NETWORK_NAME} \
docker.mirror.hashicorp.services/cimg/go:1.19.2 \ $GO_IMAGE \
tail -f /dev/null)" tail -f /dev/null)"
mkdir workspace mkdir workspace
echo ${CONTAINER_ID} > workspace/container_id echo ${CONTAINER_ID} > workspace/container_id
@ -613,7 +618,10 @@ jobs:
path: /tmp/testlogs path: /tmp/testlogs
environment: environment:
- CIRCLECI_CLI_VERSION: 0.1.5546 - CIRCLECI_CLI_VERSION: 0.1.5546
- GO_IMAGE: docker.mirror.hashicorp.services/cimg/go:1.19.2
- GO_TAGS: '' - GO_TAGS: ''
- GOFUMPT_VERSION: 0.3.1
- GOTESTSUM_VERSION: 0.5.2
test-go: test-go:
docker: docker:
- image: docker.mirror.hashicorp.services/cimg/go:1.19.2 - image: docker.mirror.hashicorp.services/cimg/go:1.19.2
@ -748,7 +756,7 @@ jobs:
-e NO_PROXY \ -e NO_PROXY \
-e VAULT_TEST_LOG_DIR=/tmp/testlogs \ -e VAULT_TEST_LOG_DIR=/tmp/testlogs \
--network ${TEST_DOCKER_NETWORK_NAME} \ --network ${TEST_DOCKER_NETWORK_NAME} \
docker.mirror.hashicorp.services/cimg/go:1.19.2 \ $GO_IMAGE \
tail -f /dev/null)" tail -f /dev/null)"
mkdir workspace mkdir workspace
echo ${CONTAINER_ID} > workspace/container_id echo ${CONTAINER_ID} > workspace/container_id
@ -832,7 +840,10 @@ jobs:
path: /tmp/testlogs path: /tmp/testlogs
environment: environment:
- CIRCLECI_CLI_VERSION: 0.1.5546 - CIRCLECI_CLI_VERSION: 0.1.5546
- GO_IMAGE: docker.mirror.hashicorp.services/cimg/go:1.19.2
- GO_TAGS: '' - GO_TAGS: ''
- GOFUMPT_VERSION: 0.3.1
- GOTESTSUM_VERSION: 0.5.2
semgrep: semgrep:
docker: docker:
- image: docker.mirror.hashicorp.services/returntocorp/semgrep:0.113.0 - image: docker.mirror.hashicorp.services/returntocorp/semgrep:0.113.0
@ -851,10 +862,13 @@ jobs:
shell: /usr/bin/env bash -euo pipefail -c shell: /usr/bin/env bash -euo pipefail -c
working_directory: /home/circleci/go/src/github.com/hashicorp/vault working_directory: /home/circleci/go/src/github.com/hashicorp/vault
steps: steps:
- checkout
- run: - run:
command: | command: |
GO_VERSION=$(cat .go-version)
[ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; } [ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; }
# Install Go # Install Go
cd ~
curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz" sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
@ -870,8 +884,6 @@ jobs:
echo "$ go version" echo "$ go version"
go version go version
name: Setup Go name: Setup Go
working_directory: ~/
- checkout
- run: - run:
command: | command: |
export CCI_PATH=/tmp/circleci-cli/$CIRCLECI_CLI_VERSION export CCI_PATH=/tmp/circleci-cli/$CIRCLECI_CLI_VERSION
@ -935,8 +947,8 @@ jobs:
- /home/circleci/go/pkg/mod - /home/circleci/go/pkg/mod
environment: environment:
- CIRCLECI_CLI_VERSION: 0.1.5546 - CIRCLECI_CLI_VERSION: 0.1.5546
- GO_IMAGE: docker.mirror.hashicorp.services/cimg/go:1.19.2
- GO_TAGS: '' - GO_TAGS: ''
- GO_VERSION: 1.19.2
- GOFUMPT_VERSION: 0.3.1 - GOFUMPT_VERSION: 0.3.1
- GOTESTSUM_VERSION: 0.5.2 - GOTESTSUM_VERSION: 0.5.2
test-go-race-remote-docker: test-go-race-remote-docker:
@ -1077,7 +1089,7 @@ jobs:
-e NO_PROXY \ -e NO_PROXY \
-e VAULT_TEST_LOG_DIR=/tmp/testlogs \ -e VAULT_TEST_LOG_DIR=/tmp/testlogs \
--network ${TEST_DOCKER_NETWORK_NAME} \ --network ${TEST_DOCKER_NETWORK_NAME} \
docker.mirror.hashicorp.services/cimg/go:1.19.2 \ $GO_IMAGE \
tail -f /dev/null)" tail -f /dev/null)"
mkdir workspace mkdir workspace
echo ${CONTAINER_ID} > workspace/container_id echo ${CONTAINER_ID} > workspace/container_id
@ -1167,7 +1179,10 @@ jobs:
path: /tmp/testlogs path: /tmp/testlogs
environment: environment:
- CIRCLECI_CLI_VERSION: 0.1.5546 - CIRCLECI_CLI_VERSION: 0.1.5546
- GO_IMAGE: docker.mirror.hashicorp.services/cimg/go:1.19.2
- GO_TAGS: '' - GO_TAGS: ''
- GOFUMPT_VERSION: 0.3.1
- GOTESTSUM_VERSION: 0.5.2
workflows: workflows:
ci: ci:
jobs: jobs:

View File

@ -12,9 +12,6 @@ parameters:
save_cache: save_cache:
type: boolean type: boolean
default: false default: false
go_image:
type: string
default: "docker.mirror.hashicorp.services/cimg/go:1.19.2"
use_docker: use_docker:
type: boolean type: boolean
default: false default: false
@ -137,7 +134,7 @@ steps:
-e NO_PROXY \ -e NO_PROXY \
-e VAULT_TEST_LOG_DIR=<< parameters.log_dir >> \ -e VAULT_TEST_LOG_DIR=<< parameters.log_dir >> \
--network ${TEST_DOCKER_NETWORK_NAME} \ --network ${TEST_DOCKER_NETWORK_NAME} \
<< parameters.go_image >> \ $GO_IMAGE \
tail -f /dev/null)" tail -f /dev/null)"
mkdir workspace mkdir workspace
echo ${CONTAINER_ID} > workspace/container_id echo ${CONTAINER_ID} > workspace/container_id

View File

@ -13,11 +13,12 @@ parameters:
default: github.com/hashicorp/* default: github.com/hashicorp/*
steps: steps:
- run: - run:
working_directory: ~/
name: Setup Go name: Setup Go
command: | command: |
GO_VERSION=$(cat .go-version)
[ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; } [ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; }
# Install Go # Install Go
cd ~
curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz" sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"

View File

@ -1,13 +1,16 @@
go-machine: references:
machine: environment: &ENVIRONMENT
image: ubuntu-2004:202201-02
shell: /usr/bin/env bash -euo pipefail -c
environment:
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3) CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_VERSION: 1.19.2 # Pin Go to patch version (ex: 1.2.3)
GOTESTSUM_VERSION: 0.5.2 # Pin gotestsum to patch version (ex: 1.2.3) GOTESTSUM_VERSION: 0.5.2 # Pin gotestsum to patch version (ex: 1.2.3)
GOFUMPT_VERSION: 0.3.1 # Pin gofumpt to patch version (ex: 1.2.3) GOFUMPT_VERSION: 0.3.1 # Pin gofumpt to patch version (ex: 1.2.3)
GO_TAGS: "" GO_TAGS: ""
GO_IMAGE: &GO_IMAGE "docker.mirror.hashicorp.services/cimg/go:1.19.2"
go-machine:
machine:
image: ubuntu-2004:202201-02
environment: *ENVIRONMENT
shell: /usr/bin/env bash -euo pipefail -c
working_directory: /home/circleci/go/src/github.com/hashicorp/vault working_directory: /home/circleci/go/src/github.com/hashicorp/vault
node: node:
docker: docker:
@ -30,24 +33,18 @@ semgrep:
docker-env-go-test-remote-docker: docker-env-go-test-remote-docker:
resource_class: medium resource_class: medium
docker: docker:
- image: "docker.mirror.hashicorp.services/cimg/go:1.19.2" - image: *GO_IMAGE
environment: environment: *ENVIRONMENT
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_TAGS: ""
working_directory: /home/circleci/go/src/github.com/hashicorp/vault working_directory: /home/circleci/go/src/github.com/hashicorp/vault
docker-env-go-test: docker-env-go-test:
resource_class: large resource_class: large
docker: docker:
- image: "docker.mirror.hashicorp.services/cimg/go:1.19.2" - image: *GO_IMAGE
environment: environment: *ENVIRONMENT
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_TAGS: ""
working_directory: /home/circleci/go/src/github.com/hashicorp/vault working_directory: /home/circleci/go/src/github.com/hashicorp/vault
docker-env-go-test-race: docker-env-go-test-race:
resource_class: xlarge resource_class: xlarge
docker: docker:
- image: "docker.mirror.hashicorp.services/cimg/go:1.19.2" - image: *GO_IMAGE
environment: environment: *ENVIRONMENT
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_TAGS: ""
working_directory: /home/circleci/go/src/github.com/hashicorp/vault working_directory: /home/circleci/go/src/github.com/hashicorp/vault

View File

@ -1,7 +1,7 @@
executor: go-machine executor: go-machine
steps: steps:
- setup-go
- checkout - checkout
- setup-go
- restore_go_mod_cache - restore_go_mod_cache
- attach_workspace: - attach_workspace:
at: . at: .

View File

@ -1,10 +1,10 @@
description: Ensure go formatting is correct. description: Ensure go formatting is correct.
executor: go-machine executor: go-machine
steps: steps:
- checkout
# Setup Go enabling the proxy for downloading modules. # Setup Go enabling the proxy for downloading modules.
- setup-go: - setup-go:
GOPROXY: https://proxy.golang.org,direct GOPROXY: https://proxy.golang.org,direct
- checkout
- run: - run:
name: make fmt name: make fmt
command: | command: |

View File

@ -1,10 +1,10 @@
description: Ensure nothing obvious is broken, and pre-cache Go modules. description: Ensure nothing obvious is broken, and pre-cache Go modules.
executor: go-machine executor: go-machine
steps: steps:
- checkout
# Setup Go enabling the proxy for downloading modules. # Setup Go enabling the proxy for downloading modules.
- setup-go: - setup-go:
GOPROXY: https://proxy.golang.org,direct GOPROXY: https://proxy.golang.org,direct
- checkout
- run: - run:
name: Install CircleCI CLI name: Install CircleCI CLI
environment: environment:

View File

@ -1,7 +1,7 @@
executor: go-machine executor: go-machine
steps: steps:
- setup-go
- checkout - checkout
- setup-go
- restore_go_mod_cache - restore_go_mod_cache
- go_test: - go_test:
log_dir: "/tmp/testlogs" log_dir: "/tmp/testlogs"

23
.github/workflows/goversion-checker.yml vendored Normal file
View File

@ -0,0 +1,23 @@
name: Check Go version
on:
pull_request:
types: [opened, synchronize]
jobs:
go-version-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Verify go versions in tree are consistent with one another
run: |
GOVER=$(cat .go-version)
EXPECTED="docker.mirror.hashicorp.services/cimg/go:$GOVER"
GOT=$(yq .references.environment.GO_IMAGE .circleci/config/executors/@executors.yml)
if [ "$EXPECTED" != "$GOT" ]; then
echo "version mismatch, .go-version has '$GOVER' and circleci config uses '$GOT'"
exit 1
fi

1
.go-version Normal file
View File

@ -0,0 +1 @@
1.19.2

View File

@ -15,7 +15,7 @@ GOFMT_FILES?=$$(find . -name '*.go' | grep -v pb.go | grep -v vendor)
SED?=$(shell command -v gsed || command -v sed) SED?=$(shell command -v gsed || command -v sed)
GO_VERSION_MIN=1.19.2 GO_VERSION_MIN=$$(cat $(CURDIR)/.go_version)
PROTOC_VERSION_MIN=3.21.7 PROTOC_VERSION_MIN=3.21.7
GO_CMD?=go GO_CMD?=go
CGO_ENABLED?=0 CGO_ENABLED?=0

View File

@ -70,8 +70,7 @@ Developing Vault
-------------------- --------------------
If you wish to work on Vault itself or any of its built-in systems, you'll If you wish to work on Vault itself or any of its built-in systems, you'll
first need [Go](https://www.golang.org) installed on your machine. Go version first need [Go](https://www.golang.org) installed on your machine.
1.19.2+ is *required*.
For local dev first make sure Go is properly installed, including setting up a For local dev first make sure Go is properly installed, including setting up a
[GOPATH](https://golang.org/doc/code.html#GOPATH). Ensure that `$GOPATH/bin` is in [GOPATH](https://golang.org/doc/code.html#GOPATH). Ensure that `$GOPATH/bin` is in

View File

@ -1,6 +1,6 @@
# Multi-stage builder to avoid polluting users environment with wrong # Multi-stage builder to avoid polluting users environment with wrong
# architecture binaries. # architecture binaries.
ARG VERSION=1.19.2 ARG VERSION
FROM golang:${VERSION} AS builder FROM golang:${VERSION} AS builder

View File

@ -2,7 +2,7 @@
# architecture binaries. This file only currently works for linux/amd64. # architecture binaries. This file only currently works for linux/amd64.
FROM debian:buster AS builder FROM debian:buster AS builder
ARG VERSION=1.19.2 ARG VERSION
ARG CGO_ENABLED=0 ARG CGO_ENABLED=0
ARG BUILD_TAGS ARG BUILD_TAGS
ENV JOBS=2 ENV JOBS=2