Skip to content

Commit

Permalink
separate images upload and replicate
Browse files Browse the repository at this point in the history
  • Loading branch information
yumex93 authored and adnxn committed Oct 17, 2018
1 parent 102f0b8 commit 6fbfe6e
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 134 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
USERID=$(shell id -u)
GO_EXECUTABLE=$(shell command -v go 2> /dev/null)

.PHONY: all gobuild static docker release certs test clean netkitten test-registry run-functional-tests benchmark-test gogenerate run-integ-tests pause-container get-cni-sources cni-plugins test-artifacts build-image-for-ecr ecr-execution-role-image-for-upload
.PHONY: all gobuild static docker release certs test clean netkitten test-registry run-functional-tests benchmark-test gogenerate run-integ-tests pause-container get-cni-sources cni-plugins test-artifacts

all: docker

Expand Down Expand Up @@ -183,12 +183,19 @@ test-in-docker:
run-functional-tests: testnnp test-registry ecr-execution-role-image telemetry-test-image
. ./scripts/shared_env && go test -tags functional -timeout=30m -v ./agent/functional_tests/...

.PHONY: build-image-for-ecr ecr-execution-role-image-for-upload upload-images replicate-images

build-image-for-ecr: netkitten volumes-test squid awscli image-cleanup-test-images fluentd taskmetadata-validator testnnp container-health-check-image telemetry-test-image ecr-execution-role-image-for-upload
@./scripts/setup-ecr

ecr-execution-role-image-for-upload:
$(MAKE) -C misc/ecr-execution-role-upload $(MFLAGS)

upload-images: build-image-for-ecr
@./scripts/upload-images $(STANDARD_REGION) $(STANDARD_REPOSITORY)

replicate-images: build-image-for-ecr
@./scripts/upload-images $(REPLICATE_REGION) $(REPLICATE_REPOSITORY)

PAUSE_CONTAINER_IMAGE = "amazon/amazon-ecs-pause"
PAUSE_CONTAINER_TAG = "0.1.0"
PAUSE_CONTAINER_TARBALL = "amazon-ecs-pause.tar"
Expand Down
11 changes: 11 additions & 0 deletions buildspec-ecr-replication.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 0.2

phases:
pre_build:
commands:
- echo Checking versions...
- aws --version
- docker version
build:
commands:
- make replicate-images
5 changes: 2 additions & 3 deletions buildspec-ecr-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- echo Checking versions...
- aws --version
- docker version
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
build:
commands:
- make build-image-for-ecr
- make upload-images
129 changes: 0 additions & 129 deletions scripts/setup-ecr

This file was deleted.

105 changes: 105 additions & 0 deletions scripts/upload-images
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
# Copyright 2018 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.
#
# The script is to upload linux images used by integration tests and functional
# tests to ECR

set -ex

NAMESPACE="linux"
REGION=$1
REPOSITORY=$2
PREFIX="${REPOSITORY}/${NAMESPACE}"
echo "${PREFIX}"

if [ -z "${REGION}" ] \
|| [ -z "${REPOSITORY}" ]; then
echo "Needs to input REGION and REPOSITORY"
exit 1
fi

mirror_image() {
docker pull $1
mirror_local_image $@
}

mirror_local_image() {
docker tag $1 $2
docker push $2
docker rmi $2
}

if [ "${REGION}" == "cn-north-1" ] || [ "${REGION}" == "cn-northwest-1" ]; then
export AWS_ACCESS_KEY_ID=${ACCESS_KEY}
export AWS_SECRET_ACCESS_KEY=${SECRET_KEY}
export AWS_DEFAULT_REGION=${REGION}
fi

ECR_ROLE_IMAGE="executionrole"

BUSYBOX_IMAGE="busybox@sha256:5551dbdfc48d66734d0f01cafee0952cb6e8eeecd1e2492240bf2fd9640c2279"
NGINX_IMAGE="nginx@sha256:0324afc5c8191616576f7b23b297d001609726a2f1b6561c90e229e54ab701cf"
PYTHON2_IMAGE="python@sha256:3a1e82d95d0e75677cdac237b0174425d8ae94dd11d1ef14db73075f1e34c06c"
UBUNTU_IMAGE="ubuntu@sha256:1bea66e185d3464fec1abda32ffaf2a11de69833cfcf81bd2b9a5be147776814"

