forked from dokku-community/dokku-apt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-build-buildpack
executable file
·46 lines (37 loc) · 1.57 KB
/
pre-build-buildpack
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
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
export DOCKER_BIN=${DOCKER_BIN:="docker"}
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/apt/internal-functions"
hook-apt-pre-build-buildpack() {
declare APP="$1" SOURCECODE_WORK_DIR="$2"
local IMAGE="dokku/$APP" DIR=/app
local CID COMMAND DOCKER_COMMIT_LABEL_ARGS
# This trigger is only called with apps using buildpacks, so it's safe to assume this:
local BUILDER_TYPE=herokuish
if [[ -n "$SOURCECODE_WORK_DIR" ]]; then
pushd "$SOURCECODE_WORK_DIR" >/dev/null
fi
if [[ ! -d "dpkg-packages" ]]; then
return
fi
if [[ -n "$SOURCECODE_WORK_DIR" ]]; then
popd >/dev/null
fi
local DOCKER_ARGS=$(: | plugn trigger docker-args-build "$APP" "$BUILDER_TYPE")
declare -a ARG_ARRAY
eval "ARG_ARRAY=($DOCKER_ARGS)"
dokku_log_info1 "Creating extended app image with custom system packages"
COMMAND="$(fn-apt-command "$APP" "$IMAGE" "$DIR")"
CID=$(docker run -d "${ARG_ARRAY[@]}" "$IMAGE" /bin/bash -e -c "$COMMAND")
"$DOCKER_BIN" attach "$CID"
if test "$("$DOCKER_BIN" wait "$CID")" -ne 0; then
dokku_log_warn "Failure installing system packages"
return 1
fi
DOCKER_COMMIT_LABEL_ARGS=("--change" "LABEL org.label-schema.schema-version=1.0" "--change" "LABEL org.label-schema.vendor=dokku" "--change" "LABEL com.dokku.app-name=$APP" "--change" "LABEL $DOKKU_CONTAINER_LABEL=")
"$DOCKER_BIN" commit "${DOCKER_COMMIT_LABEL_ARGS[@]}" "$CID" "$IMAGE" >/dev/null
"$DOCKER_BIN" rm "$CID" &>/dev/null || true
}
hook-apt-pre-build-buildpack "$@"