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

support ecr login with v1 and v2 aws cli versions across repo #312

Merged
merged 1 commit into from
Jul 6, 2020
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
20 changes: 15 additions & 5 deletions examples/apps/colorapp/src/colorteller/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
# vim:syn=sh:ts=4:sw=4:et:ai
#!/bin/bash

set -ex
set -eo pipefail

if [ -z $AWS_ACCOUNT_ID ]; then
echo "AWS_ACCOUNT_ID environment variable is not set."
Expand All @@ -14,12 +13,23 @@ if [ -z $AWS_DEFAULT_REGION ]; then
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
COLOR_TELLER_IMAGE=${COLOR_TELLER_IMAGE:-"${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/colorteller"}
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
COLOR_TELLER_IMAGE=${COLOR_TELLER_IMAGE:-"${ECR_URL}/colorteller"}
GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

# build
docker build --build-arg GO_PROXY=$GO_PROXY -t $COLOR_TELLER_IMAGE ${DIR}

# push
$(aws ecr get-login --no-include-email)
ecr_login
docker push $COLOR_TELLER_IMAGE
15 changes: 13 additions & 2 deletions examples/apps/colorapp/src/gateway/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ if [ -z $AWS_DEFAULT_REGION ]; then
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
COLOR_GATEWAY_IMAGE=${COLOR_GATEWAY_IMAGE:-"${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/gateway"}
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
COLOR_GATEWAY_IMAGE=${COLOR_GATEWAY_IMAGE:-"${ECR_URL}/gateway"}
GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

# build
docker build --build-arg GO_PROXY=$GO_PROXY -t $COLOR_GATEWAY_IMAGE ${DIR}

# push
$(aws ecr get-login --no-include-email)
ecr_login
docker push $COLOR_GATEWAY_IMAGE
19 changes: 15 additions & 4 deletions walkthroughs/howto-alb/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ fi

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
PROJECT_NAME="howto-alb"
ECR_IMAGE_PREFIX=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${PROJECT_NAME}
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX="${ECR_URL}/${PROJECT_NAME}"
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

deploy_images() {
ecr_login
for app in colorapp feapp; do
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app >/dev/null
docker build -t ${ECR_IMAGE_PREFIX}/${app} ${DIR}/${app}
$(aws ecr get-login --no-include-email)
docker push ${ECR_IMAGE_PREFIX}/${app}
done
}
Expand Down Expand Up @@ -94,7 +105,7 @@ delete_images() {
echo "deleting repository..."
aws ecr delete-repository \
--repository-name $PROJECT_NAME/$app \
--force
--force >/dev/null
done
}

Expand Down
18 changes: 15 additions & 3 deletions walkthroughs/howto-ecs-basics/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,33 @@ if [ -z $ENVOY_IMAGE ]; then
fi

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

PROJECT_NAME="$(basename ${DIR})"
STACK_NAME="appmesh-${PROJECT_NAME}"
ECR_IMAGE_PREFIX=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${PROJECT_NAME}
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX=${ECR_URL}/${PROJECT_NAME}
CW_AGENT_IMAGE="${ECR_IMAGE_PREFIX}/cwagent:$(git log -1 --format=%h src/cwagent)"
COLOR_APP_IMAGE="${ECR_IMAGE_PREFIX}/colorapp:$(git log -1 --format=%h src/colorapp)"
FRONT_APP_IMAGE="${ECR_IMAGE_PREFIX}/feapp:$(git log -1 --format=%h src/feapp)"
GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

