-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_push_docker.sh
49 lines (33 loc) · 1.04 KB
/
build_push_docker.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
#!/bin/bash
# build, tag, and push to AWS ECR
if [ $# -ge 1 ]
then
echo "tag specified $1"
tag_read=$1
else
echo "no tag specified. defaulting to latest"
fi
# prerequisites: docker (obviously), awscli configured, and a repo on ECR set up called 'awsgpu'
docker_exec="docker"
# docker_exec="sudo docker" # depending on your setup you may want this
tag="aws_gpu:${tag_read}"
$docker_exec build --tag $tag .
echo "build over at `date`"
while true; do
read -p "continue with push?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo "continuing to push..."
iam_role="YOUR_IAM_ROLE" # fill in
region="us-west-1" # for example
amazon_url="${iam_role}.dkr.ecr.${region}.amazonaws.com"
echo "logging into AWS for docker..."
aws ecr get-login-password --region ${region} | $docker_exec login --username AWS --password-stdin $amazon_url
$docker_exec tag $tag "$amazon_url/$tag"
echo "pushing..."
$docker_exec push "$amazon_url/$tag"
echo "done at `date`"