mirror of
https://github.com/dokku/dokku.git
synced 2026-05-18 05:05:46 +02:00
feat: add ability to specify a custom project.toml path
This commit is contained in:
@@ -12,25 +12,6 @@ Cloud Native Buildpacks are an evolution over the Buildpacks technology provided
|
||||
|
||||
## Usage
|
||||
|
||||
### Detection
|
||||
|
||||
This builder will be auto-detected in either the following cases:
|
||||
|
||||
- The `DOKKU_CNB_EXPERIMENTAL` app environment variable is set to `1`.
|
||||
```shell
|
||||
dokku config:set --no-restart node-js-app DOKKU_CNB_EXPERIMENTAL=1
|
||||
```
|
||||
- A `project.toml` file exists in the root of the app repository.
|
||||
- This file is consumed by `pack-cli` and used to describe how the app is built.
|
||||
|
||||
The builder can also be specified via the `builder:set` command:
|
||||
|
||||
```shell
|
||||
dokku builder:set node-js-app selected pack
|
||||
```
|
||||
|
||||
> Dokku will only select the `dockerfile` builder if both the `herokuish` and `pack` builders are not detected and a Dockerfile exists. See the [dockerfile builder documentation](/docs/deployment/builders/dockerfiles.md) for more information on how that builder functions.
|
||||
|
||||
### Requirements
|
||||
|
||||
The `pack` cli tool is not included by default with Dokku or as a dependency. It must also be installed as shown on [this page](https://buildpacks.io/docs/tools/pack/).
|
||||
@@ -51,6 +32,99 @@ As this functionality is highly experimental, there are a number of caveats. Ple
|
||||
- `pack` is not currently included with Dokku, nor is it added as a package dependency.
|
||||
- A future version will include it as a package dependency.
|
||||
|
||||
### Detection
|
||||
|
||||
This builder will be auto-detected in either the following cases:
|
||||
|
||||
- The `DOKKU_CNB_EXPERIMENTAL` app environment variable is set to `1`.
|
||||
```shell
|
||||
dokku config:set --no-restart node-js-app DOKKU_CNB_EXPERIMENTAL=1
|
||||
```
|
||||
- A `project.toml` file exists in the root of the app repository.
|
||||
- This file is consumed by `pack-cli` and used to describe how the app is built.
|
||||
|
||||
The builder can also be specified via the `builder:set` command:
|
||||
|
||||
```shell
|
||||
dokku builder:set node-js-app selected pack
|
||||
```
|
||||
|
||||
> Dokku will only select the `dockerfile` builder if both the `herokuish` and `pack` builders are not detected and a Dockerfile exists. See the [dockerfile builder documentation](/docs/deployment/builders/dockerfiles.md) for more information on how that builder functions.
|
||||
|
||||
### Changing the `project.toml` location
|
||||
|
||||
When deploying a monorepo, it may be desirable to specify the specific path of the `project.toml` file to use for a given app. This can be done via the `builder-pack:set` command.
|
||||
|
||||
```shell
|
||||
dokku builder-pack:set node-js-app projecttoml-path project2.toml
|
||||
```
|
||||
|
||||
The default value may be set by passing an empty value for the option:
|
||||
|
||||
```shell
|
||||
dokku builder-pack:set node-js-app projecttoml-path
|
||||
```
|
||||
|
||||
The `projecttoml-path` property can also be set globally. The global default is `project.toml`, and the global value is used when no app-specific value is set.
|
||||
|
||||
```shell
|
||||
dokku builder-pack:set --global projecttoml-path project2.toml
|
||||
```
|
||||
|
||||
The default value may be set by passing an empty value for the option.
|
||||
|
||||
```shell
|
||||
dokku builder-pack:set --global projecttoml-path
|
||||
```
|
||||
|
||||
### Displaying builder-pack reports for an app
|
||||
|
||||
> New as of 0.25.0
|
||||
|
||||
You can get a report about the app's storage status using the `builder-pack:report` command:
|
||||
|
||||
```shell
|
||||
dokku app-json:report
|
||||
```
|
||||
|
||||
```
|
||||
=====> node-js-app builder-pack information
|
||||
Builder-pack computed projecttoml path: project2.toml
|
||||
Builder-pack global projecttoml path: project.toml
|
||||
Builder-pack projecttoml path: project2.toml
|
||||
=====> python-sample builder-pack information
|
||||
Builder-pack computed projecttoml path: project.toml
|
||||
Builder-pack global projecttoml path: project.toml
|
||||
Builder-pack projecttoml path:
|
||||
=====> ruby-sample builder-pack information
|
||||
Builder-pack computed projecttoml path: project.toml
|
||||
Builder-pack global projecttoml path: project.json
|
||||
Builder-pack projecttoml path:
|
||||
```
|
||||
|
||||
You can run the command for a specific app also.
|
||||
|
||||
```shell
|
||||
dokku builder-pack:report node-js-app
|
||||
```
|
||||
|
||||
```
|
||||
=====> node-js-app builder-pack information
|
||||
Builder-pack computed projecttoml path: project2.toml
|
||||
Builder-pack global projecttoml path: project.toml
|
||||
Builder-pack projecttoml path: project2.toml
|
||||
```
|
||||
|
||||
You can pass flags which will output only the value of the specific information you want. For example:
|
||||
|
||||
```shell
|
||||
dokku builder-pack:report node-js-app --builder-pack-projecttoml-path
|
||||
```
|
||||
|
||||
```
|
||||
project2.toml
|
||||
```
|
||||
|
||||
### Customizing the Buildpack stack builder
|
||||
|
||||
> New as of 0.23.0
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-pack/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
trigger-builder-pack-builder-build() {
|
||||
declare desc="builder-pack builder-build plugin trigger"
|
||||
@@ -28,6 +29,15 @@ trigger-builder-pack-builder-build() {
|
||||
|
||||
pushd "$SOURCECODE_WORK_DIR" &>/dev/null
|
||||
|
||||
local NEW_PROJECT_TOML="$(fn-builder-pack-computed-projectoml-path "$APP")"
|
||||
if [[ -f "$NEW_PROJECT_TOML" ]]; then
|
||||
if [[ "$NEW_DOCKERFILE" != "project.toml" ]]; then
|
||||
mv "$NEW_PROJECT_TOML" project.toml
|
||||
fi
|
||||
else
|
||||
rm project.toml
|
||||
fi
|
||||
|
||||
local TMP_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
||||
trap "rm -rf '$TMP_FILE' >/dev/null" RETURN INT TERM
|
||||
|
||||
|
||||
15
plugins/builder-pack/commands
Executable file
15
plugins/builder-pack/commands
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-pack/help-functions"
|
||||
|
||||
case "$1" in
|
||||
help | builder-pack:help)
|
||||
cmd-builder-pack-help "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||
;;
|
||||
|
||||
esac
|
||||
33
plugins/builder-pack/help-functions
Executable file
33
plugins/builder-pack/help-functions
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-builder-pack-help() {
|
||||
declare desc="help command"
|
||||
declare CMD="$1"
|
||||
local plugin_name="builder-pack"
|
||||
local plugin_description="Manage the pack 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-pack:report [<app>] [<flag>], Displays a builder-pack report for one or more apps
|
||||
builder-pack:set <app> <property> (<value>), Set or clear a builder-pack property for an app
|
||||
help_content
|
||||
}
|
||||
91
plugins/builder-pack/internal-commands
Executable file
91
plugins/builder-pack/internal-commands
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/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-pack-report() {
|
||||
declare desc="displays a builder-pack report for one or more apps"
|
||||
declare cmd="builder-pack:report"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
declare APP="$1" INFO_FLAG="$2"
|
||||
local INSTALLED_APPS=$(dokku_apps)
|
||||
|
||||
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 $INSTALLED_APPS; do
|
||||
cmd-builder-pack-report-single "$app" "$INFO_FLAG" | tee || true
|
||||
done
|
||||
else
|
||||
cmd-builder-pack-report-single "$APP" "$INFO_FLAG"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd-builder-pack-report-single() {
|
||||
declare APP="$1" INFO_FLAG="$2"
|
||||
if [[ "$INFO_FLAG" == "true" ]]; then
|
||||
INFO_FLAG=""
|
||||
fi
|
||||
verify_app_name "$APP"
|
||||
local flag_map=(
|
||||
"--builder-pack-computed-projecttoml-path: $(fn-builder-pack-computed-projectoml-path "$APP")"
|
||||
"--builder-pack-global-projecttoml-path: $(fn-builder-pack-global-projectoml-path "$APP")"
|
||||
"--builder-pack-projecttoml-path: $(fn-builder-pack-projectoml-path "$APP")"
|
||||
)
|
||||
|
||||
if [[ -z "$INFO_FLAG" ]]; then
|
||||
dokku_log_info2_quiet "${APP} builder-pack information"
|
||||
for flag in "${flag_map[@]}"; do
|
||||
key="$(echo "${flag#--}" | cut -f1 -d' ' | tr - ' ')"
|
||||
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
|
||||
}
|
||||
|
||||
fn-builder-pack-computed-projectoml-path() {
|
||||
declare APP="$1"
|
||||
|
||||
file="$(fn-builder-pack-projectoml-path "$APP")"
|
||||
if [[ "$file" == "" ]]; then
|
||||
file="$(fn-builder-pack-global-projectoml-path "$APP")"
|
||||
fi
|
||||
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
fn-builder-pack-global-projectoml-path() {
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-get "builder-pack" "--global" "projecttoml-path" "project.toml"
|
||||
}
|
||||
|
||||
fn-builder-pack-projectoml-path() {
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-get "builder-pack" "$APP" "projecttoml-path" ""
|
||||
}
|
||||
6
plugins/builder-pack/report
Executable file
6
plugins/builder-pack/report
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-pack/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-builder-pack-report-single "$@"
|
||||
6
plugins/builder-pack/subcommands/default
Executable file
6
plugins/builder-pack/subcommands/default
Executable 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
plugins/builder-pack/subcommands/report
Executable file
6
plugins/builder-pack/subcommands/report
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-pack/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-builder-pack-report "$@"
|
||||
30
plugins/builder-pack/subcommands/set
Executable file
30
plugins/builder-pack/subcommands/set
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/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-pack-set() {
|
||||
declare desc="set or clear a builder-pack property for an app"
|
||||
declare cmd="builder-pack:set"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
declare APP="$1" KEY="$2" VALUE="$3"
|
||||
local VALID_KEYS=("projecttoml-path")
|
||||
[[ "$APP" == "--global" ]] || 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: projecttoml-path"
|
||||
fi
|
||||
|
||||
if [[ -n "$VALUE" ]]; then
|
||||
dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}"
|
||||
fn-plugin-property-write "builder-pack" "$APP" "$KEY" "$VALUE"
|
||||
else
|
||||
dokku_log_info2_quiet "Unsetting ${KEY}"
|
||||
fn-plugin-property-delete "builder-pack" "$APP" "$KEY"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd-builder-pack-set "$@"
|
||||
Reference in New Issue
Block a user