# deploy_images builds and pushes docker images for colorapp and feapp to ECR
deploy_images() {
for f in cwagent colorapp feapp; do
aws ecr describe-repositories --repository-name ${PROJECT_NAME}/${f} >/dev/null 2>&1 || aws ecr create-repository --repository-name ${PROJECT_NAME}/${f}
aws ecr describe-repositories --repository-name ${PROJECT_NAME}/${f} >/dev/null 2>&1 || aws ecr create-repository --repository-name ${PROJECT_NAME}/${f} >/dev/null
done

$(aws ecr get-login --no-include-email)
ecr_login
docker build -t ${CW_AGENT_IMAGE} ${DIR}/src/cwagent && docker push ${CW_AGENT_IMAGE}
docker build -t ${COLOR_APP_IMAGE} --build-arg GO_PROXY=${GO_PROXY} ${DIR}/src/colorapp && docker push ${COLOR_APP_IMAGE}
docker build -t ${FRONT_APP_IMAGE} --build-arg GO_PROXY=${GO_PROXY} ${DIR}/src/feapp && docker push ${FRONT_APP_IMAGE}
Expand Down
19 changes: 15 additions & 4 deletions walkthroughs/howto-grpc/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ if [ -z $KEY_PAIR ]; then
exit 1
fi

AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
ECR_IMAGE_PREFIX=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${PROJECT_NAME}
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX=${ECR_URL}/${PROJECT_NAME}

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

deploy_images() {
echo "Deploying Color Client and Color Server images to ECR..."
ecr_login
for app in color_client color_server; do
aws ecr describe-repositories --repository-name ${PROJECT_NAME}/${app} >/dev/null 2>&1 || aws ecr create-repository --repository-name ${PROJECT_NAME}/${app}
aws ecr describe-repositories --repository-name ${PROJECT_NAME}/${app} >/dev/null 2>&1 || aws ecr create-repository --repository-name ${PROJECT_NAME}/${app} >/dev/null
docker build -t ${ECR_IMAGE_PREFIX}/${app} ${DIR}/${app} --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
$(aws ecr get-login --no-include-email)
docker push ${ECR_IMAGE_PREFIX}/${app}
done
}
Expand Down Expand Up @@ -112,7 +123,7 @@ delete_images() {
echo "deleting repository \"${app}\"..."
aws ecr delete-repository \
--repository-name $PROJECT_NAME/$app \
--force
--force >/dev/null
done
}

Expand Down
22 changes: 17 additions & 5 deletions walkthroughs/howto-http-headers/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ if [ -z $ENVOY_IMAGE ]; then
exit 1
fi

AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
PROJECT_NAME="howto-http-headers"
ECR_IMAGE_PREFIX=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${PROJECT_NAME}

ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX=${ECR_URL}/${PROJECT_NAME}

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

deploy_images() {
ecr_login
for app in colorapp feapp; do
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app >/dev/null
docker build -t ${ECR_IMAGE_PREFIX}/${app} ${DIR}/${app}
$(aws ecr get-login --no-include-email)
docker push ${ECR_IMAGE_PREFIX}/${app}
done
}
Expand Down Expand Up @@ -66,10 +78,10 @@ delete_images() {

aws ecr batch-delete-image \
--repository-name $PROJECT_NAME/$app \
--image-ids imageDigest=$image_digest
--image-ids imageDigest=$image_digest >/dev/null

aws ecr delete-repository \
--repository-name $PROJECT_NAME/$app
--repository-name $PROJECT_NAME/$app >/dev/null
done
}

Expand Down
20 changes: 16 additions & 4 deletions walkthroughs/howto-http-retries/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,27 @@ if [ -z $ENVOY_IMAGE ]; then
exit 1
fi


AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
PROJECT_NAME="howto-http-retries"
ECR_IMAGE_PREFIX=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${PROJECT_NAME}
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX=${ECR_URL}/${PROJECT_NAME}

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

deploy_images() {
ecr_login
for app in colorapp feapp; do
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app >/dev/null
docker build -t ${ECR_IMAGE_PREFIX}/${app} ${DIR}/${app}
$(aws ecr get-login --no-include-email)
docker push ${ECR_IMAGE_PREFIX}/${app}
done
}
Expand Down Expand Up @@ -62,7 +74,7 @@ delete_images() {
echo "deleting repository..."
aws ecr delete-repository \
--repository-name $PROJECT_NAME/$app \
--force
--force >/dev/null
done
}

Expand Down
19 changes: 15 additions & 4 deletions walkthroughs/howto-http2/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,25 @@ if [ -z $KEY_PAIR ]; then
fi

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
ECR_IMAGE_PREFIX=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${PROJECT_NAME}
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX="${ECR_URL}/${PROJECT_NAME}"
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

deploy_images() {
echo "Deploying Color Client and Color Server images to ECR..."
ecr_login
for app in color_client color_server; do
aws ecr describe-repositories --repository-name ${PROJECT_NAME}/${app} >/dev/null 2>&1 || aws ecr create-repository --repository-name ${PROJECT_NAME}/${app}
aws ecr describe-repositories --repository-name ${PROJECT_NAME}/${app} >/dev/null 2>&1 || aws ecr create-repository --repository-name ${PROJECT_NAME}/${app} >/dev/null
docker build -t ${ECR_IMAGE_PREFIX}/${app} ${DIR}/${app} --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}
$(aws ecr get-login --no-include-email)
docker push ${ECR_IMAGE_PREFIX}/${app}
done
}
Expand Down Expand Up @@ -112,7 +123,7 @@ delete_images() {
echo "deleting repository \"${app}\"..."
aws ecr delete-repository \
--repository-name $PROJECT_NAME/$app \
--force
--force >/dev/null
done
}

