Skip to content

Commit

Permalink
initial pass at including docker-options plugin. closes #1062
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelshobbs committed Apr 1, 2015
1 parent 89af9cf commit df8f4fb
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 0 deletions.
60 changes: 60 additions & 0 deletions docs/docker-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
docker-options
========================

Usage
-----

```bash
$ dokku help
...
docker-options <app> Display apps docker options for all phases
docker-options <app> <phase(s)> Display apps docker options for phase (comma seperated phase list)
docker-options:add <app> <phase(s)> OPTION Add docker option to app for phase (comma seperated phase list)
docker-options:remove <app> <phase(s)> OPTION Remove docker option from app for phase (comma seperated phase list)
...
````

Add some options

```bash
$ dokku docker-options:add myapp deploy "-v /host/path:/container/path"
$ dokku docker-options:add myapp run "-v /another/container/path"
$ dokku docker-options:add myapp "-link container_name:alias"
```

Check what we added

```bash
$ dokku docker-options myapp
-link container_name:alias
-v /host/path:/container/path
-v /another/container/path
```

This comment has been minimized.

Copy link
@ootoovak

ootoovak Apr 26, 2015

As well as this generic spec example it would be great if you could also include a actual example. I don't know if this is right but something like:


Say we have an app called blog and it is hosted at /apps/blog and we create a new container for hosting our files using the command ...? and created at a file path /apps/files. Now with that set-up allowing the blog app to store files:

dokku docker-options:add blog deploy "-v /apps/blog"
$ dokku docker-options:add blog run "-v /apps/files"
$ dokku docker-options:add blog "-link files:alias"

Now we can check what we added:

dokku docker-options blog
-link files:alias
-v /apps/blog
-v /apps/files

Now you can use the persistant file storage your your blog like this:

Example of how you might access the file store (maybe with the example Node app?)

Thanks for the great work so far!

This comment has been minimized.

Copy link
@josegonzalez

josegonzalez Apr 27, 2015

Member

Pull requests welcome :)

This comment has been minimized.

Copy link
@ootoovak

ootoovak Apr 27, 2015

What I was looking for was persistent disk space. I found a guide here under "Adding persistent volumes for plugins and themes" that seems to be what I was looking for. Still might be useful to have in the docs as well as a use case for docker-options. Cheers!

This comment has been minimized.

Copy link
@ootoovak

ootoovak Apr 27, 2015

@josegonzalez yeah for sure. I have to understand and get it working myself first. 😄 I think it is what I am looking for but I'm not sure yet, nor am I sure how to use it properly either. I'll endeavor to figure it out and try post back when I do.


Remove an option
```bash
$ dokku docker-options:remove myapp "-link container_name:alias"
```

Manual Usage
------------

In your applications folder (/home/dokku/app_name) create a file called DOCKER_OPTIONS.

Inside this file list one docker option per line. For example:

```bash
-link container_name:alias
-v /host/path:/container/path
-v /another/container/path
```

The above example will result in the following options being passed to docker during deploy and docker run:

```bash
-link container_name:alias -v /host/path:/container/path -v /another/container/path
```

You may also include comments (lines beginning with a #) and blank lines in the DOCKER_OPTIONS file.

Move information on docker options can be found here: http://docs.docker.io/en/latest/reference/run/ .
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Docker powered mini-Heroku. The smallest PaaS implementation you've ever seen.
- [DNS Configuration](http://progrium.viewdocs.io/dokku/dns)
- [Nginx Configuration](http://progrium.viewdocs.io/dokku/nginx)
- [Running Remote commands](http://progrium.viewdocs.io/dokku/remote-commands)
- [Container Options](http://progrium.viewdocs.io/dokku/docker-options)

### Community Contributions

Expand Down
149 changes: 149 additions & 0 deletions plugins/docker-options/commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"

PHASES=(build deploy run)

FILE_PREFIX="DOCKER_OPTIONS_"

get_app() {
[[ -z $1 ]] && dokku_log_fail "Please specify an app to run the command on"
verify_app_name "$1"
APP="$1"
}

get_phases() {
local passed_phases_list=$1
local phase
if [[ -n $passed_phases_list ]]; then
IFS=',' read -ra passed_phases <<< "$passed_phases_list"
for phase in "${passed_phases[@]}"; do
verify_phase $phase
done
fi
}

verify_phase() {
local phase
for phase in "${PHASES[@]}"; do
if [[ "$phase" = "$1" ]]; then
return 0
fi
done
dokku_log_fail "Phase(s) must be one of [${PHASES[@]}]"
}

get_phase_file_path() {
local phase=$1
phase_file_path="${DOKKU_ROOT}/${APP}/${FILE_PREFIX}${phase^^}"
}

create_phase_file_if_required() {
local phase_file_path=$1
[[ -f $phase_file_path ]] || {
touch $phase_file_path
}
}

display_phase_options() {
local phase=$1
local phase_file_path=$2
echo "${phase^} options:"
sed -e 's/^/ /' $phase_file_path
}

display_all_phases_options() {
for phase in "${PHASES[@]}"; do
get_phase_file_path $phase
if [[ -s $phase_file_path ]] ; then
display_phase_options $phase $phase_file_path
fi
done
}

display_passed_phases_options() {
local passed_phases=("${!1}")
local phase
for phase in "${passed_phases[@]}"; do
get_phase_file_path $phase
if [ ! -s $phase_file_path ] ; then
echo "${phase^} options: none"
else
display_phase_options $phase $phase_file_path
fi
done
}

get_passed_docker_option() {
[[ -z "$@" ]] && dokku_log_fail "Please specify docker options to add to the phase"
passed_docker_option=("$@")
}

add_passed_docker_option() {
local passed_phases=("${!1}")
local passed_option_string=$2
local phase
for phase in "${passed_phases[@]}"; do
get_phase_file_path $phase
create_phase_file_if_required $phase_file_path
echo "${passed_option_string}" >> $phase_file_path
all_phase_options=$(< $phase_file_path)
echo -e "${all_phase_options}" | sed '/^$/d' | sort -u > $phase_file_path
done
}

remove_passed_docker_option() {
local passed_phases=("${!1}")
local passed_option_string=$2
local phase
for phase in "${passed_phases[@]}"; do
get_phase_file_path $phase
[[ ! -s $phase_file_path ]] || {
all_phase_options=$(< $phase_file_path)
all_phase_options=$(echo -e "${all_phase_options}" | sed "s#^${passed_option_string}\$##")
echo -e "${all_phase_options}" | sed '/^$/d' | sort -u > $phase_file_path
}
done
}

case "$1" in
# Display applications docker options
docker-options)
get_app $2
get_phases $3
if [[ ! "${passed_phases[@]}" ]]; then
display_all_phases_options
else
display_passed_phases_options passed_phases[@]
fi
;;

# Add a docker option to application
docker-options:add)
get_app $2
get_phases $3
shift 3 # everything else passed is the docker option
get_passed_docker_option "$@"
add_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
;;

# Remove a docker option from application
docker-options:remove)
get_app $2
get_phases $3
shift 3 # everything else passed is the docker option
get_passed_docker_option "$@"
remove_passed_docker_option passed_phases[@] "${passed_docker_option[@]}"
;;

# Display usage help
help)
cat && cat<<EOF
docker-options <app> Display apps docker options for all phases
docker-options <app> <phase(s)> Display apps docker options for phase (comma seperated phase list)
docker-options:add <app> <phase(s)> OPTION Add docker option to app for phase (comma seperated phase list)
docker-options:remove <app> <phase(s)> OPTION Remove docker option from app for phase (comma seperated phase list)
EOF
;;

esac
1 change: 1 addition & 0 deletions plugins/docker-options/docker-args-build
43 changes: 43 additions & 0 deletions plugins/docker-options/docker-args-deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x

STDIN=$(cat)
APP="$1"

case "$0" in
*docker-args-build)
PHASE=BUILD
;;
*docker-args-deploy)
PHASE=DEPLOY
;;
*docker-args-run)
PHASE=RUN
;;
esac

FILE_PREFIX="DOCKER_OPTIONS_"
PHASE_FILE_PATH="${DOKKU_ROOT}/${APP}/${FILE_PREFIX}${PHASE}"

output=""

if [[ -f "$PHASE_FILE_PATH" ]]; then
DONE=false
until $DONE; do
read line || DONE=true

[[ ! -n "$line" ]] && continue

# shellcheck disable=SC1001
case "$line" in
\#*)
continue
;;
*)
output="$output $line"
;;
esac
done < $PHASE_FILE_PATH
fi

echo "$STDIN$output"
1 change: 1 addition & 0 deletions plugins/docker-options/docker-args-run
Loading

0 comments on commit df8f4fb

Please sign in to comment.