Skip to content

Commit 79372bb

Browse files
committed
added Dockerfile support
1 parent 511abaf commit 79372bb

5 files changed

Lines changed: 102 additions & 67 deletions

File tree

‎dokku‎

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,11 @@ if [[ "$1" == "" ]]; then
2323
fi
2424

2525
case "$1" in
26-
receive)
27-
verify_app_name "$2"
28-
info "Cleaning up ..."
29-
flock -n "$DOKKU_ROOT/cleanup.lock" dokku cleanup || true
30-
info "Building $APP ..."
31-
cat | dokku build $APP
32-
info "Releasing $APP ..."
33-
dokku release $APP
34-
info "Deploying $APP ..."
35-
dokku deploy $APP
36-
info2 "Application deployed:"
37-
verbose "$(dokku url $APP)"
38-
echo
39-
;;
40-
41-
build)
42-
verify_app_name "$2"
43-
cat | docker run -i -a stdin progrium/buildstep /bin/bash \
44-
-c "mkdir -p /app && tar -xC /app" | commit_image "$IMAGE_GENERIC:build"
45-
[[ -d "$CACHE_DIR" ]] || mkdir "$CACHE_DIR"
46-
pluginhook pre-build "$APP"
47-
DOCKER_ARGS="$(: | pluginhook docker-args "$APP" build)"
48-
docker run -i -a stdin -v "$CACHE_DIR":/cache \
49-
$DOCKER_ARGS \
50-
"$IMAGE_GENERIC:build" \
51-
/build/builder | attach_and_commit_image "$IMAGE_GENERIC:build"
52-
pluginhook post-build "$APP"
53-
;;
54-
5526
release)
5627
verify_app_name "$2"
28+
verify_max_args "2" "$@"
29+
30+
info "Releasing $APP ..."
5731
tag_image "$IMAGE_GENERIC:build" "$IMAGE_GENERIC:release"
5832
pluginhook pre-release "$APP"
5933
if [[ -f "$DOKKU_ROOT/$APP/ENV" ]]; then
@@ -65,6 +39,9 @@ case "$1" in
6539

6640
deploy)
6741
verify_app_name "$2"
42+
verify_max_args "2" "$@"
43+
44+
info "Deploying $APP ..."
6845
tag_image "$IMAGE_GENERIC:release" "$IMAGE_GENERIC:latest"
6946
pluginhook pre-deploy "$APP"
7047

@@ -73,23 +50,32 @@ case "$1" in
7350

7451
# start the app
7552
DOCKER_ARGS="$(: | pluginhook docker-args "$APP" web)"
76-
id=$(docker run -d -p "$APP_PORT" -e PORT="$APP_PORT" --name="$APP_NAME" $DOCKER_ARGS "$IMAGE_GENERIC:latest" /bin/bash -c "/start web")
77-
port=$(docker port $id 5000 | sed 's/0.0.0.0://')
78-
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$port" > "$DOKKU_ROOT/$APP/URL"
7953

