forked from johnfonner/abaco-cli
-
Notifications
You must be signed in to change notification settings - Fork 3
/
abaco-init.sh
executable file
·147 lines (126 loc) · 2.86 KB
/
abaco-init.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
THIS=$(basename $0)
THIS=${THIS%.sh}
THIS=${THIS//[-]/ }
function usage() {
echo "$HELP"
exit 0
}
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$DIR/abaco-common.sh"
HELP="
Usage: ${THIS} [OPTION]... [IMAGE]
Initializes an Abaco actor project in a new directory.
The default value for -O can be changed by setting the
DOCKER_HUB_ORG environment variable (e.g. DOCKER_HUB_ORG=tacc).
Options:
-h show help message
-n project name (e.g. my-actor-name)
-d project description
-l project type (python3)
-O registry username/organization (${REGISTRY_USERNAME})
-B base path (current directory)
"
name=
description=
repo=
lang=
tenant=
uorg=${REGISTRY_USERNAME}
basepath="./"
function slugify() {
$DIR/slugify.py "${1}"
}
while getopts ":hl:n:B:d:i:O:" o; do
case "${o}" in
n) # name
name=${OPTARG}
;;
d) # description
description=${OPTARG}
;;
l) # language
lang=${OPTARG}
;;
B) # basepath
basepath=${OPTARG}
;;
O) # container reg username or org
uorg=${OPTARG}
;;
h | *) # print help text
usage
;;
esac
done
shift $((OPTIND - 1))
repo="$1"
if [ -z "${name}" ]; then
usage
fi
# URL-safen name
safename=$(slugify "${name}")
if [ "$safename" != "$name" ]; then
info "Making project name URL safe: $safename"
name="$safename"
fi
# Ensure directory $name is doens't exist yet
if [ ! -d "${basepath}/${name}" ]; then
mkdir -p "${basepath}/${name}"
else
die "Directory $name exists at ${basepath}"
fi
# Template language - default Python2
if [ -z "${lang}" ]; then
lang="python3"
info "Defaulting to Python 3"
fi
# set repo to name if not passed by user
# else, check user-passed repo is valid (slugify)
if [ -z "${repo}" ]; then
repo=${name}
else
saferepo=$(slugify $repo)
if [ "$saferepo" != "$repo" ]; then
info "Making repo name URL safe: $saferepo"
repo="$saferepo"
fi
fi
# Get tenant ID
if [ -f "${AGAVE_AUTH_CACHE}" ]; then
tenant=${TENANTID}
else
die "Can't determine TACC.cloud tenant"
fi
# Copy in template
if [ -d "$DIR/templates/$tenant/$lang" ]; then
if [ ! -f "$DIR/templates/$tenant/$lang/placeholder" ]; then
cp -R ${DIR}/templates/${tenant}/${lang}/ ${basepath}/${name}/
else
die "Template support for ${lang} is not yet implemented."
fi
else
rm -rf ${name}
die "Error creating project directory ${name}"
fi
# Template out the reactor.rc file
cat <<EOF >"${basepath}/${name}/reactor.rc"
# Reactor mandatory settings
REACTOR_NAME=${name}
REACTOR_DESCRIPTION="${description}"
REACTOR_TOKENS=1
REACTOR_PRIVILEGED=
REACTOR_USE_UID=
REACTOR_STATEFUL=
# Docker settings
DOCKER_HUB_ORG=${uorg}
DOCKER_IMAGE_TAG=${repo}
DOCKER_IMAGE_VERSION=0.0.1
EOF
if ((git_cli_avail)); then
info "Initializing ${name} as git repo..."
OWD=${PWD}
cd ${basepath}/${name} && git init && cd ${OWD}
fi
info "Complete: ${basepath}${name}"
exit 0