-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
internal-functions
executable file
·132 lines (118 loc) · 4.23 KB
/
internal-functions
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
export DOCKER_BIN=${DOCKER_BIN:="docker"}
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
fn-clean-extended-app-images() {
declare APP="$1" IMAGE="$2"
local images
# remove dangling extended app images
"$DOCKER_BIN" rmi $("$DOCKER_BIN" images --format 'dangling=true' --format "label=com.dokku.app-name=sha-$APP" --quiet) &>/dev/null || true
images="$("$DOCKER_BIN" images --filter "label=com.dokku.app-name=sha-$APP" --quiet)"
for image in $images; do
if [[ "$("$DOCKER_BIN" inspect --format '{{(index .RepoTags 0)}}' "$image" 2>/dev/null)" != "$IMAGE" ]]; then
"$DOCKER_BIN" rmi "$image" &>/dev/null || true
fi
done
}
fn-apt-fetch-sha() {
declare SOURCECODE_WORK_DIR="$1" DOKKU_IMAGE="$2"
local APT_FILES CONTENT INJECT_PACKAGES file
if [[ -d "$SOURCECODE_WORK_DIR/dpkg-packages" ]]; then
return
fi
APT_FILES=('apt-conf' 'apt-env' 'apt-keys' 'apt-preferences' 'apt-sources-list' 'apt-repositories' 'apt-debconf' 'apt-packages')
for file in "${APT_FILES[@]}"; do
if [[ -f "$SOURCECODE_WORK_DIR/$file" ]]; then
INJECT_PACKAGES=true
local file_contents=$(<$SOURCECODE_WORK_DIR/$file)
CONTENT="${CONTENT}\n${file}\n${file_contents}"
fi
done
if [[ "$INJECT_PACKAGES" != "true" ]]; then
return
fi
echo -n "$(<$PLUGIN_AVAILABLE_PATH/apt/plugin.toml)${DOKKU_IMAGE}${CONTENT}" | sha256sum | cut -d " " -f 1
}
fn-apt-populate-work-dir() {
declare SOURCECODE_WORK_DIR="$1" TMP_WORK_DIR="$2"
local APT_FILES file
APT_FILES=('apt-conf' 'apt-env' 'apt-keys' 'apt-preferences' 'apt-sources-list' 'apt-repositories' 'apt-debconf' 'apt-packages')
for file in "${APT_FILES[@]}"; do
if [[ -f "$SOURCECODE_WORK_DIR/$file" ]]; then
cp "$SOURCECODE_WORK_DIR/$file" "$TMP_WORK_DIR/$file"
fi
done
}
fn-apt-command() {
declare APP="$1" DOKKU_IMAGE="$2" DIR="$3"
cat <<EOF
# $APP $DOKKU_IMAGE
sleep 2
export DEBIAN_FRONTEND=noninteractive
if [ -f $DIR/apt-conf ]; then
echo "-----> Copying apt-conf file into place"
mv -v $DIR/apt-conf /etc/apt/apt.conf.d/99dokku-apt
fi
if [ -f $DIR/apt-env ]; then
echo "-----> Sourcing apt env"
source $DIR/apt-env
fi
if [ -f $DIR/apt-keys ]; then
echo "-----> Installing custom apt repository keys"
cat "$DIR/apt-keys" | while read key; do
if [ -n "\$key" ]; then
curl -sS "\$key" > /tmp/repository.key
echo " Installing \$key (sha256sum: \$(sha256sum /tmp/repository.key | cut -d' ' -f1))"
cat /tmp/repository.key | apt-key add - >/dev/null
fi
done
fi
if [ -d $DIR/apt-preferences ]; then
echo "-----> Injecting apt preferences"
mv -v $DIR/apt-preferences /etc/apt/preferences.d/90customizations
fi
if [ -f $DIR/apt-sources-list ]; then
echo "-----> Using customized sources.list"
mv -v /etc/apt/sources.list /etc/apt/sources.list.orig
mv -v $DIR/apt-sources-list /etc/apt/sources.list
fi
if [ -f $DIR/apt-repositories ]; then
echo "-----> Updating package list"
apt-get update >/dev/null
echo "-----> Installing required apt transport packages"
apt-get install -y software-properties-common apt-transport-https
echo "-----> Installing custom apt repositories"
cat "$DIR/apt-repositories" | while read repository; do
if [ -n "\$repository" ]; then
add-apt-repository -y "\$repository"
fi
done
fi
if [ -f $DIR/apt-debconf ]; then
cat "$DIR/apt-debconf" | while read conf; do
if [ -n "\$conf" ]; then
echo \$conf | debconf-set-selections
fi
done
fi
if [ -f $DIR/apt-packages ]; then
PACKAGES=\$(cat "$DIR/apt-packages" | tr "\\n" " ")
echo "-----> Updating package list"
apt-get update >/dev/null
echo "-----> Injecting packages: \$PACKAGES"
apt-get install -y \$PACKAGES
fi
if [ -d $DIR/dpkg-packages ]; then
PACKAGES=\$(find $DIR/dpkg-packages -type f -name '*.deb' | tr "\\n" " ")
echo "-----> Injecting packages: \$PACKAGES"
dpkg -i \$PACKAGES
fi
if [ -f /etc/apt/sources.list.orig ]; then
echo "-----> Restoring original sources.list"
mv -v /etc/apt/sources.list.orig /etc/apt/sources.list
fi
rm -rf /tmp/apt
sleep 1 # wait so that docker run has not exited before docker attach
EOF
}