-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild_and_upload.sh
executable file
·51 lines (43 loc) · 1.07 KB
/
build_and_upload.sh
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
#!/usr/bin/env sh
require() {
command -v "$1" > /dev/null 2>&1 || {
echo "Some of the required software is not installed:"
echo " please install $1" >&2;
exit 4;
}
}
get_url() {
REPO_NAME=$1
OUT=$(aws ecr describe-repositories --repository-name=$REPO_NAME 2> /dev/null || echo "{}")
echo $OUT | jq -r ".repositories[0].repositoryUri"
}
create_repo() {
REPO_NAME=$1
echo "Creating ECR repository $REPO_NAME"
aws ecr create-repository --repository-name $REPO_NAME
}
build () {
echo "Building docker image for tag $1"
docker build --pull -t $1 $2
}
upload () {
echo "Pushing $1 image"
docker push $1
}
set -e
require jq
require aws
REPO_NAME=${1-mainnet-parity}
REPO_URL=$(get_url $REPO_NAME)
if [ $REPO_URL == "null" ]; then
create_repo $REPO_NAME
REPO_URL=$(get_url $REPO_NAME)
if [ $REPO_URL == "null" ]; then
echo "Failed to create repository $REPO_NAME"; exit 4
fi
fi
BUILD_PATH=./docker
`aws ecr get-login --no-include-email`
TAG="$REPO_URL:latest"
build $TAG $BUILD_PATH
upload $TAG