This repository has been archived by the owner on Nov 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart-halfpipe.sh
executable file
·103 lines (86 loc) · 2.85 KB
/
start-halfpipe.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
#!/bin/bash
set -e # exit after any failure
HP_VERSION=2
ORA_VERSION=19.5
K8S_VERSION=v1.13.1 # include k8s leading 'v'
image_name=halfpipe
script_dir=`dirname $0`
build_dir="${script_dir}/image"
image_tag=${HP_VERSION}
image_already_built=`docker images --filter=reference=${image_name}:${image_tag} -q | wc -l`
default_port=8080
default_aws_profile=halfpipe
usage() {
cat <<EOF 1>&2
Usage: $0 [ -a <AWS profile name> ] [-b] [-k] [-p <port>]"
Start Halfpipe in a Docker container preconfigured with Oracle Instant Client ${ORA_VERSION}
where:
-a supplies a profile name found in '$HOME/.aws/credentials'
to set AWS access keys in the container (default: ${default_aws_profile})
-b forces a Docker image build, else it will build once and run image: $image_name:$image_tag
-k mounts directory '$HOME/.kube' into the container so you can launch
Kubernetes jobs easily
-p port to expose for Halfpipe's micro-service used by 'hp pipe' commands
(default: $default_port)
EOF
exit 1
}
while getopts ":a:fbkp:" o; do
case "${o}" in
a)
aws_profile=${OPTARG};;
b)
build_requested=1;;
k)
kube=1;;
p)
port=${OPTARG};;
*)
usage;;
esac
done
shift $((OPTIND-1))
if [[ -z "${aws_profile}" ]]; then # if the profile has NOT been set...
aws_profile="${default_aws_profile}" # use the default.
fi
if [[ "$kube" -eq 1 ]]; then # if we should mount ~/.kube/config...
if [[ -d "$HOME/.kube" ]]; then # if the directory exists...
# Get ready to mount the directory.
kube_mount="-v \"$HOME/.kube\":/home/dataops/.kube"
else # else there is no .kube directory...
# Abort.
echo "Error: \"$HOME/.kube\" directory not found and -k flag specified"
usage
fi
fi
if [[ -z "$port" ]]; then # if the port has NOT been set...
port=$default_port
fi
# Build Halfpipe.
if [[ "$build_requested" -eq 1 || "$image_already_built" -ne 1 ]]; then # if we should build halfpipe...
cmd="docker build \\
--build-arg HP_VERSION=${HP_VERSION} \\
--build-arg ORA_VERSION=${ORA_VERSION} \\
--build-arg K8S_VERSION=${K8S_VERSION} \\
-t ${image_name}:${image_tag} \\
\"${build_dir}\""
echo "${cmd}"
eval "${cmd}"
fi
# Create if not exists the halfpipe home dir.
mkdir -p ~/.halfpipe
# Add defaults for the first time.
if [[ ! -f "$HOME/.halfpipe/config.yaml" ]]; then # if there are no existing config defaults...
echo "Using default config file config.yaml"
cp "${script_dir}/.default-config.yaml" "$HOME/.halfpipe/config.yaml"
fi
# Start Halfpipe container.
echo "Starting ${image_name}:${image_tag} using AWS profile \"${aws_profile}\"..."
cmd="docker run -ti --rm \\
-v ~/.halfpipe:/home/dataops/.halfpipe \\
-v ~/.aws:/home/dataops/.aws \\
-e AWS_PROFILE=\"${aws_profile}\" \\
${kube_mount} \\
-p ${port}:8080 \\
${image_name}:${image_tag}"
eval "$cmd"