-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-build.sh
executable file
·85 lines (74 loc) · 2.32 KB
/
docker-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
#!/usr/bin/env bash
# Used to build/rebuild the Docker container.
VANILLA_GIT_REPO_URL='https://github.com/Haiyang-Sun/nodeprof.js.git'
# Function to print usage.
usage() {
>&2 echo "Usage: ./docker-build.sh [-h|--help] [--repo <repo path>] [--commit <hash>] [--imageName <Docker image name>]"
>&2 echo ""
>&2 echo "If --repo is not specified, it will default to \`vanilla/nodeprof.js\`, and it will be fetched automatically from ${VANILLA_GIT_REPO_URL}."
>&2 echo ""
>&2 echo "If --imageName is not specified, it will default to \`mwaldrich/docker-nodeprof\`."
}
# Default values of variables
DOCKER_NODEPROF_PATH="$(dirname "${BASH_SOURCE[0]}")"
REPO_PATH="${DOCKER_NODEPROF_PATH}/nodeprof-clones/vanilla/nodeprof.js"
CUSTOM_REPO_PATH=0
DOCKER_IMAGE_NAME="mwaldrich/docker-nodeprof"
COMMIT_REV="4cc03cf02e149eaf50f4470fd7d6383c2af72cba"
# Ensure `nodeprof-clones/` exists.
mkdir -p nodeprof-clones
# Parse arguments.
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
usage
exit 0
;;
--repo)
REPO_PATH="$2"
CUSTOM_REPO_PATH=1
shift
shift
;;
--imageName)
DOCKER_IMAGE_NAME="$2"
shift
shift
;;
--commit)
COMMIT_REV="$2"
shift
shift
;;
# Unknown argument
*)
usage
exit 1
;;
esac
done
# If the user didn't specify a custom NodeProf repository path,
# assume they wanted to use the default version.
# We will now ensure this repo exists and is up to date.
if [[ $CUSTOM_REPO_PATH = 0 ]]; then
GIT_REPO=$VANILLA_GIT_REPO_URL
REPO_NAME=nodeprof.js
LOCAL_LOCATION=nodeprof-clones/vanilla
REPO_PATH="${LOCAL_LOCATION}/${REPO_NAME}"
# Actually clone NodeProf.
mkdir -p $LOCAL_LOCATION
# Clone/pull from the repository as necessary.
if [ ! -d ${REPO_PATH}/.git ]
then
(cd $LOCAL_LOCATION && git clone $GIT_REPO && cd $REPO_NAME && git checkout $COMMIT_REV)
else
(cd $LOCAL_LOCATION/$REPO_NAME && git checkout $COMMIT_REV)
fi
fi
# Build the image.
docker build -t $DOCKER_IMAGE_NAME \
--build-arg nodeprof_repo=$REPO_PATH \
--ulimit nofile=262144:262144 \
"${DOCKER_NODEPROF_PATH}"