Andrew Coleman 2022-08-30 10:26:44 -04:00
parent 041aaac2b3
commit 13dd515aee
8 changed files with 179 additions and 7 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/builder-nixpacks/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
@ -23,18 +24,18 @@ trigger-builder-nixpacks-builder-build() {
pushd "$SOURCECODE_WORK_DIR" &>/dev/null
ENV_ARGS=($(config_export app "$APP" --format nixpacks-keys --merged))
eval "$(config_export app "$APP" --merged)"
plugn trigger pre-build-nixpacks "$APP" "$SOURCECODE_WORK_DIR"
if ! cd "$SOURCECODE_WORK_DIR" > /dev/null 2>&1; then
dokku_log_fail "Could not change to '$SOURCECODE_WORK_DIR'"
fi
local flag_map=$(fn-plugin-property-get-all "builder-nixpacks" "$APP")
let NIXPACKS_ARGS=""
for flag in ${flag_map[@]} ; do
NIXPACKS_ARGS+="$(echo "${flag}" | tr ' ' '=') "
done
nixpacks build "$IMAGE" \
--env "${ENV_ARGS[@]}" \
--name "$IMAGE"
echo /usr/bin/env "${NIXPACKS_ARGS}" nixpacks build . --name "$IMAGE"
/usr/bin/env "${NIXPACKS_ARGS}" nixpacks build . --name "$IMAGE"
docker-image-labeler --label=dokku --label=org.label-schema.schema-version=1.0 --label=org.label-schema.vendor=dokku --label=com.dokku.image-stage=build --label=com.dokku.builder-type=pack --label=com.dokku.app-name=$APP "$IMAGE"
plugn trigger post-build-nixpacks "$APP" "$SOURCECODE_WORK_DIR"

15
commands Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_AVAILABLE_PATH/builder-nixpacks/help-functions"
case "$1" in
help | builder-nixpacks:help)
cmd-builder-nixpacks-help "$@"
;;
*)
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
;;
esac

33
help-functions Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-builder-nixpacks-help() {
declare desc="help command"
declare CMD="$1"
local plugin_name="builder-nixpacks"
local plugin_description="Manage the nixpacks builder integration for an app"
if [[ "$CMD" == "${plugin_name}:help" ]]; then
echo -e "Usage: dokku ${plugin_name}[:COMMAND]"
echo ''
echo "$plugin_description"
echo ''
echo 'Additional commands:'
fn-help-content | sort | column -c2 -t -s,
elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then
fn-help-content
else
cat <<help_desc
$plugin_name, $plugin_description
help_desc
fi
}
fn-help-content() {
declare desc="return help content"
cat <<help_content
builder-nixpacks:report [<app>] [<flag>], Displays a builder-nixpacks report for one or more apps
builder-nixpacks:set <app> <property> (<value>), Set or clear a builder-nixpacks property for an app
help_content
}

64
internal-functions Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-builder-nixpacks-report() {
declare desc="displays a builder-nixpacks report for one or more apps"
declare cmd="builder-nixpacks:report"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" INFO_FLAG="$2"
if [[ -n "$APP" ]] && [[ "$APP" == --* ]]; then
INFO_FLAG="$APP"
APP=""
fi
if [[ -z "$APP" ]] && [[ -z "$INFO_FLAG" ]]; then
INFO_FLAG="true"
fi
if [[ -z "$APP" ]]; then
for app in $(dokku_apps); do
cmd-builder-nixpacks-report-single "$app" "$INFO_FLAG" | tee || true
done
else
cmd-builder-nixpacks-report-single "$APP" "$INFO_FLAG"
fi
}
cmd-builder-nixpacks-report-single() {
declare APP="$1" INFO_FLAG="$2"
if [[ "$INFO_FLAG" == "true" ]]; then
INFO_FLAG=""
fi
verify_app_name "$APP"
local flag_map=$(fn-plugin-property-get-all "builder-nixpacks" "$APP")
if [[ -z "$INFO_FLAG" ]]; then
dokku_log_info2_quiet "${APP} builder-nixpacks information"
for flag in "${flag_map[@]}"; do
key="$(echo "${flag#--}" | cut -f1 -d' ')"
dokku_log_verbose "$(printf "%-30s %-25s" "${key^}" "${flag#* }")"
done
else
local match=false
local value_exists=false
for flag in "${flag_map[@]}"; do
valid_flags="${valid_flags} $(echo "$flag" | cut -d' ' -f1)"
if [[ "$flag" == "${INFO_FLAG}:"* ]]; then
value=${flag#*: }
size="${#value}"
if [[ "$size" -ne 0 ]]; then
echo "$value" && match=true && value_exists=true
else
match=true
fi
fi
done
[[ "$match" == "true" ]] || dokku_log_fail "Invalid flag passed, valid flags:${valid_flags}"
[[ "$value_exists" == "true" ]] || dokku_log_fail "not deployed"
fi
}

6
report Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/builder-nixpacks/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-builder-nixpacks-report-single "$@"

6
subcommands/default Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/builder-pack/help-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-builder-pack-help "builder-pack:help"

6
subcommands/report Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/builder-nixpacks/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-builder-nixpacks-report "$@"

41
subcommands/set Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-builder-nixpacks-set() {
declare desc="set or clear a builder-nixpacks property for an app"
declare cmd="builder-nixpacks:set"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" KEY="$2" VALUE="$3"
local VALID_KEYS=(\
"NIXPACKS_APT_PKGS" \
"NIXPACKS_BUILD_CACHE_DIRS" \
"NIXPACKS_BUILD_CMD" \
"NIXPACKS_INSTALL_CACHE_DIRS" \
"NIXPACKS_INSTALL_CMD" \
"NIXPACKS_LIBS" \
"NIXPACKS_NO_CACHE" \
"NIXPACKS_NO_MUSL" \
"NIXPACKS_PKGS" \
"NIXPACKS_START_CMD" \
)
verify_app_name "$APP"
[[ -z "$KEY" ]] && dokku_log_fail "No key specified"
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
dokku_log_fail "Invalid key specified, valid keys include: ${VALID_KEYS[@]}"
fi
if [[ -n "$VALUE" ]]; then
dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}"
fn-plugin-property-write "builder-nixpacks" "$APP" "$KEY" "$VALUE"
else
dokku_log_info2_quiet "Unsetting ${KEY}"
fn-plugin-property-delete "builder-nixpacks" "$APP" "$KEY"
fi
}
cmd-builder-nixpacks-set "$@"