-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake.sh
More file actions
executable file
·173 lines (128 loc) · 2.63 KB
/
make.sh
File metadata and controls
executable file
·173 lines (128 loc) · 2.63 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env bash
# Setup
set -uex -o pipefail
which greadlink >/dev/null 2>&1 && readlink=greadlink || readlink=readlink
rundir=$($readlink -f "${0%/*}")
cd $rundir
## Varibles
ARGS="$@"
[ -z "$ARGS" ] && set -- build
DOCKER_BUILD_PROXY=${DOCKER_BUILD_PROXY:-}
DOCKER_NODE_VERSION=${DOCKER_NODE_VERSION:-}
SCOPE="dply"
NAME="node-docker-demo-app"
SCOPE_NAME="${SCOPE}/${NAME}"
PORT=8080
## Builds
### Helpers
docker_build(){
local tag=${1}
args=""
[ -z $DOCKER_BUILD_PROXY ] || args="$args --build-arg DOCKER_BUILD_PROXY=${DOCKER_BUILD_PROXY}"
[ -z $DOCKER_NODE_VERSION ] || args="$arg --build-arg NODE_VERSION=${DOCKER_NODE_VERSION}"
docker build $args -f "Dockerfile.$tag" -t ${SCOPE_NAME}:$tag .
}
### Commands
build(){
build_plain
build_forever
build_nodemon
build_s6
build_supervisor
}
# plain
build_plain(){
build_plain_node
build_plain_alpine
}
build_plain_node(){
docker_build plain
}
build_plain_alpine(){
docker_build plain-alpine
}
# forever
build_forever(){
build_forever_node
build_forever_alpine
}
build_forever_node(){
docker_build forever
}
build_forever_alpine(){
docker_build forever-alpine
}
# nodemon
build_nodemon(){
build_nodemon_node
build_nodemon_alpine
}
build_nodemon_node(){
docker_build nodemon
}
build_nodemon_alpine(){
docker_build nodemon-alpine
}
# s6
build_s6(){
build_s6_node
build_s6_alpine
}
build_s6_node(){
docker_build s6
}
build_s6_alpine(){
docker_build s6-alpine
}
# supervisor
build_supervisor(){
build_supervisor_node
build_supervisor_alpine
}
build_supervisor_node(){
docker_build supervisor
}
build_supervisor_alpine(){
docker_build supervisor-alpine
}
## Run
run_update(){
local version=$1
# pre Docker 1.13 updates, when FROM couldnt be a variable
#sed -i '' -e 's!^FROM node:.*-alpine!FROM node:'$version'-alpine!' Dockerfile.*-alpine
#sed -i '' -e 's!^FROM node:[0-9\.]*$!FROM node:'$version'!' Dockerfile.[a-zA-Z0-9][a-zA-Z0-9]*
sed -i '' -e 's!^ARG NODE_VERSION=".*"!ARG NODE_VERSION="'$version'"!' Dockerfile*
}
run_image(){
local tag=${1:-plain}
docker run -p "${PORT}:8080" "${SCOPE_NAME}:${tag}"
}
run(){
run_image "$@"
}
## versions
versions(){
versions_versions=$(curl -s https://nodejs.org/dist/index.json)
echo "$versions_versions" | head -10
}
## Test
test_request(){
local response
response=$(curl http://localhost:${PORT}/)
set +x
if [ "$response" != "hello!" ]; then
echo "Error: Response "$response" was unexpected"
exit 1
else
echo "$response"
fi
}
test(){
test_request
}
help(){
set +x
echo "Available commands:"
compgen -A function | awk '{print " ",$0}'
}
"$@"