-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpre-build
executable file
·47 lines (39 loc) · 1.9 KB
/
pre-build
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
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_ENABLED_PATH/common/functions"
BUILDER_TYPE="$1" APP="$2"
if [[ "$BUILDER_TYPE" != "herokuish" ]]; then
exit 0
fi
IMAGE=$(get_app_image_name $APP)
APP_SPECIFIC_KEY_FOLDER="$DOKKU_ROOT/.hostkeys/$APP/.ssh"
SHARED_KEY_FOLDER="$DOKKU_ROOT/.hostkeys/shared/.ssh"
bash $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/install
[[ ! -f "$APP_SPECIFIC_KEY_FOLDER/known_hosts" ]] && [[ ! -f "$SHARED_KEY_FOLDER/known_hosts" ]] && return
dokku_log_info1 "Adding host-keys to build environment ..."
KNOWN_HOSTS_COMBINED=""
if [[ -f "$APP_SPECIFIC_KEY_FOLDER/known_hosts" ]]; then
KNOWN_HOSTS_COMBINED=$(cat "$APP_SPECIFIC_KEY_FOLDER/known_hosts")
dokku_log_verbose_quiet "Adding app specific keys"
fi
if [[ -f "$SHARED_KEY_FOLDER/known_hosts" ]]; then
dokku_log_verbose_quiet "Adding shared keys"
if ([[ -z "$KNOWN_HOSTS_COMBINED" ]]); then
KNOWN_HOSTS_COMBINED="$KNOWN_HOSTS_COMBINED"$(cat "$SHARED_KEY_FOLDER/known_hosts")
else
KNOWN_HOSTS_COMBINED="$KNOWN_HOSTS_COMBINED"$'\n'$(cat "$SHARED_KEY_FOLDER/known_hosts")
fi
fi
if [[ ! -z "$KNOWN_HOSTS_COMBINED" ]]; then
# 1. Create the .ssh folder
id=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $IMAGE /bin/bash -c "mkdir -p -m 700 /app/.ssh")
test $(docker wait $id) -eq 0
docker commit $id $IMAGE > /dev/null
# 2. Transfer the keyfile to the container
idWithKeys=$(echo -e "$KNOWN_HOSTS_COMBINED" | docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "cat >> /etc/ssh/ssh_known_hosts && chmod 644 /etc/ssh/ssh_known_hosts")
test $(docker wait $idWithKeys) -eq 0
docker commit $idWithKeys $IMAGE > /dev/null
idWithConfig=$(echo "UserKnownHostsFile /etc/ssh/ssh_known_hosts" | docker run $DOKKU_GLOBAL_RUN_ARGS -i -a stdin $IMAGE /bin/bash -c "cat >> /etc/ssh/ssh_config" )
test $(docker wait $idWithConfig) -eq 0
docker commit $idWithConfig $IMAGE > /dev/null
fi