From f36cf9977667294c84ec071e50e584da58f1dcd1 Mon Sep 17 00:00:00 2001 From: Austin Vazquez Date: Fri, 19 Apr 2024 18:39:21 +0000 Subject: [PATCH 1/3] Cross-compile all variants in container as seperate job This change updates the build CI to cross-compile all variants in a container as part of a seperate job. This enables testing of other platforms to be added. Signed-off-by: Austin Vazquez --- .github/workflows/build.yaml | 27 ++++++++++++--------------- Dockerfile | 20 -------------------- Makefile | 33 +++++++++++++-------------------- 3 files changed, 25 insertions(+), 55 deletions(-) delete mode 100644 Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ebceb736..a8dd6a08 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -26,6 +26,17 @@ jobs: git secrets --register-aws git secrets --scan-history + cross-compile: + runs-on: 'ubuntu-22.04' + container: public.ecr.aws/docker/library/golang:1.19 + steps: + - uses: actions/checkout@v4 + with: + path: src/github.com/awslabs/amazon-ecr-credential-helper + - name: Cross-compile all variants + run: make all-variants + working-directory: src/github.com/awslabs/amazon-ecr-credential-helper + build: strategy: matrix: @@ -48,19 +59,5 @@ jobs: - run: make get-deps if: ${{ matrix.go >= '1.19' }} - # test Dockerfile build on Linux. macOS runners do not ship with Docker - # installed by default whereas Ubuntu runners do. - - name: Build in Dockerfile - run: make docker - if: ${{ matrix.os == 'ubuntu-22.04' }} - - # Apple Silicon is not supported by Go < 1.16. - # https://go.dev/blog/go1.16 - - name: Cross-compile all variants - run: make all-variants - if: ${{ matrix.go >= '1.16' }} - - name: Cross-compile all variants except for Apple Silicon - run: make linux-amd64 linux-arm64 darwin-amd64 windows-amd64 - if: ${{ matrix.go < '1.16' }} - + - run: make - run: make test diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index e1ec75c0..00000000 --- a/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"). You -# may not use this file except in compliance with the License. A copy of -# the License is located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file 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. - -FROM golang:1.19 - -WORKDIR /go/src/github.com/awslabs/amazon-ecr-credential-helper - -COPY . . - -CMD make diff --git a/Makefile b/Makefile index 22d252a7..f08ee47b 100644 --- a/Makefile +++ b/Makefile @@ -19,30 +19,23 @@ SOURCEDIR=./ecr-login SOURCES := $(shell find $(SOURCEDIR) -name '*.go') VERSION := $(shell cat VERSION) GITFILES := $(shell test -d .git && find ".git/" -type f) + +BINPATH:=$(abspath ./bin) BINARY_NAME=docker-credential-ecr-login -LOCAL_BINARY=bin/local/$(BINARY_NAME) - -LINUX_AMD64_BINARY=bin/linux-amd64/$(BINARY_NAME) -LINUX_ARM64_BINARY=bin/linux-arm64/$(BINARY_NAME) -DARWIN_AMD64_BINARY=bin/darwin-amd64/$(BINARY_NAME) -DARWIN_ARM64_BINARY=bin/darwin-arm64/$(BINARY_NAME) -WINDOWS_AMD64_BINARY=bin/windows-amd64/$(BINARY_NAME).exe -WINDOWS_ARM64_BINARY=bin/windows-arm64/$(BINARY_NAME).exe - -.PHONY: docker -docker: Dockerfile GITCOMMIT_SHA - mkdir -p bin - docker run --rm \ - -e TARGET_GOOS=$(TARGET_GOOS) \ - -e TARGET_GOARCH=$(TARGET_GOARCH) \ - -v '$(shell pwd)/bin':/go/src/github.com/awslabs/amazon-ecr-credential-helper/bin \ - $(shell docker build -q .) +LOCAL_BINARY=$(BINPATH)/local/$(BINARY_NAME) + +LINUX_AMD64_BINARY=$(BINPATH)/linux-amd64/$(BINARY_NAME) +LINUX_ARM64_BINARY=$(BINPATH)/linux-arm64/$(BINARY_NAME) +DARWIN_AMD64_BINARY=$(BINPATH)/darwin-amd64/$(BINARY_NAME) +DARWIN_ARM64_BINARY=$(BINPATH)/darwin-arm64/$(BINARY_NAME) +WINDOWS_AMD64_BINARY=$(BINPATH)/windows-amd64/$(BINARY_NAME).exe +WINDOWS_ARM64_BINARY=$(BINPATH)/windows-arm64/$(BINARY_NAME).exe .PHONY: build build: $(LOCAL_BINARY) $(LOCAL_BINARY): $(SOURCES) GITCOMMIT_SHA - ./scripts/build_binary.sh ./bin/local $(VERSION) $(shell cat GITCOMMIT_SHA) + ./scripts/build_binary.sh $(BINPATH)/local $(VERSION) $(shell cat GITCOMMIT_SHA) @echo "Built ecr-login" .PHONY: test @@ -76,13 +69,13 @@ $(DARWIN_ARM64_BINARY): $(SOURCES) GITCOMMIT_SHA windows-amd64: $(WINDOWS_AMD64_BINARY) $(WINDOWS_AMD64_BINARY): $(SOURCES) GITCOMMIT_SHA ./scripts/build_variant.sh windows amd64 $(VERSION) $(shell cat GITCOMMIT_SHA) - @mv ./bin/windows-amd64/$(BINARY_NAME) ./$(WINDOWS_AMD64_BINARY) + @mv $(BINPATH)/windows-amd64/$(BINARY_NAME) $(WINDOWS_AMD64_BINARY) .PHONY: windows-arm64 windows-arm64: $(WINDOWS_ARM64_BINARY) $(WINDOWS_ARM64_BINARY): $(SOURCES) GITCOMMIT_SHA ./scripts/build_variant.sh windows arm64 $(VERSION) $(shell cat GITCOMMIT_SHA) - @mv ./bin/windows-arm64/$(BINARY_NAME) ./$(WINDOWS_ARM64_BINARY) + @mv $(BINPATH)/windows-arm64/$(BINARY_NAME) $(WINDOWS_ARM64_BINARY) GITCOMMIT_SHA: $(GITFILES) git rev-parse --short=7 HEAD > GITCOMMIT_SHA From 7c47254129bea1273ec3c9921ce7b47fab9a96b5 Mon Sep 17 00:00:00 2001 From: Austin Vazquez Date: Sat, 20 Apr 2024 00:20:50 +0000 Subject: [PATCH 2/3] Refactor build job into unit test job Signed-off-by: Austin Vazquez --- .github/workflows/build.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a8dd6a08..1d948569 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,7 +37,7 @@ jobs: run: make all-variants working-directory: src/github.com/awslabs/amazon-ecr-credential-helper - build: + unit-test: strategy: matrix: go: ['1.19', '1.20', '1.21'] @@ -48,7 +48,7 @@ jobs: # Build all variants regardless of failures fail-fast: false - name: ${{ matrix.os }} / Go ${{ matrix.go }} + name: unit-test (${{ matrix.os }} / Go ${{ matrix.go }}) runs-on: ${{ matrix.os }} steps: @@ -56,8 +56,4 @@ jobs: - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - - run: make get-deps - if: ${{ matrix.go >= '1.19' }} - - - run: make - run: make test From 9cd765a847d9952f931b888e959ab754fefe4ea9 Mon Sep 17 00:00:00 2001 From: Austin Vazquez Date: Sat, 20 Apr 2024 01:48:45 +0000 Subject: [PATCH 3/3] Swap to alpine container to minimize dependencies Signed-off-by: Austin Vazquez --- .codebuild/buildspec.yml | 1 + .github/workflows/build.yaml | 10 +++++++++- scripts/install_deps.sh | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 scripts/install_deps.sh diff --git a/.codebuild/buildspec.yml b/.codebuild/buildspec.yml index 6eaf3868..ec8e2ba1 100644 --- a/.codebuild/buildspec.yml +++ b/.codebuild/buildspec.yml @@ -4,6 +4,7 @@ phases: install: commands: - chmod +x -R scripts + - ./scripts/install_deps.sh - ./scripts/hack/codepipeline-git-commit.sh - ./scripts/hack/symlink-gopath-codebuild.sh - cd /go/src/github.com/awslabs/amazon-ecr-credential-helper diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1d948569..cd23a192 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -28,11 +28,19 @@ jobs: cross-compile: runs-on: 'ubuntu-22.04' - container: public.ecr.aws/docker/library/golang:1.19 + container: public.ecr.aws/docker/library/golang:1.21-alpine steps: + # Need to update git before checking out the repository. + # This is a workaround for https://github.com/actions/checkout/issues/335 + # where older git versions would not create the .git folder for the repository. + - name: Update Git + run: apk add --no-cache git - uses: actions/checkout@v4 with: path: src/github.com/awslabs/amazon-ecr-credential-helper + - name: Install dependencies to container + run: ./scripts/install_deps.sh + working-directory: src/github.com/awslabs/amazon-ecr-credential-helper - name: Cross-compile all variants run: make all-variants working-directory: src/github.com/awslabs/amazon-ecr-credential-helper diff --git a/scripts/install_deps.sh b/scripts/install_deps.sh new file mode 100755 index 00000000..634b6509 --- /dev/null +++ b/scripts/install_deps.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file 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. + +# A POSIX shell script which installs the required dependencies +# to build the Amazon ECR credential helper variants in a Golang +# Alpine container. + +set -ex + +apk add --no-cache \ + bash \ + git \ + make \ No newline at end of file