-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentry.sh
executable file
·52 lines (46 loc) · 1.58 KB
/
entry.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
#!/usr/bin/env bash
# Entrypoint example.
# This is an example entrypoint utilising Panubo practice, and demonstrating
# various methods for container initialization.
# See: https://github.com/panubo/bash-container for additional
# entrypoint functions
# LICENSE: MIT License, Copyright (c) 2017-2018 Volt Grid Pty Ltd t/a Panubo
# run_deployfile [FILENAME]
# run_deployfile Deployfile
run_deployfile() {
# Run all Deployfile commands
local deployfile="${1:-'Deployfile'}"
local command_run=false
if [[ ! -e "${deployfile}" ]]; then return 0; fi
while read -r line || [[ -n "${line}" ]]; do
if [[ -z "${line}" ]] || [[ "${line}" == \#* ]]; then continue; fi
(>&2 echo "Running task ${line%%:*}: ${line#*:[[:space:]]}")
eval "${line#*:[[:space:]]}"
rc=$?
[[ "${rc}" -ne 0 ]] && return "${rc}"
command_run=true
done < "${deployfile}"
[[ "${command_run}" == "true" ]] && return 0
# return 1 if no commands were run
return 1
}
# exec_procfile FILENAME TYPE
# exec_procfile Procfile web
exec_procfile() {
# Exec Procfile command
local procfile="${1:-'Procfile'}"
if [[ ! -e "${procfile}" ]]; then return 0; fi
while read -r line || [[ -n "${line}" ]]; do
if [[ -z "${line}" ]] || [[ "${line}" == \#* ]]; then continue; fi
if [[ "${2}" == "${line%%:*}" ]]; then
echo "Executing ${2} from ${1}..."
eval exec "${line#*:[[:space:]]}"
fi
done < "${procfile}"
}
# Run all commands specified in the Deployfile
run_deployfile Deployfile
# Try to run a procfile command
exec_procfile Procfile "$1"
# fall back and execute the passed arg
exec "$@"