Skip to content

Commit

Permalink
push Docker images to public ECR registry on CI build (localstack#5221)
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer authored Mar 3, 2022
1 parent b9dece1 commit 3efb640
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
37 changes: 30 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,29 +337,52 @@ jobs:
at: /tmp/workspace
- run:
name: Load docker image - amd64/full
command: docker load -i target/localstack-docker-image-amd64.tar
command: |
# Load localstack/localstack-full:latest for AMD64
docker load -i target/localstack-docker-image-amd64.tar
- run:
name: Load docker image - amd64/light
command: docker load -i target/localstack-docker-image-light-amd64.tar
command: |
# Load localstack/localstack-light:latest
docker load -i target/localstack-docker-image-light-amd64.tar
- run:
name: Log in to ECR registry
command: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
- run:
name: Push docker images - amd64
command: PLATFORM="amd64" make docker-push-master
command: |
# Push to Docker Hub
PLATFORM="amd64" make docker-push-master-all
# Push to Amazon Public ECR
PLATFORM="amd64" SOURCE_IMAGE_NAME="localstack/localstack-light" TARGET_IMAGE_NAME="public.ecr.aws/localstack/localstack" make docker-push-master
# Load and push per architecture (load overwrites the previous ones)
- run:
name: Load docker image - arm64/full
command: docker load -i target/localstack-docker-image-arm64.tar
command: |
# Load localstack/localstack-full:latest for ARM64
docker load -i target/localstack-docker-image-arm64.tar
- run:
name: Load docker image - arm64/light
command: docker load -i target/localstack-docker-image-light-arm64.tar
- run:
name: Push docker images - arm64
command: PLATFORM="arm64" make docker-push-master
command: |
# Push to Docker Hub
PLATFORM="arm64" make docker-push-master-all
# Push to Amazon Public ECR
PLATFORM="arm64" SOURCE_IMAGE_NAME="localstack/localstack-light" TARGET_IMAGE_NAME="public.ecr.aws/localstack/localstack" make docker-push-master
- run:
name: Create multi-platform manifests - full
command: make docker-create-push-manifests
command: |
# Push to Docker Hub
make docker-create-push-manifests
- run:
name: Create multi-platform manifests - light
command: make docker-create-push-manifests-light
command: |
# Push to Docker Hub
make docker-create-push-manifests-light
# Push to Amazon Public ECR
MANIFEST_IMAGE_NAME="public.ecr.aws/localstack/localstack" make docker-create-push-manifests
workflows:
main:
Expand Down
46 changes: 18 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IMAGE_NAME ?= localstack/localstack
IMAGE_NAME_LIGHT ?= localstack/localstack-light
IMAGE_NAME_FULL ?= localstack/localstack-full
IMAGE_NAME_LIGHT ?= $(IMAGE_NAME)-light
IMAGE_NAME_FULL ?= $(IMAGE_NAME)-full
IMAGE_TAG ?= $(shell cat localstack/__init__.py | grep '^__version__ =' | sed "s/__version__ = ['\"]\(.*\)['\"].*/\1/")
VENV_BIN ?= python3 -m venv
VENV_DIR ?= .venv
Expand Down Expand Up @@ -113,7 +113,9 @@ docker-build-multiarch: ## Build the Multi-Arch Full Docker Image
# Multi-Platform builds cannot be loaded to the docker daemon from buildx, so we can't add "--load".
make DOCKER_BUILD_FLAGS="--platform linux/amd64,linux/arm64" docker-build

docker-push-master: ## Push Docker image to registry IF we are currently on the master branch
SOURCE_IMAGE_NAME ?= $(IMAGE_NAME_FULL)
TARGET_IMAGE_NAME ?= $(IMAGE_NAME_FULL)
docker-push-master: ## Push a single platform-specific Docker image to registry IF we are currently on the master branch
(CURRENT_BRANCH=`(git rev-parse --abbrev-ref HEAD | grep '^master$$' || ((git branch -a | grep 'HEAD detached at [0-9a-zA-Z]*)') && git branch -a)) | grep '^[* ]*master$$' | sed 's/[* ]//g' || true`; \
test "$$CURRENT_BRANCH" != 'master' && echo "Not on master branch.") || \
((test "$$DOCKER_USERNAME" = '' || test "$$DOCKER_PASSWORD" = '' ) && \
Expand All @@ -124,35 +126,23 @@ docker-push-master: ## Push Docker image to registry IF we are currently on t
echo "This is a fork and not the main repo.") || \
( \
docker info | grep Username || docker login -u $$DOCKER_USERNAME -p $$DOCKER_PASSWORD; \
docker tag $(IMAGE_NAME_LIGHT):latest $(IMAGE_NAME):latest-$(PLATFORM) && \
docker tag $(IMAGE_NAME_LIGHT):latest $(IMAGE_NAME_LIGHT):latest-$(PLATFORM) && \
docker tag $(IMAGE_NAME_FULL):latest $(IMAGE_NAME_FULL):latest-$(PLATFORM) && \
docker tag $(SOURCE_IMAGE_NAME):latest $(TARGET_IMAGE_NAME):latest-$(PLATFORM) && \
((! (git diff HEAD~1 localstack/__init__.py | grep '^+__version__ =') && \
echo "Only pushing tag 'latest' as version has not changed.") || \
(docker tag $(IMAGE_NAME):latest-$(PLATFORM) $(IMAGE_NAME):$(IMAGE_TAG)-$(PLATFORM) && \
docker tag $(IMAGE_NAME):latest-$(PLATFORM) $(IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker tag $(IMAGE_NAME):latest-$(PLATFORM) $(IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) && \
docker tag $(IMAGE_NAME_LIGHT):latest-$(PLATFORM) $(IMAGE_NAME_LIGHT):$(IMAGE_TAG)-$(PLATFORM) && \
docker tag $(IMAGE_NAME_LIGHT):latest-$(PLATFORM) $(IMAGE_NAME_LIGHT):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker tag $(IMAGE_NAME_LIGHT):latest-$(PLATFORM) $(IMAGE_NAME_LIGHT):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) && \
docker tag $(IMAGE_NAME_FULL):latest-$(PLATFORM) $(IMAGE_NAME_FULL):$(IMAGE_TAG)-$(PLATFORM) && \
docker tag $(IMAGE_NAME_FULL):latest-$(PLATFORM) $(IMAGE_NAME_FULL):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker tag $(IMAGE_NAME_FULL):latest-$(PLATFORM) $(IMAGE_NAME_FULL):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) && \
docker push $(IMAGE_NAME):$(IMAGE_TAG)-$(PLATFORM) && \
docker push $(IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker push $(IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) && \
docker push $(IMAGE_NAME_LIGHT):$(IMAGE_TAG)-$(PLATFORM) && \
docker push $(IMAGE_NAME_LIGHT):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker push $(IMAGE_NAME_LIGHT):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) && \
docker push $(IMAGE_NAME_FULL):$(IMAGE_TAG)-$(PLATFORM) && \
docker push $(IMAGE_NAME_FULL):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker push $(IMAGE_NAME_FULL):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) \
(docker tag $(TARGET_IMAGE_NAME):latest-$(PLATFORM) $(TARGET_IMAGE_NAME):$(IMAGE_TAG)-$(PLATFORM) && \
docker tag $(TARGET_IMAGE_NAME):latest-$(PLATFORM) $(TARGET_IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker tag $(TARGET_IMAGE_NAME):latest-$(PLATFORM) $(TARGET_IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) && \
docker push $(TARGET_IMAGE_NAME):$(IMAGE_TAG)-$(PLATFORM) && \
docker push $(TARGET_IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION)-$(PLATFORM) && \
docker push $(TARGET_IMAGE_NAME):$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)-$(PLATFORM) \
)) && \
docker push $(IMAGE_NAME):latest-$(PLATFORM) && \
docker push $(IMAGE_NAME_LIGHT):latest-$(PLATFORM) && \
docker push $(IMAGE_NAME_FULL):latest-$(PLATFORM) \
docker push $(TARGET_IMAGE_NAME):latest-$(PLATFORM) \
)

