-
Notifications
You must be signed in to change notification settings - Fork 17
/
metroae-container
executable file
·79 lines (67 loc) · 2.07 KB
/
metroae-container
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
#!/bin/bash
# WARNING: Any paths defined in the deployment files must be relative to this folder. No absolute paths, and no paths outside of this folder
TAG=$(git rev-parse --short HEAD)
TI=""
ENCRYPTED_TOKEN=\$ANSIBLE_VAULT
CURRENT_DIR=`pwd`
DEPLOYMENTS_BASE_DIR=$CURRENT_DIR/deployments
DEPLOYMENT_DIR=$DEPLOYMENTS_BASE_DIR/default
[ -t 0 ] && TI="-ti"
function check_password_needed {
deployment_dir="$1"
encrypted_files=$(grep -Ril $ENCRYPTED_TOKEN $deployment_dir)
if [[ -z $METROAE_PASSWORD ]]; then
if [[ -z "$encrypted_files" ]]; then
SKIP_PASSWORD=1
else
SKIP_PASSWORD=0
fi
else
SKIP_PASSWORD=1
fi
}
function ask_password {
if [[ $SKIP_PASSWORD -ne 1 ]]; then
write_to_screen_and_script_log "The deployment contains encrypted content which requires a password to access."
echo "Enter the password, below, or add the environment variable METROAE_PASSWORD and retry."
echo ""
read -s -p "Enter password: " METROAE_PASSWORD
export METROAE_PASSWORD
fi
}
docker image inspect metroaecontainer:$TAG > /dev/null 2>&1
if [[ "$?" != "0" ]]
then
if [[ -n "$TI" ]]
then
echo "The docker image for this repo head does not exist. We will build it. Press any key to continue"
read -n 1
fi
set -e
./docker/build-container raw
set +e
fi
SSHMOUNT=""
[[ -e .ssh ]] && SSHMOUNT="-v `pwd`/.ssh:/root/.ssh"
check_password_needed "$DEPLOYMENT_DIR"
ask_password
VAULTPASS=""
if [[ ! -z $METROAE_PASSWORD ]]; then
VAULTPASS=" -e METROAE_PASSWORD=$METROAE_PASSWORD"
fi
# Run the command inside docker
args=( "$@" )
# we use host networking because we want the host's dns server and host file
docker run \
--network=host \
--rm \
$TI \
$SSHMOUNT \
$VAULTPASS \
-e SKIP_PROMPTS \
--env-file <(env | grep -Ev '^(PWD|PATH|HOME|USER|SHELL|MAIL|SSH_CONNECTION|LOGNAME|OLDPWD|LESSOPEN|_XDG_RUNTIME_DIR|HISTCONTROL)') \
-v \
"`pwd`:/metroae" \
-e METROAE_DIR=`pwd` \
metroaecontainer:$TAG \
./metroae "${args[@]}"