Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to use custom docker arguments when creating the service #149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# dokku mysql [![Build Status](https://img.shields.io/github/workflow/status/dokku/dokku-mysql/CI/master?style=flat-square "Build Status")](https://github.com/dokku/dokku-mysql/actions/workflows/ci.yml?query=branch%3Amaster) [![IRC Network](https://img.shields.io/badge/irc-libera-blue.svg?style=flat-square "IRC Libera")](https://webchat.libera.chat/?channels=dokku)

Official mysql plugin for dokku. Currently defaults to installing [mysql 8.0.29](https://hub.docker.com/_/mysql/).
Official mysql plugin for dokku. Currently defaults to installing [mysql 8.0.31](https://hub.docker.com/_/mysql/).

## Requirements

Expand Down Expand Up @@ -66,6 +66,7 @@ dokku mysql:create <service> [--create-flags...]
flags:

- `-c|--config-options "--args --go=here"`: extra arguments to pass to the container create command (default: `None`)
- `-D|--docker-options "--args"`: extra arguments to pass to the docker run command
- `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with
- `-i|--image IMAGE`: the image name to start the service with
- `-I|--image-version IMAGE_VERSION`: the image version to start the service with
Expand Down
10 changes: 9 additions & 1 deletion common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ service_commit_config() {
echo "$SERVICE_SHM_SIZE" >"$SERVICE_ROOT/SHM_SIZE"
fi

if [[ -n "$SERVICE_DOCKER_OPTIONS" ]]; then
echo "$SERVICE_DOCKER_OPTIONS" >"$SERVICE_ROOT/DOCKER_OPTIONS"
fi

if [[ -n "$PLUGIN_IMAGE" ]]; then
echo "$PLUGIN_IMAGE" >"$SERVICE_ROOT/IMAGE"
fi
Expand Down Expand Up @@ -688,6 +692,7 @@ service_parse_args() {
"--config-options") set -- "$@" "-c" ;;
"--custom-env") set -- "$@" "-C" ;;
"--database") set -- "$@" "-d" ;;
"--docker-options") set -- "$@" "-D" ;;
"--image-version") set -- "$@" "-I" ;;
"--image") set -- "$@" "-i" ;;
"--memory") set -- "$@" "-m" ;;
Expand All @@ -702,7 +707,7 @@ service_parse_args() {
done

OPTIND=1
while getopts "a:c:C:d:i:I:m:p:q:R:r:s:u:" opt; do
while getopts "a:c:C:d:D:i:I:m:p:q:R:r:s:u:" opt; do
case "$opt" in
a)
SERVICE_ALIAS="${OPTARG^^}"
Expand All @@ -717,6 +722,9 @@ service_parse_args() {
d)
export SERVICE_DATABASE=$OPTARG
;;
D)
export SERVICE_DOCKER_OPTIONS=$OPTARG
;;
i)
export PLUGIN_IMAGE=$OPTARG
;;
Expand Down
7 changes: 6 additions & 1 deletion functions
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,16 @@ service_create_container() {
SHM_SIZE="--shm-size=${SERVICE_SHM_SIZE}"
fi

[[ -f "$SERVICE_ROOT/DOCKER_OPTIONS" ]] && SERVICE_DOCKER_OPTIONS="$(cat "$SERVICE_ROOT/DOCKER_OPTIONS")"
if [[ -n "SERVICE_DOCKER_OPTIONS" ]]; then
DOCKER_OPTIONS="${SERVICE_DOCKER_OPTIONS}"
fi

[[ -f "$SERVICE_ROOT/IMAGE" ]] && PLUGIN_IMAGE="$(cat "$SERVICE_ROOT/IMAGE")"
[[ -f "$SERVICE_ROOT/IMAGE_VERSION" ]] && PLUGIN_IMAGE_VERSION="$(cat "$SERVICE_ROOT/IMAGE_VERSION")"

# shellcheck disable=SC2086
ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE -v "$SERVICE_HOST_ROOT/data:/var/lib/mysql" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/etc/mysql/conf.d" -e "MYSQL_ROOT_PASSWORD=$ROOTPASSWORD" -e MYSQL_USER=mysql -e "MYSQL_PASSWORD=$PASSWORD" -e "MYSQL_DATABASE=$DATABASE_NAME" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=mysql "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS)
ID=$(docker run --name "$SERVICE_NAME" $MEMORY_LIMIT $SHM_SIZE $DOCKER_OPTIONS -v "$SERVICE_HOST_ROOT/data:/var/lib/mysql" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/etc/mysql/conf.d" -e "MYSQL_ROOT_PASSWORD=$ROOTPASSWORD" -e MYSQL_USER=mysql -e "MYSQL_PASSWORD=$PASSWORD" -e "MYSQL_DATABASE=$DATABASE_NAME" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=mysql "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" $CONFIG_OPTIONS)
echo "$ID" >"$SERVICE_ROOT/ID"

dokku_log_verbose_quiet "Waiting for container to be ready"
Expand Down
1 change: 1 addition & 0 deletions subcommands/create
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ service-create-cmd() {
#E dokku $PLUGIN_COMMAND_PREFIX:create lollipop
#A service, service to run command against
#F -c|--config-options "--args --go=here", extra arguments to pass to the container create command
#F -D|--docker-options "--args", extra arguments to pass to the docker run command
#F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
#F -i|--image IMAGE, the image name to start the service with
#F -I|--image-version IMAGE_VERSION, the image version to start the service with
Expand Down