Below is a simple script to deploy a Docker image to ECR…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| set -e
log () {
local bold=$(tput bold)
local normal=$(tput sgr0)
echo "${bold}${1}${normal}" 1>&2;
}
if [ -z "${AWS_ACCOUNT}" ];
then
log "Missing a valid AWS_ACCOUNT env variable";
exit 1;
else
log "Using AWS_ACCOUNT '${AWS_ACCOUNT}'";
fi
AWS_REGION=${AWS_REGION:-us-east-1}
REPO_NAME=${REPO_NAME:-my/repo}
log "๐ Authenticating..."
aws ecr get-login-password \
--region ${AWS_REGION} \
| docker login \
--username AWS \
--password-stdin \
${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com
log "๐ฆ Building image..."
docker build -t ${REPO_NAME} .
log "๐ท๏ธ Tagging image..."
docker tag \
${REPO_NAME}:latest \
${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/${REPO_NAME}:latest
log "๐ Pushing to ECR repo..."
docker push \
${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com/${REPO_NAME}:latest
log "๐ Deployment Successful. ๐บ"
|