-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-push-public-aws-image
executable file
·96 lines (84 loc) · 2.06 KB
/
build-push-public-aws-image
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function usage(){
cat 1>&2 <<EOF
Usage: $SCRIPT <tag> <version> [OPTIONS]
DESCRIPTION:
This pushes a local tag to a remote repository, ie: 'docker push public.ecr.aws/<ALIAS>/<TAG>'
POSITIONAL:
tag Tag to push, ex: flipbox/php:80-apache
version Version, matches the directory with a Dockerfile inside ($(ls -d */ | xargs | sed 's#/##g')) and should also match the tag version
OPTIONS:
--alias|-a AWS public profile alias
--profile AWS Profile
--dry-run Dry run
-h|--help Display help
EOF
}
TAG=
ALIAS=l8r9s7z3
VERSION=
PROFILE=
DRY_RUN="NO"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-a|--alias)
ALIAS="$2"
shift # past argument
shift # value
;;
--profile)
PROFILE="--profile $2"
shift # past argument
shift # value
;;
--dry-run)
DRY_RUN="YES"
shift # past argument
;;
-h|--help)
usage;
exit 0;
;;
*) # unknown option
TAG="$1" # save it in an array for later
shift # past argument
VERSION="$1"
shift
;;
esac
done
if [ -z "$TAG" ]; then
echo "<tag> is required (first positional argument)"
usage;
exit 1;
fi
if [ -z "$VERSION" ]; then
echo "<version> is required (second positional argument)"
usage;
exit 1;
fi
if [ -z "$ALIAS" ]; then
echo "--alias is required"
usage;
exit 1;
fi
if [ -z "$PROFILE" ]; then
echo "--profile is required"
usage;
exit 1;
fi
if [ "$DRY_RUN" == "YES" ]; then
echo "DRY-RUN: logging into aws with: $PROFILE"
echo "DRY-RUN: docker buildx build \\"
echo " --platform linux/amd64,linux/arm64 \\"
echo " ${VERSION}/apache --pull -t public.ecr.aws/${ALIAS}/${TAG} --push"
exit 0;
fi
# login to ecr
aws ${PROFILE} ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
# build and push
docker buildx build \
--platform linux/amd64,linux/arm64 \
${VERSION}/apache --pull -t public.ecr.aws/${ALIAS}/${TAG} --push