80-
# finish deployment
81-
pluginhook post-deploy "$APP" "$port"
54+
if docker run --rm "$IMAGE" test -f /exec; then
55+
# buildstep
56+
INT_PORT="$APP_PORT"
57+
id=$(docker run -d -p "$INT_PORT" -e PORT="$INT_PORT" --name="$APP_NAME" $DOCKER_ARGS "$IMAGE_GENERIC:latest" /bin/bash -c "/start web")
58+
addr=$(docker port $id "$INT_PORT")
59+
port=${addr#*:}
60+
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$port" > "$DOKKU_ROOT/$APP/URL"
61+
pluginhook post-deploy "$APP" "$port" "$INT_PORT"
62+
else
63+
# Dockerfile
64+
INT_PORT="80"
65+
id=$(docker run -d -p "$INT_PORT" --name="$APP_NAME" $DOCKER_ARGS "$IMAGE_GENERIC:latest")
66+
addr=$(docker port $id "$INT_PORT")
67+
port=${addr#*:}
68+
echo "http://$(< "$DOKKU_ROOT/HOSTNAME"):$port" > "$DOKKU_ROOT/$APP/URL"
69+
pluginhook post-deploy "$APP" "$port" "$INT_PORT"
70+
fi
8271

83-
# cleanup at the end
84-
sleep 2s
85-
remove_container $APP_ALL_NAMES
86-
flock -n "$DOKKU_ROOT/cleanup.lock" dokku cleanup &
72+
info2 "Application deployed:"
73+
verbose "$(dokku url $APP)"
8774
;;
8875

8976
cleanup)
90-
# delete all non-running container - it's not very wise
91-
# docker ps -a | grep 'Exit' | awk '{print $1}' | xargs docker rm &> /dev/null || true
92-
# delete unused images
77+
info "Cleaning up ..."
78+
docker ps -a | grep 'Exit' | grep -v "seconds ago" | awk '{print $1}' | xargs docker rm &> /dev/null || true
9379
docker images | grep '<none>' | awk '{print $3}' | xargs docker rmi &> /dev/null || true
9480
;;
9581

‎plugins/00_dokku-standard/commands‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ case "$1" in
5151
docker rm -f "$APP_RUN_NAME" 1>/dev/null 2>/dev/null || true
5252

5353
DOCKER_ARGS=$(: | pluginhook docker-args $APP run)
54-
docker run --rm --name="$APP_RUN_NAME" -i -t $DOCKER_ARGS "$IMAGE" /exec "$@"
54+
55+
if docker run --rm "$IMAGE" test -f /exec; then
56+
# buildstep
57+
docker run --rm --name="$APP_RUN_NAME" -i -t $DOCKER_ARGS "$IMAGE" /exec "$@"
58+
else
59+
# Dockerfile
60+
docker run --rm --name="$APP_RUN_NAME" -i -t $DOCKER_ARGS "$IMAGE" --entrypoint="/bin/bash"
61+
fi
5562
;;
5663

5764
url)

‎plugins/dokku-rebuild/commands‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,70 @@
22

33
source "$(dirname $0)/../dokku_common"
44

5+
dokku_build_app_from_git() {
6+
verify_app_name "$1"
7+
verify_max_args "2" "$@"
8+
REV="$2"
9+
10+
flock -n "$DOKKU_ROOT/cleanup.lock" dokku cleanup || true &
11+
12+
# delete directory on return
13+
TMP_WORK_DIR="$(mktemp -d)"
14+
trap "rm -rf \"$TMP_WORK_DIR\"" RETURN
15+
16+
# clone git repository
17+
chmod 755 "$TMP_WORK_DIR"
18+
unset GIT_DIR GIT_WORK_TREE
19+
git clone "$DOKKU_ROOT/$APP" "$TMP_WORK_DIR" > /dev/null
20+
pushd "$TMP_WORK_DIR" > /dev/null
21+
git config advice.detachedHead false
22+
git checkout "$REV" > /dev/null
23+
git submodule update --init --recursive > /dev/null
24+
find -name .git -prune -exec rm -rf {} \; > /dev/null
25+
26+
# wait for cleanup
27+
wait
28+
29+
if [[ -f "Dockerfile" ]]; then
30+
info "Building $APP using Dockerfile..."
31+
docker build -t "$IMAGE_GENERIC:build" .
32+
pluginhook pre-build "$APP"
33+
pluginhook post-build "$APP"
34+
else
35+
info "Building $APP using buildstep..."
36+
37+
tar c . | docker run -i -a stdin "progrium/buildstep" /bin/bash \
38+
-c "mkdir -p /app && tar -xC /app" | commit_image "$IMAGE_GENERIC:build"
39+
[[ -d "$CACHE_DIR" ]] || mkdir "$CACHE_DIR"
40+
41+
pluginhook pre-build "$APP"
42+
DOCKER_ARGS="$(: | pluginhook docker-args "$APP" build)"
43+
docker run -i -a stdin -v "$CACHE_DIR":/cache \
44+
$DOCKER_ARGS \
45+
"$IMAGE_GENERIC:build" \
46+
/build/builder | attach_and_commit_image "$IMAGE_GENERIC:build"
47+
48+
pluginhook post-build "$APP"
49+
fi
50+
51+
dokku release "$APP"
52+
dokku deploy "$APP"
53+
}
54+
555
case "$1" in
656
rebuild)
757
verify_app_name "$2"
8-
verify_max_args 2 "$@"
58+
verify_max_args 3 "$@"
959