docker-push-master-all: ## Push Docker images of localstack, localstack-light, and localstack-full
make SOURCE_IMAGE_NAME=$(IMAGE_NAME_LIGHT) TARGET_IMAGE_NAME=$(IMAGE_NAME) docker-push-master
make SOURCE_IMAGE_NAME=$(IMAGE_NAME_LIGHT) TARGET_IMAGE_NAME=$(IMAGE_NAME_LIGHT) docker-push-master
make SOURCE_IMAGE_NAME=$(IMAGE_NAME_FULL) TARGET_IMAGE_NAME=$(IMAGE_NAME_FULL) docker-push-master

MANIFEST_IMAGE_NAME ?= $(IMAGE_NAME_FULL)
docker-create-push-manifests: ## Create and push manifests for a docker image (default: full)
Expand Down Expand Up @@ -284,4 +274,4 @@ clean-dist: ## Clean up python distribution directories
rm -rf dist/ build/
rm -rf *.egg-info

.PHONY: usage venv freeze install-basic install-runtime install-test install-dev install entrypoints init init-testlibs dist publish coveralls start docker-save-image docker-save-image-light docker-build docker-build-light docker-build-multi-platform docker-push-master docker-create-push-manifests docker-create-push-manifests-light docker-run-tests docker-run docker-mount-run docker-build-lambdas docker-cp-coverage test test-coverage test-docker test-docker-mount test-docker-mount-code ci-pro-smoke-tests lint lint-modified format format-modified init-precommit clean clean-dist vagrant-start vagrant-stop infra
.PHONY: usage venv freeze install-basic install-runtime install-test install-dev install entrypoints init init-testlibs dist publish coveralls start docker-save-image docker-save-image-light docker-build docker-build-light docker-build-multi-platform docker-push-master docker-push-master-all docker-create-push-manifests docker-create-push-manifests-light docker-run-tests docker-run docker-mount-run docker-build-lambdas docker-cp-coverage test test-coverage test-docker test-docker-mount test-docker-mount-code ci-pro-smoke-tests lint lint-modified format format-modified init-precommit clean clean-dist vagrant-start vagrant-stop infra

0 comments on commit 3efb640

Please sign in to comment.