forked from jackie930/t5-pegasus-textsummary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_and_push.sh
68 lines (55 loc) · 2.36 KB
/
build_and_push.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
set -v
set -e
# This script shows how to build the Docker image and push it to ECR to be ready for use
# by SageMaker.
# The argument to this script is the image name. This will be used as the image on the local
# machine and combined with the account and region to form the repository name for ECR.
image=$1
if [ "$image" == "" ]
then
echo "Use image name pegasus"
image="pegasus"
fi
# Get the account number associated with the current IAM credentials
account=$(aws sts get-caller-identity --query Account --output text)
if [ $? -ne 0 ]
then
exit 255
fi
# Get the region defined in the current configuration
region=$(aws configure get region)
echo ${region}
region=${region:-us-east-1}
#regions=$(aws ec2 describe-regions --all-regions --query "Regions[].{Name:RegionName}" --output text)
#for region in $regions; do
#aws s3 cp s3://aws-solutions-${region}/spot-bot-models/cars/model.tar.gz ./
#tar zxvf model.tar.gz
# TODO: update regional location based on https://amazonaws-china.com/releasenotes/available-deep-learning-containers-images/
if [[ $region =~ ^cn.* ]]
then
fullname="${account}.dkr.ecr.${region}.amazonaws.com.cn/${image}:latest"
registry_id="727897471807"
registry_uri="${registry_id}.dkr.ecr.${region}.amazonaws.com.cn"
elif [[ $region = "ap-east-1" ]]
then
fullname="${account}.dkr.ecr.${region}.amazonaws.com/${image}:latest"
registry_id="871362719292"
registry_uri="${registry_id}.dkr.ecr.${region}.amazonaws.com"
else
fullname="${account}.dkr.ecr.${region}.amazonaws.com/${image}:latest"
registry_id="763104351884"
registry_uri="${registry_id}.dkr.ecr.${region}.amazonaws.com"
fi
echo ${fullname}
# If the repository doesn't exist in ECR, create it.
aws ecr describe-repositories --repository-names "${image}" --region ${region} || aws ecr create-repository --repository-name "${image}" --region ${region}
# Get the login command from ECR and execute it directly
$(aws ecr get-login --registry-ids ${account} --region ${region} --no-include-email)
$(aws ecr get-login --registry-ids ${registry_id} --region ${region} --no-include-email)
# Build the docker image, tag with full name and then push it to ECR
# docker build -t ${image} -f Dockerfile . --build-arg REGISTRY_URI=${registry_uri}
docker build -t ${image} -f Dockerfile . --build-arg REGION=${region}
docker tag ${image} ${fullname}
docker push ${fullname}
#done