-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint
More file actions
65 lines (51 loc) · 2.71 KB
/
docker-entrypoint
File metadata and controls
65 lines (51 loc) · 2.71 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
#!/usr/bin/env bash
DEVSHOP_PATH="$( cd "$(dirname "$0")"/.. ; pwd -P )"
export PATH="$DEVSHOP_PATH/bin:$DEVSHOP_PATH/scripts:$PATH"
set -e
devshop-logo "Docker Entrypoint"
# Set ANSIBLE_TAGS from environment variable ANSIBLE_TAGS, or use ANSIBLE_TAGS_RUNTIME.
ANSIBLE_TAGS=${ANSIBLE_TAGS:-runtime}
DOCKER_COMMAND=${@:-date}
DOCKER_COMMAND_POST=${DOCKER_COMMAND_POST:-"echo No DOCKER_COMMAND_POST variable set. Which should never happen, because it is in the Dockerfile. Probably means you are running this outside of a container."}
INIT_COMMAND=${INIT_COMMAND:-docker-systemd}
DEBUG_ENVIRONMENT=${DEBUG_ENVIRONMENT:-ANSIBLE_}
if [ -n "${DEVSHOP_ENTRYPOINT_LOG_FILES}" ]; then
DOCKER_COMMAND_LOGS="tail-file --follow --verbose $DEVSHOP_ENTRYPOINT_LOG_FILES"
echo "Tailing Log Files: $DEVSHOP_ENTRYPOINT_LOG_FILES"
echo 'TIP: Set the $DEVSHOP_ENTRYPOINT_LOG_FILES environment variable to change the files to show in the Docker logs.'
log "Running DOCKER_COMMAND_LOGS in a new process after 5 seconds: $DOCKER_COMMAND_LOGS ..."
devshop-line
(sleep 5 && $DOCKER_COMMAND_LOGS) &
else
echo 'WARNING: $DEVSHOP_ENTRYPOINT_LOG_FILES variable was empty. Not launching log tails.'
devshop-line
fi
echo "The following commands will be run in this container: "
echo "INIT_COMMAND: $INIT_COMMAND"
echo "DOCKER_COMMAND: $DOCKER_COMMAND"
echo "DOCKER_COMMAND_POST: $DOCKER_COMMAND_POST"
echo "DOCKER_COMMAND_LOGS: $DOCKER_COMMAND_LOGS"
devshop-line
devshop-logo "Container Environment:"
[ -f /etc/centos-release ] && log Contents of /etc/centos-release && cat /etc/centos-release
[ -f /etc/os-release ] && log Contents of /etc/os-release && cat /etc/os-release
devshop-line
log "Environment: (Filtered by $DEBUG_ENVIRONMENT)"
env | grep "${DEBUG_ENVIRONMENT}" || echo "No Variables with a name containing '${DEBUG_ENVIRONMENT}' found."
echo 'TIP: Set the $DEBUG_ENVIRONMENT environment variable to a variable name (or partial string) to print out values.'
devshop-line
devshop-log "Launching Docker Commands in a new process..."
((sleep 3 && \
devshop-logo "System Status: systemctl status --no-pager" && systemctl status --no-pager && \
devshop-logo "Running DOCKER_COMMAND: $DOCKER_COMMAND ..." && $DOCKER_COMMAND &&
devshop-logo "Running DOCKER_COMMAND_POST: $DOCKER_COMMAND_POST ..." && $DOCKER_COMMAND_POST && \
# If successful
devshop-log "Docker Entrypoint Commands Completed successfully! (exit 0)") || ( \
devshop-log "Docker Entrypoint Command failed. (exit $?)" && \
exit $?)) &
DOCKER_COMMANDS_PID=$!
echo "Docker Commands PID: $DOCKER_COMMAND_PID"
devshop-line
# We keep this as devshop-systemd because systemd must run as PID 1.
log "Running Init Command: $INIT_COMMAND"
exec "$INIT_COMMAND"