Skip to content

Commit

Permalink
Reduce number of places where go version is set (#17762)
Browse files Browse the repository at this point in the history
Reduce go version references to two: .go_version and @executors.yml.
  • Loading branch information
ncabatoff committed Nov 23, 2022
1 parent 10562de commit 4f39f68
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 52 deletions.
47 changes: 31 additions & 16 deletions .circleci/config.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions .circleci/config/commands/go_test.yml
Expand Up @@ -12,9 +12,6 @@ parameters:
save_cache:
type: boolean
default: false
go_image:
type: string
default: "docker.mirror.hashicorp.services/cimg/go:1.17.13"
use_docker:
type: boolean
default: false
Expand Down Expand Up @@ -149,7 +146,7 @@ steps:
-e NO_PROXY \
-e VAULT_TEST_LOG_DIR=<< parameters.log_dir >> \
--network vaulttest --name \
testcontainer << parameters.go_image >> \
testcontainer $GO_IMAGE \
tail -f /dev/null
# Run tests
Expand Down
3 changes: 2 additions & 1 deletion .circleci/config/commands/setup-go.yml
Expand Up @@ -13,11 +13,12 @@ parameters:
default: github.com/hashicorp/*
steps:
- run:
working_directory: ~/
name: Setup Go
command: |
GO_VERSION=$(cat .go-version)
[ -n "$GO_VERSION" ] || { echo "You must set GO_VERSION"; exit 1; }
# Install Go
cd ~
curl -sSLO "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
Expand Down
33 changes: 15 additions & 18 deletions .circleci/config/executors/@executors.yml
@@ -1,13 +1,16 @@
references:
environment: &ENVIRONMENT
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI 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)
GO_TAGS: ""
GO_IMAGE: &GO_IMAGE "docker.mirror.hashicorp.services/cimg/go:1.17.13"

go-machine:
machine:
image: ubuntu-2004:202201-02
environment: *ENVIRONMENT
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)
GO_VERSION: 1.17.13 # Pin Go to patch version (ex: 1.2.3)
GOTESTSUM_VERSION: 0.5.2 # Pin gotestsum to patch version (ex: 1.2.3)
GOFUMPT_VERSION: 0.2.1 # Pin gofumpt to patch version (ex: 1.2.3)
GO_TAGS: ""
working_directory: /home/circleci/go/src/github.com/hashicorp/vault
node:
docker:
Expand All @@ -27,24 +30,18 @@ alpine:
docker-env-go-test-remote-docker:
resource_class: medium
docker:
- image: "docker.mirror.hashicorp.services/cimg/go:1.17.13"
environment:
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_TAGS: ""
- image: *GO_IMAGE
environment: *ENVIRONMENT
working_directory: /home/circleci/go/src/github.com/hashicorp/vault
docker-env-go-test:
resource_class: large
docker:
- image: "docker.mirror.hashicorp.services/cimg/go:1.17.13"
environment:
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_TAGS: ""
- image: *GO_IMAGE
environment: *ENVIRONMENT
working_directory: /home/circleci/go/src/github.com/hashicorp/vault
docker-env-go-test-race:
resource_class: xlarge
docker:
- image: "docker.mirror.hashicorp.services/cimg/go:1.17.13"
environment:
CIRCLECI_CLI_VERSION: 0.1.5546 # Pin CircleCI CLI to patch version (ex: 1.2.3)
GO_TAGS: ""
- image: *GO_IMAGE
environment: *ENVIRONMENT
working_directory: /home/circleci/go/src/github.com/hashicorp/vault
2 changes: 1 addition & 1 deletion .circleci/config/jobs/build-go-dev.yml
@@ -1,7 +1,7 @@
executor: go-machine
steps:
- setup-go
- checkout
- setup-go
- restore_go_mod_cache
- attach_workspace:
at: .
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config/jobs/fmt.yml
@@ -1,10 +1,10 @@
description: Ensure go formatting is correct.
executor: go-machine
steps:
- checkout
# Setup Go enabling the proxy for downloading modules.
- setup-go:
GOPROXY: https://proxy.golang.org,direct
- checkout
- run:
name: make fmt
command: |
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config/jobs/pre-flight-checks.yml
@@ -1,10 +1,10 @@
description: Ensure nothing obvious is broken, and pre-cache Go modules.
executor: go-machine
steps:
- checkout
# Setup Go enabling the proxy for downloading modules.
- setup-go:
GOPROXY: https://proxy.golang.org,direct
- checkout
- run:
name: Install CircleCI CLI
environment:
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config/jobs/test-go-nightly.yml
@@ -1,7 +1,7 @@
executor: go-machine
steps:
- setup-go
- checkout
- setup-go
- restore_go_mod_cache
- go_test:
log_dir: "/tmp/testlogs"
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/goversion-checker.yml
@@ -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 change: 1 addition & 0 deletions .go-version
@@ -0,0 +1 @@
1.19.2
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -15,7 +15,7 @@ EXTERNAL_TOOLS=\
GOFMT_FILES?=$$(find . -name '*.go' | grep -v pb.go | grep -v vendor)


GO_VERSION_MIN=1.17.13
GO_VERSION_MIN=$$(cat $(CURDIR)/.go_version)
GO_CMD?=go
CGO_ENABLED?=0
ifneq ($(FDB_ENABLED), )
Expand Down Expand Up @@ -179,8 +179,8 @@ ember-dist-dev:
@echo "--> Building Ember application"
@cd ui && yarn run build:dev

static-dist: ember-dist
static-dist-dev: ember-dist-dev
static-dist: ember-dist
static-dist-dev: ember-dist-dev

proto: bootstrap
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative vault/*.proto
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -70,8 +70,7 @@ Developing Vault
--------------------

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
1.17.13+ is *required*.
first need [Go](https://www.golang.org) installed on your machine.

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
Expand Down
5 changes: 2 additions & 3 deletions scripts/docker/Dockerfile
@@ -1,7 +1,6 @@
# Multi-stage builder to avoid polluting users environment with wrong
# architecture binaries. Since this binary is used in an alpine container,
# we're explicitly compiling for 'linux/amd64'
ARG VERSION=1.17.13
# architecture binaries.
ARG VERSION

FROM golang:${VERSION} AS builder

Expand Down
2 changes: 1 addition & 1 deletion scripts/docker/Dockerfile.ui
Expand Up @@ -3,7 +3,7 @@
# we're explicitly compiling for 'linux/amd64'
FROM debian:buster AS builder

ARG VERSION=1.17.13
ARG VERSION
ARG CGO_ENABLED=0
ARG BUILD_TAGS
ENV JOBS=2
Expand Down

0 comments on commit 4f39f68

Please sign in to comment.