diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..c80200c1d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*] +insert_final_newline = true +indent_style = space +indent_size = 2 diff --git a/contrib/dokku-installer.rb b/contrib/dokku-installer.rb index ef06f64d5..938ca8544 100755 --- a/contrib/dokku-installer.rb +++ b/contrib/dokku-installer.rb @@ -3,120 +3,120 @@ require "sinatra" require "open3" if ARGV[0] == "onboot" - File.open("/etc/init/dokku-installer.conf", "w") do |f| - f.puts "start on runlevel [2345]" - f.puts "exec #{File.absolute_path(__FILE__)} selfdestruct" - end - File.open("/etc/nginx/conf.d/dokku-installer.conf", "w") do |f| - f.puts "upstream dokku-installer { server 127.0.0.1:2000; }" - f.puts "server {" - f.puts " listen 80;" - f.puts " location / {" - f.puts " proxy_pass http://dokku-installer;" - f.puts " }" - f.puts "}" - end - `rm /etc/nginx/sites-enabled/*` - puts "Installed Upstart service and default Nginx virtualhost for installer to run on boot." - exit + File.open("/etc/init/dokku-installer.conf", "w") do |f| + f.puts "start on runlevel [2345]" + f.puts "exec #{File.absolute_path(__FILE__)} selfdestruct" + end + File.open("/etc/nginx/conf.d/dokku-installer.conf", "w") do |f| + f.puts "upstream dokku-installer { server 127.0.0.1:2000; }" + f.puts "server {" + f.puts " listen 80;" + f.puts " location / {" + f.puts " proxy_pass http://dokku-installer;" + f.puts " }" + f.puts "}" + end + `rm /etc/nginx/sites-enabled/*` + puts "Installed Upstart service and default Nginx virtualhost for installer to run on boot." + exit end -version = "v0.2.1" -dokku_root = ENV["DOKKU_ROOT"] || "/home/dokku" -admin_key = `cat /root/.ssh/authorized_keys`.split("\n").first -hostname = `bash -c '[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME || curl icanhazip.com'`.strip -template = DATA.read +version = "v0.3.0" +dokku_root = ENV["DOKKU_ROOT"] || "/home/dokku" +admin_key = `cat /root/.ssh/authorized_keys`.split("\n").first +hostname = `bash -c '[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME || curl icanhazip.com'`.strip +template = DATA.read set :port, 2000 set :environment, :production disable :protection get "/" do - ERB.new(template).result binding + ERB.new(template).result binding end post "/setup" do - if params[:vhost] == "true" - File.open("#{dokku_root}/VHOST", "w") {|f| f.write params[:hostname] } - else - `rm #{dokku_root}/VHOST` - end - File.open("#{dokku_root}/HOSTNAME", "w") {|f| f.write params[:hostname] } - Open3.capture2("sshcommand acl-add dokku admin", :stdin_data => params[:key]) - Thread.new { - `rm /etc/nginx/conf.d/dokku-installer.conf && /etc/init.d/nginx stop && /etc/init.d/nginx start` - `rm /etc/init/dokku-installer.conf && stop dokku-installer` - }.run if ARGV[0] == "selfdestruct" + if params[:vhost] == "true" + File.open("#{dokku_root}/VHOST", "w") {|f| f.write params[:hostname] } + else + `rm #{dokku_root}/VHOST` + end + File.open("#{dokku_root}/HOSTNAME", "w") {|f| f.write params[:hostname] } + Open3.capture2("sshcommand acl-add dokku admin", :stdin_data => params[:key]) + Thread.new { + `rm /etc/nginx/conf.d/dokku-installer.conf && /etc/init.d/nginx stop && /etc/init.d/nginx start` + `rm /etc/init/dokku-installer.conf && stop dokku-installer` + }.run if ARGV[0] == "selfdestruct" end __END__ - Dokku Setup - - + Dokku Setup + + -
-
-

Dokku Setup <%= version %>

-
-

Admin Access

-
- -
-
-

Hostname Configuration

