feat: add ability to specify a custom Dockerfile for an app
This commit is contained in:
@@ -3,3 +3,7 @@
|
||||
## Changes
|
||||
|
||||
- The network plugin can now set an `initial-network` for all containers on creation. This is a replacement for specifying the `--network` flag via the `docker-options` plugin. Please see the [network documentation](/docs/networking/network.md#attaching-an-app-to-a-network) for more information.
|
||||
|
||||
## Deprecations
|
||||
|
||||
- In previous versions of Dokku, the only way to specify a custom `Dockerfile` was to use the `docker-options` plugin to set the `--file` flag for a docker build. As of 0.25.0, the `builder-dockerfile:set` command should be used instead, as outlined in the [docs here](/docs/deployment/builders/dockerfiles.md#changingthe-dockerfile-location). Usage of the old method should be migrated to the new method.
|
||||
|
||||
@@ -27,6 +27,82 @@ If an application was previously deployed via buildpacks, the following commands
|
||||
dokku config:unset --no-restart node-js-app DOKKU_PROXY_PORT_MAP
|
||||
```
|
||||
|
||||
### Changing the `Dockerfile` location
|
||||
|
||||
> The previous method to perform this - via `docker-options:add` - should be removed in favor of the `builder-dockerfile:set` command outlined here.
|
||||
|
||||
When deploying a monorepo, it may be desirable to specify the specific path of the `Dockerfile` file to use for a given app. This can be done via the `builder-dockerfile:set` command.
|
||||
|
||||
```shell
|
||||
dokku builder-dockerfile:set node-js-app dockerfile-path Dockerfile2
|
||||
```
|
||||
|
||||
The default value may be set by passing an empty value for the option:
|
||||
|
||||
```shell
|
||||
dokku builder-dockerfile:set node-js-app dockerfile-path
|
||||
```
|
||||
|
||||
The `dockerfile-path` property can also be set globally. The global default is `Dockerfile`, and the global value is used when no app-specific value is set.
|
||||
|
||||
```shell
|
||||
dokku builder-dockerfile:set --global dockerfile-path Dockerfile2
|
||||
```
|
||||
|
||||
The default value may be set by passing an empty value for the option.
|
||||
|
||||
```shell
|
||||
dokku builder-dockerfile:set --global dockerfile-path
|
||||
```
|
||||
|
||||
### Displaying builder-dockerfile reports for an app
|
||||
|
||||
> New as of 0.25.0
|
||||
|
||||
You can get a report about the app's storage status using the `builder-dockerfile:report` command:
|
||||
|
||||
```shell
|
||||
dokku app-json:report
|
||||
```
|
||||
|
||||
```
|
||||
=====> node-js-app builder-dockerfile information
|
||||
Builder-dockerfile computed dockerfile path: Dockerfile2
|
||||
Builder-dockerfile global dockerfile path: Dockerfile
|
||||
Builder-dockerfile dockerfile path: Dockerfile2
|
||||
=====> python-sample builder-dockerfile information
|
||||
Builder-dockerfile computed dockerfile path: Dockerfile
|
||||
Builder-dockerfile global dockerfile path: Dockerfile
|
||||
Builder-dockerfile dockerfile path:
|
||||
=====> ruby-sample builder-dockerfile information
|
||||
Builder-dockerfile computed dockerfile path: Dockerfile
|
||||
Builder-dockerfile global dockerfile path: Dockerfile
|
||||
Builder-dockerfile dockerfile path:
|
||||
```
|
||||
|
||||
You can run the command for a specific app also.
|
||||
|
||||
```shell
|
||||
dokku builder-dockerfile:report node-js-app
|
||||
```
|
||||
|
||||
```
|
||||
=====> node-js-app builder-dockerfile information
|
||||
Builder-dockerfile computed dockerfile path: Dockerfile2
|
||||
Builder-dockerfile global dockerfile path: Dockerfile
|
||||
Builder-dockerfile dockerfile path: Dockerfile2
|
||||
```
|
||||
|
||||
You can pass flags which will output only the value of the specific information you want. For example:
|
||||
|
||||
```shell
|
||||
dokku builder-dockerfile:report node-js-app --builder-dockerfile-dockerfile-path
|
||||
```
|
||||
|
||||
```
|
||||
Dockerfile2
|
||||
```
|
||||
|
||||
### Build-time configuration variables
|
||||
|
||||
For security reasons - and as per [Docker recommendations](https://github.com/docker/docker/issues/13490) - Dockerfile-based deploys have variables available only during runtime.
|
||||
@@ -37,12 +113,6 @@ For users that require customization in the `build` phase, you may use build arg
|
||||
dokku docker-options:add node-js-app build '--build-arg NODE_ENV=production'
|
||||
```
|
||||
|
||||
The location of the `Dockerfile` may also be specified. If the location is changed, the repository **must also** have a `Dockerfile` in the root directory in order to trigger a dockerfile-based deploy.
|
||||
|
||||
```shell
|
||||
dokku docker-options:add node-js-app build '--file Dockerfile.dokku'
|
||||
```
|
||||
|
||||
Once set, the Dockerfile usage would be as follows:
|
||||
|
||||
```Dockerfile
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-dockerfile/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
trigger-builder-dockerfile-builder-build() {
|
||||
declare desc="builder-dockerfile builder-build plugin trigger"
|
||||
@@ -19,6 +21,19 @@ trigger-builder-dockerfile-builder-build() {
|
||||
|
||||
pushd "$SOURCECODE_WORK_DIR" &>/dev/null
|
||||
|
||||
local NEW_DOCKERFILE="$(fn-builder-dockerfile-computed-dockerfile-path "$APP")"
|
||||
if [[ -f "$NEW_DOCKERFILE" ]]; then
|
||||
if [[ "$NEW_DOCKERFILE" != "Dockerfile" ]]; then
|
||||
mv "$NEW_DOCKERFILE" Dockerfile
|
||||
fi
|
||||
else
|
||||
rm Dockerfile
|
||||
fi
|
||||
|
||||
if [[ ! -f Dockerfile ]]; then
|
||||
dokku_log_fail "Invalid dockerfile-path specified: $dockerfile_path"
|
||||
fi
|
||||
|
||||
# extract first port from Dockerfile
|
||||
dos2unix Dockerfile
|
||||
local DOCKERFILE_PORTS=$(get_dockerfile_exposed_ports Dockerfile)
|
||||
@@ -34,7 +49,7 @@ trigger-builder-dockerfile-builder-build() {
|
||||
declare -a ARG_ARRAY
|
||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||
|
||||
"$DOCKER_BIN" image build "${DOCKER_BUILD_LABEL_ARGS[@]}" $DOKKU_GLOBAL_BUILD_ARGS "${ARG_ARRAY[@]}" "${DOKKU_DOCKER_BUILD_OPTS[@]}" -t $IMAGE .
|
||||
"$DOCKER_BIN" image build --file "$dockerfile_path" "${DOCKER_BUILD_LABEL_ARGS[@]}" $DOKKU_GLOBAL_BUILD_ARGS "${ARG_ARRAY[@]}" "${DOKKU_DOCKER_BUILD_OPTS[@]}" -t $IMAGE .
|
||||
|
||||
plugn trigger post-build-dockerfile "$APP"
|
||||
}
|
||||
|
||||
15
plugins/builder-dockerfile/commands
Executable file
15
plugins/builder-dockerfile/commands
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-dockerfile/help-functions"
|
||||
|
||||
case "$1" in
|
||||
help | builder-dockerfile:help)
|
||||
cmd-builder-dockerfile-help "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||
;;
|
||||
|
||||
esac
|
||||
33
plugins/builder-dockerfile/help-functions
Executable file
33
plugins/builder-dockerfile/help-functions
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-builder-dockerfile-help() {
|
||||
declare desc="help command"
|
||||
declare CMD="$1"
|
||||
local plugin_name="builder-dockerfile"
|
||||
local plugin_description="Manage the dockerfile 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-dockerfile:report [<app>] [<flag>], Displays a builder-dockerfile report for one or more apps
|
||||
builder-dockerfile:set <app> <property> (<value>), Set or clear a builder-dockerfile property for an app
|
||||
help_content
|
||||
}
|
||||
91
plugins/builder-dockerfile/internal-commands
Executable file
91
plugins/builder-dockerfile/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-dockerfile-report() {
|
||||
declare desc="displays a builder-dockerfile report for one or more apps"
|
||||
declare cmd="builder-dockerfile: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-dockerfile-report-single "$app" "$INFO_FLAG" | tee || true
|
||||
done
|
||||
else
|
||||
cmd-builder-dockerfile-report-single "$APP" "$INFO_FLAG"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd-builder-dockerfile-report-single() {
|
||||
declare APP="$1" INFO_FLAG="$2"
|
||||
if [[ "$INFO_FLAG" == "true" ]]; then
|
||||
INFO_FLAG=""
|
||||
fi
|
||||
verify_app_name "$APP"
|
||||
local flag_map=(
|
||||
"--builder-dockerfile-computed-dockerfile-path: $(fn-builder-dockerfile-computed-dockerfile-path "$APP")"
|
||||
"--builder-dockerfile-global-dockerfile-path: $(fn-builder-dockerfile-global-dockerfile-path "$APP")"
|
||||
"--builder-dockerfile-dockerfile-path: $(fn-builder-dockerfile-dockerfile-path "$APP")"
|
||||
)
|
||||
|
||||
if [[ -z "$INFO_FLAG" ]]; then
|
||||
dokku_log_info2_quiet "${APP} builder-dockerfile 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-dockerfile-computed-dockerfile-path() {
|
||||
declare APP="$1"
|
||||
|
||||
file="$(fn-builder-dockerfile-dockerfile-path "$APP")"
|
||||
if [[ "$file" == "" ]]; then
|
||||
file="$(fn-builder-dockerfile-global-dockerfile-path "$APP")"
|
||||
fi
|
||||
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
fn-builder-dockerfile-global-dockerfile-path() {
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-get "builder-dockerfile" "--global" "dockerfile-path" "Dockerfile"
|
||||
}
|
||||
|
||||
fn-builder-dockerfile-dockerfile-path() {
|
||||
declare APP="$1"
|
||||
|
||||
fn-plugin-property-get "builder-dockerfile" "$APP" "dockerfile-path" ""
|
||||
}
|
||||
6
plugins/builder-dockerfile/report
Executable file
6
plugins/builder-dockerfile/report
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-dockerfile/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-builder-dockerfile-report-single "$@"
|
||||
6
plugins/builder-dockerfile/subcommands/default
Executable file
6
plugins/builder-dockerfile/subcommands/default
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-dockerfile/help-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-builder-dockerfile-help "builder-dockerfile:help"
|
||||
6
plugins/builder-dockerfile/subcommands/report
Executable file
6
plugins/builder-dockerfile/subcommands/report
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_AVAILABLE_PATH/builder-dockerfile/internal-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-builder-dockerfile-report "$@"
|
||||
30
plugins/builder-dockerfile/subcommands/set
Executable file
30
plugins/builder-dockerfile/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-dockerfile-set() {
|
||||
declare desc="set or clear a builder-dockerfile property for an app"
|
||||
declare cmd="builder-dockerfile:set"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
declare APP="$1" KEY="$2" VALUE="$3"
|
||||
local VALID_KEYS=("dockerfile-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: dockerfile-path"
|
||||
fi
|
||||
|
||||
if [[ -n "$VALUE" ]]; then
|
||||
dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}"
|
||||
fn-plugin-property-write "builder-dockerfile" "$APP" "$KEY" "$VALUE"
|
||||
else
|
||||
dokku_log_info2_quiet "Unsetting ${KEY}"
|
||||
fn-plugin-property-delete "builder-dockerfile" "$APP" "$KEY"
|
||||
fi
|
||||
}
|
||||
|
||||
cmd-builder-dockerfile-set "$@"
|
||||
Reference in New Issue
Block a user