10-
REF=$(cat "$APP_DIR/refs/heads/master")
11-
cd "$APP_DIR" && git archive "$REF" | dokku receive "$APP" | sed -u "s/^/"$'\e[1G'"/"
60+
if [[ $# -ge 3 ]]; then
61+
REF="$3"
62+
elif [[ -f "$APP_DIR/refs/heads/master" ]]; then
63+
REF="$(cat "$APP_DIR/refs/heads/master")"
64+
else
65+
fail "$APP: No refs/heads/master found"
66+
fi
67+
68+
dokku_build_app_from_git "$APP" "$REF" | sed -u "s/^/"$'\e[1G'"/"
1269
;;
1370

1471
rebuild:all)

‎plugins/git/commands‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@
22

33
source "$(dirname $0)/../dokku_common"
44

5-
git_archive_all() {
6-
APP=$1; REV=$2
7-
TMP_WORK_DIR=$(mktemp -d)
8-
chmod 755 $TMP_WORK_DIR
9-
unset GIT_DIR GIT_WORK_TREE
10-
git clone $DOKKU_ROOT/$APP $TMP_WORK_DIR > /dev/null
11-
pushd $TMP_WORK_DIR > /dev/null
12-
git config advice.detachedHead false
13-
git checkout $REV > /dev/null
14-
git submodule update --init --recursive > /dev/null
15-
find -name .git -prune -exec rm -rf {} \; > /dev/null
16-
tar c .
17-
popd > /dev/null
18-
rm -rf $TMP_WORK_DIR > /dev/null
19-
}
20-
215
case "$1" in
226
git-hook)
237
verify_app_name "$2"
@@ -27,7 +11,7 @@ case "$1" in
2711
# Only run this script for the master branch. You can remove this
2812
# if block if you wish to run it for others as well.
2913
if [[ $refname = "refs/heads/master" ]] ; then
30-
git_archive_all "$APP" "$newrev" | dokku receive "$APP" | sed -u "s/^/"$'\e[1G'"/"
14+
dokku rebuild "$APP" "$newrev"
3115
else
3216
echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master."
3317
echo $'\e[1G\e[K'"-----> for example, try 'git push <dokku> ${refname/refs\/heads\/}:master'"
@@ -46,9 +30,9 @@ case "$1" in
4630
cat > "$PRERECEIVE_HOOK" <<EOF
4731
#!/usr/bin/env bash
4832
set -e; set -o pipefail;
49-
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook $APP
33+
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook "$APP"
5034
EOF
51-
chmod +x $PRERECEIVE_HOOK
35+
chmod +x "$PRERECEIVE_HOOK"
5236
fi
5337

5438
verify_app_name "$APP"

‎plugins/nginx-vhosts/post-deploy‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
source "$(dirname $0)/../dokku_common"
44

5-
APP="$1"; PORT="$2"
5+
APP="$1"; PORT="$2"; INT_PORT="$3"
6+
[[ "$INT_PORT" != "" ]] || INT_PORT="$APP_PORT"
67
WILDCARD_SSL="$DOKKU_ROOT/ssl"
78
SSL="$DOKKU_ROOT/$APP/ssl"
89

@@ -60,7 +61,7 @@ server {
6061
6162
location / {
6263
proxy_pass http://$APP;
63-
proxy_redirect http://$hostname:5000/ https://$hostname/;
64+
proxy_redirect http://$hostname:$INT_PORT/ https://$hostname/;
6465
proxy_http_version 1.1;
6566
proxy_set_header Upgrade \$http_upgrade;
6667
proxy_set_header Connection "upgrade";
@@ -84,7 +85,7 @@ server {
8485
server_name $hostname;
8586
location / {
8687
proxy_pass http://$APP;
87-
proxy_redirect http://$hostname:5000/ http://$hostname/;
88+
proxy_redirect http://$hostname:$INT_PORT/ http://$hostname/;
8889
proxy_http_version 1.1;
8990
proxy_set_header Upgrade \$http_upgrade;
9091
proxy_set_header Connection "upgrade";

0 commit comments

Comments
 (0)