PARALLEL_PULL_FTS_BUSYBOX=${BUSYBOX_IMAGE}
PARALLEL_PULL_FTS_UBUNTU=${UBUNTU_IMAGE}
PARALLEL_PULL_FTS_NGINX=${NGINX_IMAGE}
PARALLEL_PULL_FTS_CONSUL="consul@sha256:ce15f85417a0cf121d943563dedb873c7d6c26e9b1e8b47bc2f1b5a3e27498e1"
PARALLEL_PULL_FTS_DEBIAN="debian@sha256:f7062cf040f67f0c26ff46b3b44fe036c29468a7e69d8170f37c57f2eec1261b"
PARALLEL_PULL_FTS_HTTPD="httpd@sha256:0d817a924bed1a216f12a0f4947b5f8a2f173bd5a9cebfe1382d024287154c99"
PARALLEL_PULL_FTS_MONGO="mongo@sha256:23e5cdbd9bc26a6d1ae4db8252a295d6bdba8332dec68483816d5b7bb2438d7d"
PARALLEL_PULL_FTS_REDIS="redis@sha256:eed4da4937cb562e9005f3c66eb8c3abc14bb95ad497c03dc89d66bcd172fc7f"
PARALLEL_PULL_FTS_REGISTRY="registry@sha256:946480a23b33480b8e7cdb89b82c1bd6accae91a8e66d017e21e8b56551f6209"


$(aws ecr get-login --region ${AWS_DEFAULT_REGION} --no-include-email)

for image in "amazon-ecs-netkitten" "amazon-ecs-volumes-test" "squid" "awscli" "image-cleanup-test-image1" "image-cleanup-test-image2" "image-cleanup-test-image3" "fluentd" "amazon-ecs-taskmetadata-validator" "amazon-ecs-telemetry-test" "amazon-ecs-containerhealthcheck"; do
# Create the repository if it does not exist
if ! aws ecr describe-repositories --region ${AWS_DEFAULT_REGION}| grep -q "repositoryName\": \"${NAMESPACE}/${image}" ;
then
aws ecr create-repository --region ${AWS_DEFAULT_REGION} --repository-name "${NAMESPACE}/${image}"
fi
mirror_local_image "amazon/${image}:make" "${PREFIX}/${image}:latest"
done


for image in "executionrole" "busybox" "nginx" "python" "ubuntu" "consul" "debian" "httpd" "mongo" "redis" "registry"; do
# Create the repository if it does not exist
if ! aws ecr describe-repositories --region ${AWS_DEFAULT_REGION}| grep -q "repositoryName\": \"${NAMESPACE}/${image}" ;
then
aws ecr create-repository --region ${AWS_DEFAULT_REGION} --repository-name "${NAMESPACE}/${image}"
fi
done

mirror_local_image "amazon/${ECR_ROLE_IMAGE}:fts" "${PREFIX}/${ECR_ROLE_IMAGE}:fts"
mirror_image ${BUSYBOX_IMAGE} "${PREFIX}/busybox:latest"
mirror_image ${NGINX_IMAGE} "${PREFIX}/nginx:latest"
mirror_image ${PYTHON2_IMAGE} "${PREFIX}/python:2"
mirror_image ${UBUNTU_IMAGE} "${PREFIX}/ubuntu:latest"
mirror_image ${PARALLEL_PULL_FTS_BUSYBOX} "${PREFIX}/busybox:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_UBUNTU} "${PREFIX}/ubuntu:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_CONSUL} "${PREFIX}/consul:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_DEBIAN} "${PREFIX}/debian:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_HTTPD} "${PREFIX}/httpd:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_MONGO} "${PREFIX}/mongo:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_NGINX} "${PREFIX}/nginx:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_REDIS} "${PREFIX}/redis:parallel-pull-fts"
mirror_image ${PARALLEL_PULL_FTS_REGISTRY} "${PREFIX}/registry:parallel-pull-fts"

# Remove the tag so this image can be deleted successfully in the docker image cleanup integ tests
docker rmi amazon/image-cleanup-test-image1:make
docker rmi amazon/image-cleanup-test-image2:make
docker rmi amazon/image-cleanup-test-image3:make

0 comments on commit 6fbfe6e

Please sign in to comment.