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

Refactor and update build CI #784

Merged
merged 3 commits into from
Apr 23, 2024
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
1 change: 1 addition & 0 deletions .codebuild/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 21 additions & 20 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -37,30 +56,12 @@ 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:
- uses: actions/checkout@v4
- 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
33 changes: 13 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions Dockerfile → scripts/install_deps.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
Loading