forked from switchablenorms/CelebAMask-HQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·127 lines (108 loc) · 3.22 KB
/
build.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#==============================================================================
#
# build.sh
#
#==============================================================================
#
# Project build script.
#
# Requires the following programs:
#
# docker
# aws-cli
#
# Usage: ./build.sh [-d|--device <cpu|cuda>] <command> <command>
#
# Commands:
#
# dockerInstall - Creates the docker images, installs it in the local repository
# and updates the "latest" tags to point to the images.
#
set -e
DOCKER_USER=aif
DOCKER_IMAGE="celebamask-hq.face_parsing"
DEVICE='cuda'
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#------------------------------------------------------------------------------
# GET AWS CREDS LOCAL
#------------------------------------------------------------------------------
function getAwsCredsLocal() {
local aws_profile
aws_profile="default"
eval $1=$(aws --profile $aws_profile configure get aws_access_key_id)
eval $2=$(aws --profile $aws_profile configure get aws_secret_access_key)
}
#------------------------------------------------------------------------------
# DOCKER INSTALL
#------------------------------------------------------------------------------
function dockerInstall() {
local major
local minor
local patch
local snapshot
local docker_base
local aws_secret
local temp_creds
parseVersion major minor patch snapshot
version="${major}.${minor}.${patch}${snapshot}"
temp_creds=$(mktemp)
if [ "$DEVICE" = "cuda" ]
then
docker_base="nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04"
else
docker_base="ubuntu:18.04"
fi
if [ -f "$HOME/.aws/credentials" ]; then
aws_secret="--secret id=aws_creds,src=$HOME/.aws/credentials"
else
aws_secret="--secret id=aws_creds,src=$temp_creds"
fi
pushd ${SCRIPT_DIR}/face_parsing
DOCKER_BUILDKIT=1 docker build $aws_secret --build-arg BASE_IMAGE="$docker_base" -t ${DOCKER_USER}/${DOCKER_IMAGE}:${version} .
docker tag ${DOCKER_USER}/${DOCKER_IMAGE}:${version} ${DOCKER_USER}/${DOCKER_IMAGE}:latest
popd
rm -f $temp_creds
}
#------------------------------------------------------------------------------
# PARSE VERSION
#------------------------------------------------------------------------------
function parseVersion() {
version=`cat "${SCRIPT_DIR}/VERSION"`
local RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
# MAJOR
eval $1=`echo ${version} | sed -e "s#$RE#\1#"`
# MINOR
eval $2=`echo ${version} | sed -e "s#$RE#\2#"`
# PATCH
eval $3=`echo ${version} | sed -e "s#$RE#\3#"`
# SNAPSHOT
eval $4=`echo ${version} | sed -e "s#$RE#\4#"`
}
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-d|--device)
DEVICE="$2"
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
for i in "$@"
do
case $i in
dockerInstall)
dockerInstall
shift
;;
*)
;;
esac
done