-
- - -
-
- -
-

Your app URLs will look like:

-
http://hostname:port
-
- -
-
-
- +
+
+

Dokku Setup <%= version %>

+
+

Admin Access

+
+ +
+
+

Hostname Configuration

+
+ + +
+
+ +
+

Your app URLs will look like:

+
http://hostname:port
+
+ +
+
+
+ diff --git a/plugins/00_dokku-standard/backup-check b/plugins/00_dokku-standard/backup-check index 91e7bfb51..aae373832 100755 --- a/plugins/00_dokku-standard/backup-check +++ b/plugins/00_dokku-standard/backup-check @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + VERSION="$1" IMPORT_DIR="$2" TARGET_DIR="$3" @@ -15,4 +16,3 @@ for app in $APPS; do done exit $ret - diff --git a/plugins/00_dokku-standard/backup-export b/plugins/00_dokku-standard/backup-export index 651d0b3db..8a1fcf24c 100755 --- a/plugins/00_dokku-standard/backup-export +++ b/plugins/00_dokku-standard/backup-export @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + VERSION="$1" BASE_DIR="$2" diff --git a/plugins/00_dokku-standard/backup-import b/plugins/00_dokku-standard/backup-import index 86404a99b..eca5228b3 100755 --- a/plugins/00_dokku-standard/backup-import +++ b/plugins/00_dokku-standard/backup-import @@ -1,15 +1,16 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + VERSION="$1" IMPORT_DIR="$2" TARGET_DIR="$3" [[ -f $IMPORT_DIR/.sshcommand ]] && mv $IMPORT_DIR/.sshcommand $TARGET_DIR/.sshcommand if [[ -f $IMPORT_DIR/.ssh/authorized_keys ]]; then - mkdir -p $TARGET_DIR/.ssh - cat $IMPORT_DIR/.ssh/authorized_keys $TARGET_DIR/.ssh/authorized_keys | uniq > $TARGET_DIR/.ssh/authorized_keys - chmod 0700 $TARGET_DIR/.ssh - chmod 0600 $TARGET_DIR/.ssh/* + mkdir -p $TARGET_DIR/.ssh + cat $IMPORT_DIR/.ssh/authorized_keys $TARGET_DIR/.ssh/authorized_keys | uniq > $TARGET_DIR/.ssh/authorized_keys + chmod 0700 $TARGET_DIR/.ssh + chmod 0600 $TARGET_DIR/.ssh/* fi [[ -f $IMPORT_DIR/HOSTNAME ]] && mv $IMPORT_DIR/HOSTNAME $TARGET_DIR/HOSTNAME [[ -f $IMPORT_DIR/VHOST ]] && mv $IMPORT_DIR/VHOST $TARGET_DIR/VHOST diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 325beb1dc..8e4c36cb9 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -31,13 +31,13 @@ case "$1" in run) if [[ -z $2 ]]; then - echo "Please specify an app to run the command on" - exit 1 + echo "Please specify an app to run the command on" + exit 1 fi APP="$2"; IMAGE="dokku/$APP" if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 + echo "App $APP does not exist" + exit 1 fi shift 2 @@ -48,8 +48,8 @@ case "$1" in url) APP="$2"; if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then - echo "App $APP does not exist" - exit 1 + echo "App $APP does not exist" + exit 1 fi if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then @@ -74,4 +74,3 @@ EOF ;; esac - diff --git a/plugins/00_dokku-standard/install b/plugins/00_dokku-standard/install index bc804f546..9625e8fdc 100755 --- a/plugins/00_dokku-standard/install +++ b/plugins/00_dokku-standard/install @@ -2,7 +2,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x if [[ ! -f "$DOKKU_ROOT/HOSTNAME" ]]; then - echo $(hostname -f) > $DOKKU_ROOT/HOSTNAME + echo $(hostname -f) > $DOKKU_ROOT/HOSTNAME fi # temporary hack for https://github.com/progrium/dokku/issues/82 diff --git a/plugins/apps/commands b/plugins/apps/commands index c98546ab5..770f772f4 100755 --- a/plugins/apps/commands +++ b/plugins/apps/commands @@ -68,4 +68,3 @@ EOF ;; esac - diff --git a/plugins/backup/commands b/plugins/backup/commands index 9aa6cdc65..4c41037fc 100755 --- a/plugins/backup/commands +++ b/plugins/backup/commands @@ -1,7 +1,9 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + CURRENT_BACKUP_VERSION=1 -set -e; case "$1" in + +case "$1" in backup:export) OUTPUT_FILE="$2" BACKUP_DIR="$DOKKU_ROOT" @@ -24,9 +26,9 @@ set -e; case "$1" in # if no file specified, output to stdout if [[ -z $OUTPUT_FILE ]]; then - cat $BACKUP_TMP_FILE + cat $BACKUP_TMP_FILE else - mv $BACKUP_TMP_FILE $OUTPUT_FILE + mv $BACKUP_TMP_FILE $OUTPUT_FILE fi rm -rf $BACKUP_TMP_DIR @@ -48,14 +50,14 @@ set -e; case "$1" in tar xf $INPUT_FILE --directory=$BACKUP_TMP_DIR if [[ ! -f $BACKUP_TMP_DIR/.dokku_backup_version ]]; then - echo "Unable to determine backup version" - exit 1 + echo "Unable to determine backup version" + exit 1 fi VERSION=$(< $BACKUP_TMP_DIR/.dokku_backup_version) if [[ $VERSION -ne 1 ]]; then - echo "Unknown format version $VERSION" - exit 1 + echo "Unknown format version $VERSION" + exit 1 fi echo "Importing a version $VERSION backup..." @@ -91,4 +93,3 @@ EOF ;; esac - diff --git a/plugins/checks/check-deploy b/plugins/checks/check-deploy index 6db3f6444..00346af5b 100755 --- a/plugins/checks/check-deploy +++ b/plugins/checks/check-deploy @@ -14,6 +14,7 @@ # in seconds). set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + CONTAINERID="$1"; APP="$2"; PORT="$3" ; HOSTNAME="${4:-localhost}" # source in app env to get DOKKU_CHECKS_WAIT and any other necessary vars @@ -27,23 +28,23 @@ WAIT="${DOKKU_CHECKS_WAIT:-5}" # after successfully copying the file. Thus, we suppress stderr. # ref: https://github.com/dotcloud/docker/issues/3986 if [[ ! -f "$FILENAME" ]] ; then - echo " check-deploy: $FILENAME not found. attempting to retrieve it from container ..." - TMPDIR=$(mktemp -d /tmp/CHECKS.XXXXX) - docker cp $CONTAINERID:/app/CHECKS $TMPDIR 2> /dev/null || true - if [[ ! -s "${TMPDIR}/CHECKS" ]] ; then - echo " CHECKS file not found in container. skipping checks." - rm -rf $TMPDIR - exit 0 - else - echo " CHECKS file found in container" - FILENAME=${TMPDIR}/CHECKS + echo " check-deploy: $FILENAME not found. attempting to retrieve it from container ..." + TMPDIR=$(mktemp -d /tmp/CHECKS.XXXXX) + docker cp $CONTAINERID:/app/CHECKS $TMPDIR 2> /dev/null || true + if [[ ! -s "${TMPDIR}/CHECKS" ]] ; then + echo " CHECKS file not found in container. skipping checks." + rm -rf $TMPDIR + exit 0 + else + echo " CHECKS file found in container" + FILENAME=${TMPDIR}/CHECKS - function cleanup() { - echo " removing CHECKS file copied from container" - rm -rf $TMPDIR - } - trap cleanup EXIT - fi + function cleanup() { + echo " removing CHECKS file copied from container" + rm -rf $TMPDIR + } + trap cleanup EXIT + fi fi echo "Waiting $WAIT seconds ..." diff --git a/plugins/config/backup-export b/plugins/config/backup-export index 68b5c0393..bc709ce83 100755 --- a/plugins/config/backup-export +++ b/plugins/config/backup-export @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + shopt -s nullglob VERSION="$1" BASE_DIR="$2" diff --git a/plugins/config/backup-import b/plugins/config/backup-import index 9ed3b1eca..7652df515 100755 --- a/plugins/config/backup-import +++ b/plugins/config/backup-import @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + shopt -s nullglob VERSION="$1" IMPORT_DIR="$2" @@ -7,5 +8,5 @@ TARGET_DIR="$3" cd $IMPORT_DIR for file in */ENV; do - cp $file "$TARGET_DIR/$file" + cp $file "$TARGET_DIR/$file" done diff --git a/plugins/config/commands b/plugins/config/commands index 441e5fec5..724fb58c9 100755 --- a/plugins/config/commands +++ b/plugins/config/commands @@ -75,7 +75,6 @@ config_write() { } case "$1" in - config) APP="$2" @@ -186,4 +185,3 @@ EOF ;; esac - diff --git a/plugins/git/backup-import b/plugins/git/backup-import index 6d4a30a10..8d40fd316 100755 --- a/plugins/git/backup-import +++ b/plugins/git/backup-import @@ -1,18 +1,20 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + VERSION="$1" IMPORT_DIR="$2" TARGET_DIR="$3" APPS="$4" -while read APP; do - APP_PATH="$TARGET_DIR/$APP"; - git init --bare $APP_PATH > /dev/null - PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" - cat > $PRERECEIVE_HOOK < /dev/null + PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" + cat > $PRERECEIVE_HOOK < /dev/null diff --git a/plugins/git/commands b/plugins/git/commands index e42246fb4..0b90005e5 100755 --- a/plugins/git/commands +++ b/plugins/git/commands @@ -2,19 +2,19 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x git_archive_all() { - APP=$1; REV=$2 - TMP_WORK_DIR=$(mktemp -d) - chmod 755 $TMP_WORK_DIR - unset GIT_DIR GIT_WORK_TREE - git clone $DOKKU_ROOT/$APP $TMP_WORK_DIR &> /dev/null - pushd $TMP_WORK_DIR > /dev/null - git config advice.detachedHead false - git checkout $REV &> /dev/null - git submodule update --init --recursive &> /dev/null - find -name .git -prune -exec rm -rf {} \; > /dev/null - tar c . - popd > /dev/null - rm -rf $TMP_WORK_DIR > /dev/null + APP=$1; REV=$2 + TMP_WORK_DIR=$(mktemp -d) + chmod 755 $TMP_WORK_DIR + unset GIT_DIR GIT_WORK_TREE + git clone $DOKKU_ROOT/$APP $TMP_WORK_DIR &> /dev/null + pushd $TMP_WORK_DIR > /dev/null + git config advice.detachedHead false + git checkout $REV &> /dev/null + git submodule update --init --recursive &> /dev/null + find -name .git -prune -exec rm -rf {} \; > /dev/null + tar c . + popd > /dev/null + rm -rf $TMP_WORK_DIR > /dev/null } case "$1" in @@ -31,7 +31,6 @@ case "$1" in echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master." echo $'\e[1G\e[K'"-----> for example, try 'git push ${refname/refs\/heads\/}:master'" fi - done ;; @@ -40,14 +39,15 @@ case "$1" in APP_PATH=$DOKKU_ROOT/$APP if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then - git init --bare $APP_PATH > /dev/null - PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" - cat > $PRERECEIVE_HOOK < /dev/null + PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive" + cat > $PRERECEIVE_HOOK < /dev/null diff --git a/plugins/nginx-vhosts/post-deploy b/plugins/nginx-vhosts/post-deploy index 1e0b1e7fe..b0d06e8cb 100755 --- a/plugins/nginx-vhosts/post-deploy +++ b/plugins/nginx-vhosts/post-deploy @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + APP="$1"; PORT="$2" WILDCARD_SSL="$DOKKU_ROOT/tls" SSL="$DOKKU_ROOT/$APP/tls"