forked from 28mm/blast-radius
-
Notifications
You must be signed in to change notification settings - Fork 10
/
docker-entrypoint.sh
45 lines (37 loc) · 1.25 KB
/
docker-entrypoint.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
#!/bin/sh
set -e
# If command starts with an option, prepend the blast-radius.
if [ "${1}" != "blast-radius" ]; then
if [ -n "${1}" ]; then
set -- blast-radius "$@"
fi
fi
# Assert CLI args are overwritten, otherwise set them to preferred defaults
export TF_CLI_ARGS_get=${TF_CLI_ARGS_get:-'-update'}
export TF_CLI_ARGS_init=${TF_CLI_ARGS_init:-'-input=false'}
# Inside the container
# Need to create the upper and work dirs inside a tmpfs.
# Otherwise OverlayFS complains about AUFS folders.
# Source: https://gist.github.com/detunized/7c8fc4c37b49c5475e68ef9574587eee
mkdir -p /tmp/overlay && \
mount -t tmpfs tmpfs /tmp/overlay && \
mkdir -p /tmp/overlay/upper && \
mkdir -p /tmp/overlay/work && \
mkdir -p /data-rw && \
mount -t overlay overlay -o lowerdir=/data,upperdir=/tmp/overlay/upper,workdir=/tmp/overlay/work /data-rw
# change to the overlayFS
cd /data-rw
# Is Terraform already initialized? Ensure modules are all downloaded.
[ -d '.terraform' ] && terraform get
# Reinitialize for some reason
if [ -n "$CHDIR" ] && [ -d "$CHDIR" ]; then
terraform -chdir="$CHDIR" init
echo "Initializing Terraform in directory: $CHDIR"
else
terraform init
fi
# it's possible that we're in a sub-directory. leave.
cd /data-rw
cat /output.txt
# Let's go!
exec "$@"