#!/bin/bash # Copyright 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. # Run a local registry on the 'well known' port 51670 if it is not running. # Also push images we will need to it. set -ex REGISTRY_IMAGE="public.ecr.aws/docker/library/registry:2.7.1" ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd ) cd "${ROOT}" REGISTRY_CONTAINER_NAME="test-ecs-registry" echo "Removing $REGISTRY_CONTAINER_NAME" # stop and remove the registry container. The script will not exit if the container is not running docker stop "$REGISTRY_CONTAINER_NAME" || true && docker rm "$REGISTRY_CONTAINER_NAME" || true echo "Running $REGISTRY_CONTAINER_NAME" docker run -d --name="$REGISTRY_CONTAINER_NAME" -e SETTINGS_FLAVOR=local -p "127.0.0.1:51670:5000" "${REGISTRY_IMAGE}" # give the registry some seconds to get ready for pushes sleep 7 mirror_local_image() { echo "Mirroring $1" docker tag $1 $2 docker push $2 docker rmi $2 } for image in "amazon/amazon-ecs-netkitten" "amazon/amazon-ecs-volumes-test" \ "amazon/image-cleanup-test-image1" "amazon/image-cleanup-test-image2" \ "amazon/image-cleanup-test-image3" "amazon/amazon-ecs-exec-command-agent-test"; do mirror_local_image "${image}:make" "127.0.0.1:51670/${image}:latest" done if [[ "$(uname -m)" == "x86_64" ]]; then mirror_local_image "amazon/fluentd:make" "127.0.0.1:51670/amazon/fluentd:latest" fi # 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 amazon/image-cleanup-test-image2:make amazon/image-cleanup-test-image3:make mirror_local_image public.ecr.aws/docker/library/busybox:1.34.1 "127.0.0.1:51670/busybox:latest" # create a context folder used by docker build. It will only have a file # full of random bits so that the parallel pull images are different. mkdir -p docker-context cat << EOF > docker-context/Dockerfile FROM amazon/amazon-ecs-pause:0.1.0 ADD random-bits /random-bits EOF # cleanup the context rm -rf docker-context