From 2834ce1f1af5615491a5d5b6e1a67185a92f1f59 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 25 Feb 2015 19:45:20 -0800 Subject: [PATCH 1/3] extract first port from Dockerfile and set config variable for use in deploy phase. closes #993 --- dokku | 6 ++++-- plugins/00_dokku-standard/commands | 3 +++ tests/apps/dockerfile/Dockerfile | 2 +- tests/unit/ports.bats | 8 ++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dokku b/dokku index 467d0f759..3b4a7c26a 100755 --- a/dokku +++ b/dokku @@ -75,10 +75,12 @@ case "$1" in DOCKER_ARGS+=$(: | pluginhook docker-args-deploy $APP) BIND_EXTERNAL=$(pluginhook bind-external-ip $APP) - is_image_buildstep_based "$IMAGE" && START_CMD="/start web" + is_image_buildstep_based "$IMAGE" && DOKKU_BUILDSTEP=true + [[ -n "$DOKKU_BUILDSTEP" ]] && START_CMD="/start web" + [[ -z "$DOKKU_BUILDSTEP" ]] && eval "$(grep DOKKU_DOCKERFILE_PORT $DOKKU_ROOT/$APP/ENV)" if [[ "$BIND_EXTERNAL" = "false" ]];then - port=5000 + port=${DOKKU_DOCKERFILE_PORT:=5000} id=$(docker run -d -e PORT=$port $DOCKER_ARGS $IMAGE $START_CMD) ipaddr=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $id) else diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 364d95606..81d989655 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -34,6 +34,9 @@ case "$1" in ;; dockerfile) + # extract first port from Dockerfile + DOCKERFILE_PORT=$(grep EXPOSE Dockerfile | head -1 | awk '{ print $2 }') + [[ -n "$DOCKERFILE_PORT" ]] && dokku config:set $APP DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT # sticking with same pattern of building app image before pre-build for now. docker build -t "$IMAGE" . # buildstep pluginhooks don't necessarily make sense for dockerfiles. call the new breed!!! diff --git a/tests/apps/dockerfile/Dockerfile b/tests/apps/dockerfile/Dockerfile index badf138d9..cdae029b0 100644 --- a/tests/apps/dockerfile/Dockerfile +++ b/tests/apps/dockerfile/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:trusty ENV LC_ALL C ENV DEBIAN_FRONTEND noninteractive ENV DEBCONF_NONINTERACTIVE_SEEN true -EXPOSE 5000 +EXPOSE 3000 RUN apt-get install -y software-properties-common && add-apt-repository ppa:chris-lea/node.js && apt-get update RUN apt-get install -y build-essential curl postgresql-client-9.3 nodejs git diff --git a/tests/unit/ports.bats b/tests/unit/ports.bats index bace5c786..3612c5932 100644 --- a/tests/unit/ports.bats +++ b/tests/unit/ports.bats @@ -108,3 +108,11 @@ teardown() { echo "status: "$status assert_success } + +@test "dockerfile port exposure" { + deploy_app dockerfile + run bash -c "grep upstream $DOKKU_ROOT/$TEST_APP/nginx.conf | grep 3000" + echo "output: "$output + echo "status: "$status + assert_success +} From 1a7586cd03bc4e0d67cc9ac2eb7a93e899142032 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Wed, 25 Feb 2015 20:34:32 -0800 Subject: [PATCH 2/3] don't use config:set --- plugins/00_dokku-standard/commands | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 81d989655..fe558aa51 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -36,7 +36,13 @@ case "$1" in dockerfile) # extract first port from Dockerfile DOCKERFILE_PORT=$(grep EXPOSE Dockerfile | head -1 | awk '{ print $2 }') - [[ -n "$DOCKERFILE_PORT" ]] && dokku config:set $APP DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT + if [[ -n "$DOCKERFILE_PORT" ]];then + if [[ -f "$DOKKU_ROOT/$APP/ENV" ]] && [[ "$(grep DOKKU_DOCKERFILE_PORT $DOKKU_ROOT/$APP/ENV) > /dev/null 2>&1; echo $?" == "0" ]];then + sed -i -e "s:DOKKU_DOCKERFILE_PORT=.*:DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT:g" "$DOKKU_ROOT/$APP/ENV" + else + echo "export DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT" >> "$DOKKU_ROOT/$APP/ENV" + fi + fi # sticking with same pattern of building app image before pre-build for now. docker build -t "$IMAGE" . # buildstep pluginhooks don't necessarily make sense for dockerfiles. call the new breed!!! From 767b45ae562795442fdc70ecfb71c8918f7543cc Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Thu, 19 Mar 2015 08:09:11 -0700 Subject: [PATCH 3/3] use config:set-norestart --- plugins/00_dokku-standard/commands | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index fe558aa51..6f8ca6642 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -36,13 +36,8 @@ case "$1" in dockerfile) # extract first port from Dockerfile DOCKERFILE_PORT=$(grep EXPOSE Dockerfile | head -1 | awk '{ print $2 }') - if [[ -n "$DOCKERFILE_PORT" ]];then - if [[ -f "$DOKKU_ROOT/$APP/ENV" ]] && [[ "$(grep DOKKU_DOCKERFILE_PORT $DOKKU_ROOT/$APP/ENV) > /dev/null 2>&1; echo $?" == "0" ]];then - sed -i -e "s:DOKKU_DOCKERFILE_PORT=.*:DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT:g" "$DOKKU_ROOT/$APP/ENV" - else - echo "export DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT" >> "$DOKKU_ROOT/$APP/ENV" - fi - fi + [[ -n "$DOCKERFILE_PORT" ]] && dokku config:set-norestart $APP DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT + # sticking with same pattern of building app image before pre-build for now. docker build -t "$IMAGE" . # buildstep pluginhooks don't necessarily make sense for dockerfiles. call the new breed!!!