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 ebceb736..cd23a192 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -26,7 +26,26 @@ jobs: git secrets --register-aws git secrets --scan-history - build: + cross-compile: + runs-on: 'ubuntu-22.04' + 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 + + unit-test: strategy: matrix: go: ['1.19', '1.20', '1.21'] @@ -37,7 +56,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: @@ -45,22 +64,4 @@ jobs: - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - - 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 test 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 diff --git a/Dockerfile b/scripts/install_deps.sh old mode 100644 new mode 100755 similarity index 59% rename from Dockerfile rename to scripts/install_deps.sh index e1ec75c0..634b6509 --- a/Dockerfile +++ b/scripts/install_deps.sh @@ -1,20 +1,25 @@ -# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. +#!/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/ +# 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 +# A POSIX shell script which installs the required dependencies +# to build the Amazon ECR credential helper variants in a Golang +# Alpine container. -COPY . . +set -ex -CMD make +apk add --no-cache \ + bash \ + git \ + make \ No newline at end of file