Skip to content

Commit

Permalink
Repo controlled build go version
Browse files Browse the repository at this point in the history
  • Loading branch information
xdu31 committed Nov 11, 2023
1 parent e85c254 commit ceb6db6
Show file tree
Hide file tree
Showing 23 changed files with 1,102 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.20.10
- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.20.10
- name: GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.20.10
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# 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.
ARG BUILDER=public.ecr.aws/eks-distro-build-tooling/golang:1.19-gcc
ARG BUILDER=public.ecr.aws/eks-distro-build-tooling/golang:1.20.10-11-gcc
ARG BASE_IMAGE=public.ecr.aws/eks-distro/kubernetes/go-runner:v0.13.0-eks-1-23-9

FROM --platform=$BUILDPLATFORM ${BUILDER} AS build
Expand Down
21 changes: 21 additions & 0 deletions LICENSES/third_party/gimme/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015-2018 gimme contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ lint:
hack/verify-golint.sh

test:
go test -v -cover -race ./...
hack/run-test.sh

build-docker:
docker buildx build \
--output=type=docker \
--platform=linux/$(GOARCH) \
-t ${REPO}/${IMAGE}:latest \
-t ${REPO}/${IMAGE}:${TAG} \
--build-arg BUILDER=$(shell hack/setup-go.sh) \
--build-arg TAG=${TAG} .

build-server:
go build -ldflags \
"-w -s -X sigs.k8s.io/aws-encryption-provider/pkg/version.Version=${TAG}" \
-o bin/aws-encryption-provider cmd/server/main.go
TAG=${TAG} hack/build-server.sh

build-client:
go build -ldflags "-w -s" -o bin/grpcclient cmd/client/main.go
go build -ldflags "-w -s" -o bin/grpcclientv2 cmd/clientv2/main.go
TAG=${TAG} hack/build-client.sh

8 changes: 8 additions & 0 deletions hack/build-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

source hack/setup-go.sh

go version
go build -ldflags "-w -s" -o bin/grpcclient cmd/client/main.go
go build -ldflags "-w -s" -o bin/grpcclientv2 cmd/clientv2/main.go
9 changes: 9 additions & 0 deletions hack/build-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

source hack/setup-go.sh

go version
go build -ldflags \
"-w -s -X sigs.k8s.io/aws-encryption-provider/pkg/version.Version=${TAG}" \
-o bin/aws-encryption-provider cmd/server/main.go
7 changes: 7 additions & 0 deletions hack/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

source hack/setup-go.sh

go version
go test -v -cover -race ./...
45 changes: 45 additions & 0 deletions hack/setup-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# Copyright 2020 The Kubernetes Authors.
#
# 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.

# script to setup go version with gimme as needed
# MUST BE RUN FROM THE REPO ROOT DIRECTORY

# read go-version file unless GO_VERSION is set
GO_VERSION="${GO_VERSION:-"$(cat .go-version)"}"
EKSD_GO_IMAGE_SUFFIX=$(echo $GO_VERSION | cut -d'.' -f3)
((EKSD_GO_IMAGE_SUFFIX+=1))
GO_IMAGE=public.ecr.aws/eks-distro-build-tooling/golang:$GO_VERSION-$EKSD_GO_IMAGE_SUFFIX-gcc

# we don't actually care where the .env files are
# however, GIMME_SILENT_ENV doesn't trigger re-generating a .env if it
# already exists and isn't "silent" (no `go version` command in it)
# so we fix that by changing where the .env is written, ensuring ours
# is generated from this repo and silent.
export GIMME_ENV_PREFIX=./bin/.gimme/
export GIMME_SILENT_ENV=y

# only setup go if we haven't set FORCE_HOST_GO, or `go version` doesn't match
# go version output looks like:
# go version go1.14.5 darwin/amd64
if ! ([ -n "${FORCE_HOST_GO:-}" ] || \
(command -v go >/dev/null && [ "$(go version | cut -d' ' -f3)" = "go${GO_VERSION}" ])); then
# eval because the output of this is shell to set PATH etc.
eval "$(hack/third_party/gimme/gimme "${GO_VERSION}")"
fi

# force go modules
export GO111MODULE=on

echo $GO_IMAGE
21 changes: 21 additions & 0 deletions hack/third_party/gimme/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015-2018 gimme contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions hack/third_party/gimme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# gimme

This is an unmodified copy of [gimme], so we don't have to download it
from the internet.

[gimme]: https://github.com/travis-ci/gimme
Loading

0 comments on commit ceb6db6

Please sign in to comment.