diff --git a/builder-build b/builder-build index 76a0d81..4f0020e 100755 --- a/builder-build +++ b/builder-build @@ -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" diff --git a/commands b/commands new file mode 100755 index 0000000..387e874 --- /dev/null +++ b/commands @@ -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 diff --git a/help-functions b/help-functions new file mode 100755 index 0000000..6426ea2 --- /dev/null +++ b/help-functions @@ -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 <] [], Displays a builder-nixpacks report for one or more apps + builder-nixpacks:set (), Set or clear a builder-nixpacks property for an app +help_content +} diff --git a/internal-functions b/internal-functions new file mode 100755 index 0000000..49be029 --- /dev/null +++ b/internal-functions @@ -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 +} diff --git a/report b/report new file mode 100755 index 0000000..7273565 --- /dev/null +++ b/report @@ -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 "$@" diff --git a/subcommands/default b/subcommands/default new file mode 100755 index 0000000..f29e6df --- /dev/null +++ b/subcommands/default @@ -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" diff --git a/subcommands/report b/subcommands/report new file mode 100755 index 0000000..4ea4b1d --- /dev/null +++ b/subcommands/report @@ -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 "$@" diff --git a/subcommands/set b/subcommands/set new file mode 100755 index 0000000..44a75bc --- /dev/null +++ b/subcommands/set @@ -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 "$@"