Expand Down
15 changes: 5 additions & 10 deletions walkthroughs/howto-ingress-gateway/src/colorteller/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@ if [ -z $COLOR_TELLER_IMAGE_NAME ]; then
fi

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"

IMAGE="${ECR_URL}/${COLOR_TELLER_IMAGE_NAME}:latest"

# build
docker build -t $IMAGE $DIR --build-arg GO_PROXY=${GO_PROXY:-"https://proxy.golang.org"}

# ECR login
# login
AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)

if [ $AWS_CLI_VERSION -eq 1 ]; then
$(aws ecr get-login --no-include-email)
elif [ $AWS_CLI_VERSION -eq 2 ]; then
aws ecr get-login-password | docker login --username AWS --password-stdin ${ECR_URL}
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
echo "Invalid AWS CLI version"
exit 1
$(aws ecr get-login --no-include-email)
fi

# push
Expand Down
17 changes: 14 additions & 3 deletions walkthroughs/howto-k8s-alb/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ if [ -z $ENVOY_IMAGE ]; then
exit 1
fi

AWS_CLI_VERSION=$(aws --version 2>&1 | cut -d/ -f2 | cut -d. -f1)
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
PROJECT_NAME="$(basename ${DIR})"
APP_NAMESPACE=${PROJECT_NAME}
MESH_NAME=${PROJECT_NAME}

ECR_IMAGE_PREFIX="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${PROJECT_NAME}"
ECR_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
ECR_IMAGE_PREFIX="${ECR_URL}/${PROJECT_NAME}"
FRONT_APP_IMAGE="${ECR_IMAGE_PREFIX}/feapp"
COLOR_APP_IMAGE="${ECR_IMAGE_PREFIX}/colorapp"
MANIFEST_VERSION="${1:-v1beta2}"
Expand Down Expand Up @@ -73,11 +75,20 @@ check_appmesh_k8s() {
fi
}

ecr_login() {
if [ $AWS_CLI_VERSION -gt 1 ]; then
aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | \
docker login --username AWS --password-stdin ${ECR_URL}
else
$(aws ecr get-login --no-include-email)
fi
}

deploy_images() {
ecr_login
for app in colorapp feapp; do
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app
aws ecr describe-repositories --repository-name $PROJECT_NAME/$app >/dev/null 2>&1 || aws ecr create-repository --repository-name $PROJECT_NAME/$app >/dev/null
docker build -t ${ECR_IMAGE_PREFIX}/${app} ${DIR}/${app}
$(aws ecr get-login --no-include-email)
docker push ${ECR_IMAGE_PREFIX}/${app}
done
}
Expand Down
Loading