Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo controlled build go version #692

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
aws-iam-authenticator

bin

/dist
/_output

Expand Down
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.21.5
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ARG golang_image=public.ecr.aws/docker/library/golang:1.21.5
FROM --platform=$BUILDPLATFORM $golang_image AS builder
WORKDIR /go/src/github.com/kubernetes-sigs/aws-iam-authenticator
COPY . .
RUN go version
RUN goproxy=https://goproxy.io go mod download
ARG TARGETOS TARGETARCH
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make bin
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ image: .image-linux-$(GOARCH)
.PHONY: .image-linux-%
.image-linux-%:
docker buildx build --output=type=docker --platform linux/$* \
--build-arg golang_image=$(shell hack/setup-go.sh) \
--tag aws-iam-authenticator:$(VERSION)_$(GIT_COMMIT)_$(BUILD_DATE_STRIPPED)-linux_$* .

.PHONY: goreleaser
Expand All @@ -111,8 +112,7 @@ endif

.PHONY: test
test:
go test -v -coverprofile=coverage.out -race $(PKG)/pkg/...
go tool cover -html=coverage.out -o coverage.html
./hack/test-unit.sh

.PHONY: integration
integration:
Expand Down
31 changes: 31 additions & 0 deletions hack/setup-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/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 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)"}"
GO_IMAGE=public.ecr.aws/docker/library/golang:$GO_VERSION

# gotoolchain
# https://go.dev/doc/toolchain
export GOSUMDB="sum.golang.org"
export GOTOOLCHAIN=go${GO_VERSION}

# force go modules
export GO111MODULE=on

echo $GO_IMAGE
4 changes: 4 additions & 0 deletions hack/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ if [[ "${CREATE_TEST_ROLE}" = "true" ]]; then
TEST_ROLE_ARN="$(echo ${create_role_output} | jq -r '.Role.Arn')"
fi

source hack/setup-go.sh

go version

make clean
make bin

Expand Down
31 changes: 31 additions & 0 deletions hack/test-unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Copyright 2016 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.

set -o errexit
set -o pipefail
set -o nounset

# cd to the repo root and setup go
REPO_ROOT="$(cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd)"

source hack/setup-go.sh

pushd ${REPO_ROOT}

go version
go test -v -coverprofile=coverage.out -race sigs.k8s.io/aws-iam-authenticator/pkg/...
go tool cover -html=coverage.out -o coverage.html
popd
Loading