-
Notifications
You must be signed in to change notification settings - Fork 19
/
post-build-buildstep
executable file
·62 lines (52 loc) · 1.44 KB
/
post-build-buildstep
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
#!/bin/bash
APP="$1"; IMAGE="dokku/$APP"
read -d '' runner <<'EOF'
#!/bin/bash
# **shoreman** is an implementation of the **Procfile** format. Inspired by
# the original [foreman](http://ddollar.github.com/foreman/) tool for ruby,
# as well as [norman](https://github.com/josh/norman) for node.js.
# This version is altered for use within dokku
# .env parsing has been removed
# children are killed using their parent ID
set -e
export HOME=/app
for file in \$HOME/.profile.d/*; do source \$file; done
hash -r
cd \$HOME
case "\$(basename \$0)" in
start)
while read line || [ -n "\$line" ]
do
if [[ "\$line" =~ ^([A-Za-z0-9_-]+):\s*(.+)$ ]]
then
name=\${line%%:*}
command=\${line#*: }
echo "Starting \${name}..."
setuidgid "$(stat -c %U "$HOME")" sh -c "\${command} | sed -u -e 's/^/\${name}| /'" &
fi
done < "Procfile"
onexit() {
echo SIGINT received
echo sending SIGTERM to all processes
children=\$(ps --ppid=\$\$ -o pid='')
kill -- \$children &> /dev/null
sleep 1
}
trap onexit SIGTERM SIGINT EXIT
wait
;;
*)
"\$@"
;;
esac
EOF
set -e
# Check for Procfile
id=$(docker run -d $IMAGE test -f app/Procfile)
if [ $(docker wait $id) -ne 0 ]; then
exit 0
fi
echo "-----> Injecting Shoreman ..."
id=$(echo "$runner" | docker run -i -a stdin $IMAGE /bin/bash -c "cat > /start")
test $(docker wait $id) -eq 0
docker commit $id $IMAGE > /dev/null