feat: initial docker installation support

Refs #1076
This commit is contained in:
Jose Diaz-Gonzalez
2019-05-13 03:05:50 -04:00
parent 6b42fde028
commit 3eb9c9b3ba
10 changed files with 172 additions and 0 deletions

60
Dockerfile Normal file
View File

@@ -0,0 +1,60 @@
FROM phusion/baseimage:0.11
CMD ["/sbin/my_init"]
RUN apt-get update && apt-get -y upgrade && apt-get -y install \
nano \
rsync \
software-properties-common \
sudo \
wget && \
apt-get purge -y syslog-ng-core && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ARG DOKKU_TAG=0.17.7
ARG DOKKU_GID=200
ARG DOKKU_UID=200
ARG DOKKU_DOCKERFILE=true
ARG DOKKU_WEB_CONFIG=false
ARG DOKKU_HOSTNAME=dokku.invalid
ARG DOKKU_VHOST_ENABLE=false
ARG DOKKU_SKIP_KEY_FILE=true
RUN addgroup --gid $DOKKU_GID dokku && \
adduser --uid $DOKKU_UID --gid $DOKKU_GID --disabled-password --gecos "" "dokku"
RUN export DOKKU_TAG=$DOKKU_TAG \
DOKKU_DOCKERFILE=$DOKKU_DOCKERFILE \
DOKKU_WEB_CONFIG=$DOKKU_WEB_CONFIG \
DOKKU_HOSTNAME=$DOKKU_HOSTNAME \
DOKKU_VHOST_ENABLE=$DOKKU_VHOST_ENABLE \
DOKKU_SKIP_KEY_FILE=$DOKKU_SKIP_KEY_FILE && \
wget https://raw.githubusercontent.com/dokku/dokku/v$DOKKU_TAG/bootstrap.sh && \
bash bootstrap.sh && \
apt-get clean && rm -rf bootstrap.sh /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /tmp
COPY ./docker .
RUN \
rsync -a /tmp/ / && \
rm -rf /tmp/* && \
rm /etc/runit/runsvdir/default/sshd/down && \
chown -R dokku:dokku /home/dokku/ && \
mkdir -p /skel/etc /skel/home /skel/var/lib/dokku /var/log/services && \
mv /etc/ssh /skel/etc/ssh && \
mv /home/dokku /skel/home/dokku && \
mv /var/lib/dokku/config /skel/var/lib/dokku/config && \
mv /var/lib/dokku/data /skel/var/lib/dokku/data && \
ln -sf /mount/etc/ssh /etc/ssh && \
ln -sf /mount/home/dokku /home/dokku && \
ln -sf /mount/var/lib/dokku/config /var/lib/dokku/config && \
ln -sf /mount/var/lib/dokku/data /var/lib/dokku/data && \
mv /etc/my_init.d/00_regen_ssh_host_keys.sh \
/etc/my_init.d/15_regen_ssh_host_keys && \
rm /etc/nginx/sites-enabled/default && \
rm /usr/share/nginx/html/index.html && \
rm /etc/my_init.d/10_syslog-ng.init && \
sed -i '/imklog/d' /etc/rsyslog.conf && \
rm /var/log/btmp /var/log/wtmp /var/log/*log /var/log/apt/* /var/log/dokku/* /var/log/nginx/*

View File

@@ -0,0 +1,4 @@
PATH=/usr/local/bin:/usr/bin:/bin
SHELL=/bin/bash
*/5 * * * * root /usr/bin/dokku ps:retire >> /var/log/dokku/retire.log 2>&1

View File

@@ -0,0 +1,9 @@
/var/log/services/* {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}

View File

@@ -0,0 +1,36 @@
#!/bin/bash
set -eo pipefail
log-info() {
declare desc="Log info formatter"
echo " $*" 1>&2
}
log-fail() {
declare desc="Log fail formatter"
echo "! $*" 1>&2
exit 1
}
main() {
if [[ ! -d /mount ]]; then
log-info "Creating missing /mount"
mkdir -p /mount
fi
directories=("/etc/ssh" "/home/dokku" "/var/lib/dokku/config" "/var/lib/dokku/data")
for dir in "${directories[@]}"; do
if [[ ! -e "$dir" ]]; then
log-info "Copying ${dir} skel into place"
mkdir -p "/mount${dir}"
rsync -a "/skel${dir}/" "${dir}/" || log-fail "Unable to copy ${dir} skel into place"
fi
# chown mount directories to "dokku:dokku"
if [[ "$dir" != "/etc/ssh" ]]; then
find "$dir" -print0 | xargs -0 chown -h dokku:dokku
fi
done
}
main "$@"

View File

@@ -0,0 +1,15 @@
#!/bin/bash
exec >> /var/log/services/dokku-restore
exec 2>&1
if [[ "$1" -ne 0 ]]; then
echo "Error initializing dokku! Retrying in 30 seconds..."
exec sleep 30
exit 0
fi
echo "Done initializing dokku."
exec sleep infinity
exit 0

View File

@@ -0,0 +1,14 @@
#!/bin/bash
exec >> /var/log/services/dokku-init
exec 2>&1
echo "Running dokku-init"
cd /tmp || exit 1
if [[ -n "$DOKKU_HOSTNAME" ]]; then
echo "dokku dokku/vhost_enable boolean true" | debconf-set-selections
dokku --quiet domains:set-global "$DOKKU_HOSTNAME"
fi
exec dokku ps:restore

View File

@@ -0,0 +1,7 @@
#!/bin/bash
exec >> /var/log/services/nginx
exec 2>&1
echo "Running nginx"
exec /usr/sbin/nginx -c /etc/nginx/nginx.conf -g "daemon off;"

View File

@@ -0,0 +1,7 @@
#!/bin/bash
exec >> /var/log/services/rsyslog
exec 2>&1
echo "Running rsyslog"
exec /usr/sbin/rsyslogd -n

View File

@@ -0,0 +1 @@
dokku ALL=NOPASSWD:SETENV:/usr/bin/docker

19
docker/usr/local/bin/docker Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $TRACE ]] && set -x
main() {
declare desc="re-runs docker commands as sudo"
local DOCKER_BIN=""
if [[ -x "/usr/bin/docker" ]]; then
DOCKER_BIN="/usr/bin/docker"
fi
if [[ -z "$DOCKER_BIN" ]]; then
echo "! No docker binary found" 1>&2
exit 1
fi
sudo -E "$DOCKER_BIN" "$@"
}
main "$@"