Skip to content

Commit

Permalink
Adds back Dockerfile for local builds
Browse files Browse the repository at this point in the history
This commit reverts the removal of the repositories Dockerfile for local
builds. The container was helpful for users which need to build the
credential helper from source but do not have an environment to do so.

In addition to the revert, this chance adds dependabot configuration to
update the base image for the container and reworks the docker make
target to build artifacts with correct user permissions.

Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez committed Apr 24, 2024
1 parent 8fda210 commit 2b9fe9c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .codebuild/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ phases:
install:
commands:
- chmod +x -R scripts
- ./scripts/install_deps.sh
- ./scripts/container_init.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
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ updates:
directory: "/"
schedule:
interval: "daily"

# Base image in Dockerfile
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
14 changes: 1 addition & 13 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,10 @@ jobs:
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
run: make all-variants-in-docker

unit-test:
strategy:
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.

FROM public.ecr.aws/docker/library/golang:1.21-alpine

WORKDIR /go/src/github.com/awslabs/amazon-ecr-credential-helper

COPY ./scripts/container_init.sh /setup/container_init.sh

RUN /setup/container_init.sh

14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ SOURCEDIR=./ecr-login
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
VERSION := $(shell cat VERSION)
GITFILES := $(shell test -d .git && find ".git/" -type f)
UID:=$(shell id -u)
GID:=$(shell id -g)

BINPATH:=$(abspath ./bin)
BINARY_NAME=docker-credential-ecr-login
Expand All @@ -31,6 +33,18 @@ 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: docker
docker: build-in-docker

%-in-docker:
docker run --rm \
--user $(UID):$(GID) \
--env TARGET_GOOS=$(TARGET_GOOS) \
--env TARGET_GOARCH=$(TARGET_GOARCH) \
--volume $(ROOT):/go/src/github.com/awslabs/amazon-ecr-credential-helper \
$(shell docker build -q .) \
make $(subst -in-docker,,$@)

.PHONY: build
build: $(LOCAL_BINARY)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ go install github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-
```

If you already have Docker environment, just clone this repository anywhere
and run `make docker`. This command builds the binary with Go inside the Docker
and run `make build-in-docker`. This command builds the binary with Go inside the Docker
container and output it to local directory.

With `TARGET_GOOS` environment variable, you can also cross compile the binary.
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ GOOS=${TARGET_GOOS:-} GOARCH=${TARGET_GOARCH:-} CGO_ENABLED=0 \
-a \
-ldflags "-buildid= -s ${version_ldflags}" \
-trimpath \
-o ../$1/docker-credential-ecr-login \
-o $1/docker-credential-ecr-login \
./cli/docker-credential-ecr-login
4 changes: 2 additions & 2 deletions scripts/build_variant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export TARGET_GOARCH="$2"
ECR_LOGIN_VERSION="$3"
ECR_LOGIN_GITCOMMIT_SHA="$4"

./scripts/build_binary.sh "./bin/${TARGET_GOOS}-${TARGET_GOARCH}" $ECR_LOGIN_VERSION $ECR_LOGIN_GITCOMMIT_SHA
./scripts/build_binary.sh "${ROOT}/bin/${TARGET_GOOS}-${TARGET_GOARCH}" $ECR_LOGIN_VERSION $ECR_LOGIN_GITCOMMIT_SHA

echo "Built ecr-login for ${TARGET_GOOS}-${TARGET_GOARCH}-${ECR_LOGIN_VERSION}"
echo "Built ecr-login for ${TARGET_GOOS}-${TARGET_GOARCH}-${ECR_LOGIN_VERSION}"
9 changes: 7 additions & 2 deletions scripts/install_deps.sh → scripts/container_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# 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
Expand All @@ -22,4 +22,9 @@ set -ex
apk add --no-cache \
bash \
git \
make
make

# Resolves permission issues for Go cache when
# building credential helper as non-root user.
mkdir /.cache && chmod 777 /.cache

0 comments on commit 2b9fe9c

Please sign in to comment.