这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
2 changes: 1 addition & 1 deletion plugins/00_dokku-standard/commands
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ case "$1" in

dockerfile)
# extract first port from Dockerfile
DOCKERFILE_PORT=$(grep EXPOSE Dockerfile | head -1 | awk '{ print $2 }' || true)
DOCKERFILE_PORT=$(get_dockerfile_exposed_port Dockerfile)
[[ -n "$DOCKERFILE_PORT" ]] && dokku config:set-norestart $APP DOKKU_DOCKERFILE_PORT=$DOCKERFILE_PORT

# buildstep pluginhooks don't necessarily make sense for dockerfiles. call the new breed!!!
Expand Down
9 changes: 9 additions & 0 deletions plugins/common/functions
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,12 @@ get_container_ids() {
shopt -u nullglob
echo $DOKKU_CIDS
}

get_dockerfile_exposed_port() {
local DOCKERFILE_PORT=$(grep "^EXPOSE \+[[:digit:]]\+\(\/tcp\)\? *$" $1 | head -1 | sed 's/EXPOSE \+\([[:digit:]]\+\)\(\/tcp\)\?.*/\1/' || true)
if [[ -n "$DOCKERFILE_PORT" ]]; then
echo "$DOCKERFILE_PORT"
else
echo ""
fi
}
4 changes: 3 additions & 1 deletion tests/apps/dockerfile/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ FROM ubuntu:trusty
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
EXPOSE 3000
EXPOSE 3001/udp
EXPOSE 3000/tcp
EXPOSE 3003

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
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/core_ports.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load test_helper
setup() {
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -f "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -f "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
DOCKERFILE="$BATS_TMPDIR/Dockerfile"
}

teardown() {
Expand Down Expand Up @@ -162,3 +163,29 @@ check_urls() {

check_urls http://my-cool-guy-test-app.127.0.0.1.xip.io
}

@test "(core) port exposure (dockerfile raw port)" {
source "$PLUGIN_PATH/common/functions"
cat<<EOF > $DOCKERFILE
EXPOSE 3001/udp
EXPOSE 3003
EXPOSE 3000/tcp
EOF
run get_dockerfile_exposed_port $DOCKERFILE
echo "output: "$output
echo "status: "$status
assert_output 3003
}

@test "(core) port exposure (dockerfile tcp port)" {
source "$PLUGIN_PATH/common/functions"
cat<<EOF > $DOCKERFILE
EXPOSE 3001/udp
EXPOSE 3000/tcp
EXPOSE 3003
EOF
run get_dockerfile_exposed_port $DOCKERFILE
echo "output: "$output
echo "status: "$status
assert_output 3000
}
1 change: 1 addition & 0 deletions tests/unit/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# constants
DOKKU_ROOT=${DOKKU_ROOT:=~dokku}
PLUGIN_PATH=${PLUGIN_PATH:="/var/lib/dokku/plugins"}
TEST_APP=my-cool-guy-test-app

# test functions
Expand Down