Skip to content

Instantly share code, notes, and snippets.

@lebalz
Last active November 24, 2023 14:27
Show Gist options
  • Save lebalz/0877cc16ead689a5c785e4bf6626f9ed to your computer and use it in GitHub Desktop.
Save lebalz/0877cc16ead689a5c785e4bf6626f9ed to your computer and use it in GitHub Desktop.

bash scripts which can be used to deploy dokku services

Dependencies

The Prometheus script needs a prometheus config, which is fetched by default from here

Install Grafana + Prometheus + node-exporter + c-advisor

Run the following on your dokku host where you want to serve grafana from:

# grafana
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/grafana.sh | bash -s -- -d dokku.org -e [email protected]
# prometheus
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/prometheus.sh | bash -s -- -u admin -p asdfasdf -d dokku.org -e [email protected]
# node-exporter
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/node-exporter.sh | bash -s -- -d dokku.org -e [email protected]
# c-advisor
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/c_advisor.sh | bash -s -- -u admin -p asdfasdf -d dokku.org -e [email protected]

On every other d host you like to monitor ressources, add c-advisor and node-exporter and adapt the your prometheus.yml accordingly (located under /var/lib/dokku/data/storage/prometheus/config/prometheus.yml). Make sure to reload prometheus configs by performing a POST request to prometheus.dokku.org/-/reload. This can be done by with this sh script: curl -s https://gist.githubusercontent.com/lebalz/67f1aaa8aeada40d738ae163533c7a71/raw/reload.sh | bash -s -- -u admin -p asdfasdf -d dokku.org

# node-exporter
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/node-exporter.sh | bash -s -- -d dokku.org -e [email protected]
# c-advisor
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/c_advisor.sh | bash -s -- -u admin -p asdfasdf -d dokku.org -e [email protected]

Dokku

Create new Dokku instance

After setting up a new vm, run the following commands as root (sudo su). Make sure to set the current DOKKU_TAG in the script below (see Dokku-Website).

apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get install build-essentials python -y

wget https://raw.githubusercontent.com/dokku/dokku/v0.19.5/bootstrap.sh
sudo DOKKU_TAG=v0.19.5 bash bootstrap.sh

dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
dokku plugin:install https://github.com/dokku/dokku-redis.git redis

# lazydocker

curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash

Dokku Client

Install a dokku client to easily manage dokku apps without the need to ssh to the server all the time.

Infos / Troubleshooting

Log to stdout to be reported by docker container (and dokku logs <app-name>)

Loggers must log to the standard output to be captured and shown as docker logs. Rails apps must therefore export the env variable RAILS_LOG_TO_STDOUT=true.

Upload files larger than 2MB

Increase the maximal upload size per app with

mkdir /home/dokku/<APP-NAME>/nginx.conf.d/
chown -R dokku:dokku /home/dokku/<APP-NAME>/nginx.conf.d/
echo 'client_max_body_size 50m;' > /home/dokku/<APP-NAME>/nginx.conf.d/upload.conf
chown dokku:dokku /home/dokku/<APP-NAME>/nginx.conf.d/upload.conf

Serve static assets with rails

To serve static assets (e.g. for react front-ends), set the rails env variable RAILS_SERVE_STATIC_FILES=true.

dokku: pgAdmin

initial setup

dokku apps:create pgadmin
docker pull dpage/pgadmin4
 
# set credentials for the contaier
# credentials can be set in /home/dokku/pgadmin/ENV too
dokku config:set pgadmin [email protected]
dokku config:set pgadmin PGADMIN_DEFAULT_PASSWORD="foobar"

# storage mount
mkdir -p /var/lib/dokku/data/storage/pgadmin/data

# pgadmin runs with uid 5050 inside the container - give it permissions...
chown -R 5050:5050 /var/lib/dokku/data/storage/pgadmin/data/
dokku storage:mount pgadmin /var/lib/dokku/data/storage/pgadmin/data:/var/lib/pgadmin
 
# tag the container to be known by dokku
docker tag dpage/pgadmin4:latest dokku/pgadmin:v4.14
dokku tags:deploy pgadmin v4.14
 
# show current stats of domain/port configuration
dokku domains:report pgadmin
dokku proxy:report pgadmin

# configure domain/port...
dokku domains:add pgadmin foo.dokku.bar.ch
dokku proxy:ports-add pgadmin http:80:80

upgrade docker image

e.g. update from v4.14 to v4.17

docker pull dpage/pgadmin4
docker tag dpage/pgadmin4:latest dokku/pgadmin:v4.17
dokku ps:stop pgadmin
dokku tags:deploy pgadmin v4.17
#!/usr/bin/env bash
# USAGE (from GIST):
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/c_advisor.sh | bash -s -- -u admin -p asdfasdf -d dokku.org -e [email protected]
usage="usage: c_advisor.ssh -u cAdvisor_username
-p cAdvisor_password
-d dokku-domain
-e mail for letsencrypt
[-v cAdvisor docker version]
[-n app name on dokku]
[-s skip letsencrypt]
[-h help]"
while getopts "u:p:d:e:v:n:h" option; do
case "${option}" in
h) echo "$usage"
exit 0
;;
u) USERNAME=${OPTARG};;
p) PASSWORD=${OPTARG};;
d) DOMAIN=${OPTARG};;
e) EMAIL=${OPTARG};;
v) VERSION=${OPTARG};;
n) APP_NAME=${OPTARG};;
s) SKIP_LETSENCRYPT=${OPTARG};;
esac
done
if [ -z "$VERSION" ]; then
VERSION="v0.35.0"
else
echo "VERSION=$VERSION"
fi
if [ -z "$APP_NAME" ]; then
APP_NAME="c-advisor"
else
echo "APP_NAME=$APP_NAME"
fi
if [ -z "$EMAIL" ]; then
EMAIL="[email protected]"
else
echo "EMAIL=$EMAIL"
fi
dokku apps:create ${APP_NAME}
docker image pull gcr.io/google-containers/cadvisor:$VERSION
docker image tag gcr.io/google-containers/cadvisor:$VERSION dokku/${APP_NAME}:$VERSION
dokku config:set ${APP_NAME} DOKKU_DOCKERFILE_START_CMD="--docker_only --housekeeping_interval=10s --max_housekeeping_interval=60s --disable_metrics=disk"
dokku storage:mount ${APP_NAME} /:/rootfs:ro
dokku storage:mount ${APP_NAME} /sys:/sys:ro
dokku storage:mount ${APP_NAME} /var/lib/docker:/var/lib/docker:ro
dokku storage:mount ${APP_NAME} /var/run:/var/run:rw
dokku tags:deploy ${APP_NAME} $VERSION
dokku domains:add ${APP_NAME} "${APP_NAME}.${DOMAIN}"
dokku proxy:ports-set ${APP_NAME} "http:80:8080"
if [ "$SKIP_LETSENCRYPT" ]; then
# install plugin letsencrypt for dokku if not present
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_letsencrypt.sh | bash
if [[ -z $(dokku letsencrypt:ls | grep ${APP_NAME}) ]]; then
dokku config:set --no-restart ${APP_NAME} DOKKU_LETSENCRYPT_EMAIL=${EMAIL}
dokku letsencrypt ${APP_NAME}
fi
fi
# install plugin http-auth for dokku if not present
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_http_auth.sh | bash
dokku http-auth:on ${APP_NAME} ${USERNAME} ${PASSWORD}
#!/usr/bin/env bash
set -e
# USAGE (from GIST):
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/db-sql-setup.sh | bash -s -- -k $(cat config/master.key)
usage="usage: db-sql.ssh -k rails_master_key
[-n app name on dokku (default: db-sql)]
[-h help]"
while getopts k:n:h option; do
case "${option}" in
k) RAILS_MASTER_KEY=${OPTARG};;
n) APP_NAME=${OPTARG};;
h) echo "$usage"
exit 0
;;
esac
done
if [ -z "$APP_NAME" ]; then
APP_NAME="db-sql"
else
echo "APP_NAME=$APP_NAME"
fi
if [[ $(ls /home/dokku/${APP_NAME}) ]]; then
echo "${APP_NAME} exists"
else
dokku apps:create ${APP_NAME}
dokku postgres:create ${APP_NAME}
dokku postgres:link ${APP_NAME} ${APP_NAME}
fi
# db connection url - since executed from within the postgres container, change host to localhost
DB_URL=$(dokku config:get ${APP_NAME} DATABASE_URL | sed 's/@.*:/@localhost:/')
# ensure postgres extension 'pgcrypto' is installed
dokku postgres:enter ${APP_NAME} psql ${DB_URL} -c 'CREATE EXTENSION IF NOT EXISTS "pgcrypto" SCHEMA public;'
# configure the rails app
dokku config:set ${APP_NAME} RAILS_MASTER_KEY="$RAILS_MASTER_KEY"
dokku config:set ${APP_NAME} RAILS_SERVE_STATIC_FILES="1" RAILS_ENV="production" NO_VHOST="0" DOKKU_DOCKERFILE_PORTS="3000"
dokku proxy:ports-set ${APP_NAME} "http:80:3000"
dokku docker-options:add ${APP_NAME} build "--build-arg RAILS_MASTER_KEY=$RAILS_MASTER_KEY"

Hints to setup new mysql edu db on dokku

dokku mysql:create edu-db
cat /var/lib/dokku/services/mysql/edu-db/ROOTPASSWORD

edit /var/lib/dokku/services/mysql/edu-db/my.cnf and fill in following content:

[mysqld]
default_password_lifetime=0
lower_case_table_names = 1
max_connections = 1000
max_connect_errors=50000
max_allowed_packet=128M
general_log = on
general_log_file=/var/log/mysql/query.log

edit root password

cd /var/lib/dokku/services/mysql/edu-db/
cat ROOTPASSWORD
mv ROOTPASSWORD ROOTPASSWORD.old
nano ROOTPASSWORD

then enter mysql (with the old root password) and modify the users:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '{ROOTPASSWORD}';
ALTER USER 'mysql'@'localhost' IDENTIFIED WITH mysql_native_password by '{ROOTPASSWORD}';
FLUSH PRIVILEGES;

expose

dokku mysql:expose edu-db 21

export dump

docker exec dokku.mysql.edu-db /usr/bin/mysqldump --all-databases -u root --password={ROOTPW} > edu-db.sql

import dump

cat edu-db.sql | docker exec -i dokku.mysql.edu-db /usr/bin/mysql -u root --password={ROOTPW}
#!/usr/bin/env bash
# USAGE (from GIST):
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/grafana.sh | bash -s -- -d dokku.org -e [email protected]
usage="usage: grafana.ssh -d dokku-domain
-e mail for letsencrypt
[-v grafana docker version]
[-n app name on dokku]
[-h help]"
while getopts "d:v:e:n:h" option; do
case "${option}" in
h) echo "$usage"
exit 0
;;
d) DOMAIN=${OPTARG};;
e) EMAIL=${OPTARG};;
v) VERSION=${OPTARG};;
n) APP_NAME=${OPTARG};;
esac
done
if [ -z "$VERSION" ]; then
VERSION="6.7.1"
else
echo "VERSION=$VERSION"
fi
if [ -z "$EMAIL" ]; then
EMAIL="[email protected]"
else
echo "EMAIL=$EMAIL"
fi
if [ -z "$APP_NAME" ]; then
APP_NAME="grafana"
else
echo "APP_NAME=$APP_NAME"
fi
dokku apps:create ${APP_NAME}
docker image pull grafana/grafana:${VERSION}
docker image tag grafana/grafana:${VERSION} dokku/${APP_NAME}:${VERSION}
dokku storage:mount ${APP_NAME} /var/lib/dokku/data/storage/grafana:/var/lib/grafana
sudo mkdir -p /var/lib/dokku/data/storage/${APP_NAME}
sudo chown 472:472 /var/lib/dokku/data/storage/${APP_NAME}
# deploy
dokku tags:deploy ${APP_NAME} ${VERSION}
dokku domains:add ${APP_NAME} "${APP_NAME}.${DOMAIN}"
dokku proxy:ports-set ${APP_NAME} "http:80:3000"
# install plugin letsencrypt for dokku if not present
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_letsencrypt.sh | bash
if [[ -z $(dokku letsencrypt:ls | grep ${APP_NAME}) ]]; then
dokku config:set --no-restart ${APP_NAME} DOKKU_LETSENCRYPT_EMAIL=${EMAIL}
dokku letsencrypt ${APP_NAME}
fi
#!/usr/bin/env bash
# checks if the install_http_auth plugin is installed
# - install unless not present
# - enable if disabled
# USAGE
# - on dokku host
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_http_auth.sh | bash
# - on local host
# ssh -T [email protected] 'curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_http_auth.sh | bash'
echo "# ---------------------------------------------------------------------------- #"
if [[ -z $(dokku plugin:list | egrep -oh "http-auth.+enabled") ]]; then
if [[ -z $(dokku plugin:list | egrep -oh "http-auth.+disabled") ]]; then
echo "# --------------------- Install dokku http-auth plugin ----------------------- #"
dokku plugin:install https://github.com/dokku/dokku-http-auth.git
else
echo "# --------------------- Enable dokku http-auth plugin ------------------------ #"
dokku plugin:enable http-auth
fi
else
echo "# ----------------------- http-auth already installed ------------------------ #"
fi
#!/usr/bin/env bash
# checks if the letsencrypt plugin is installed
# - install unless not present
# - enable if disabled
# USAGE
# - on dokku host
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_letsencrypt.sh | bash
# - on local host
# ssh -T [email protected] 'curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_letsencrypt.sh | bash'
echo "# ---------------------------------------------------------------------------- #"
if [[ -z $(dokku plugin:list | egrep -oh "letsencrypt.+enabled") ]]; then
if [[ -z $(dokku plugin:list | egrep -oh "letsencrypt.+disabled") ]]; then
echo "# ----------------------- Install dokku letsencrypt plugin ------------------- #"
dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
else
echo "# ----------------------- Enable dokku letsencrypt plugin -------------------- #"
dokku plugin:enable letsencrypt
fi
else
echo "# ----------------------- letsencrypt already installed ---------------------- #"
fi
#!/usr/bin/env bash
# checks if the mysql plugin is installed
# - install unless not present
# - enable if disabled
# USAGE
# - on dokku host
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_mysql.sh | bash
# - on local host
# ssh -T [email protected] 'curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_mysql.sh | bash'
echo "# ---------------------------------------------------------------------------- #"
if [[ -z $(dokku plugin:list | egrep -oh "mysql.+enabled") ]]; then
if [[ -z $(dokku plugin:list | egrep -oh "mysql.+disabled") ]]; then
echo "# ----------------------- Install dokku mysql plugin ---------------------- #"
dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql
else
echo "# ----------------------- Enable dokku mysql plugin ----------------------- #"
dokku plugin:enable mysql
fi
else
echo "# ----------------------- mysql already installed ------------------------- #"
fi
#!/usr/bin/env bash
# checks if the postgres plugin is installed
# - install unless not present
# - enable if disabled
# USAGE
# - on dokku host
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_postgres.sh | bash
# - on local host
# ssh -T [email protected] 'curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_postgres.sh | bash'
echo "# ---------------------------------------------------------------------------- #"
if [[ -z $(dokku plugin:list | egrep -oh "postgres.+enabled") ]]; then
if [[ -z $(dokku plugin:list | egrep -oh "postgres.+disabled") ]]; then
echo "# ----------------------- Install dokku postgres plugin ---------------------- #"
dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
else
echo "# ----------------------- Enable dokku postgres plugin ----------------------- #"
dokku plugin:enable postgres
fi
else
echo "# ----------------------- postgres already installed ------------------------- #"
fi

Ledokku

Installation

dokku apps:create ledokku
mkdir -p /var/lib/dokku/data/storage/ledokku/ssh

dokku storage:mount ledokku /var/lib/dokku/data/storage/ledokku/ssh/:/root/.ssh
chown dokku:dokku /var/lib/dokku/data/storage/ledokku/ssh

# if redis is not installed:
# dokku plugin:install https://github.com/dokku/dokku-redis.git redis
dokku redis:create ledokku
dokku redis:link ledokku ledokku

dokku postgres:create ledokku
dokku postgres:link ledokku ledokku

# create github tenant: https://github.com/settings/developers
dokku config:set ledokku GITHUB_CLIENT_ID="...."
dokku config:set ledokku GITHUB_CLIENT_SECRET="...."

# prepare config
dokku config:set ledokku DOKKU_SSH_HOST="the-real-server-ip, not host name!"
dokku config:set ledokku JWT_SECRET=$(openssl rand -hex 32)
dokku config:set ledokku TELEMETRY_DISABLED=1

dokku git:from-image ledokku ledokku/ledokku:0.5.1
dokku proxy:ports-add ledokku http:80:4000
dokku proxy:ports-remove ledokku http:4000:4000

# letsencrypt
dokku config:set --no-restart ledokku DOKKU_LETSENCRYPT_EMAIL="[email protected]"
dokku letsencrypt ledokku
#!/usr/bin/env bash
# USAGE (from GIST):
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/node-exporter.sh | bash -s -- -d dokku.org -e [email protected]
usage="usage: node-exporter.ssh -u node-exporter username
-p node-exporter password
[-d dokku-domain]
[-e mail for letsencrypt]
[-v node-exporter docker version]
[-n app name on dokku]
[-h help]"
while getopts "u:p:e:d:v:n:h" option; do
case "${option}" in
h) echo "$usage"
exit 0
;;
u) USERNAME=${OPTARG};;
p) PASSWORD=${OPTARG};;
d) DOMAIN=${OPTARG};;
e) EMAIL=${OPTARG};;
v) VERSION=${OPTARG};;
n) APP_NAME=${OPTARG};;
esac
done
if [ -z "$VERSION" ]; then
VERSION="v0.18.1"
else
echo "VERSION=$VERSION"
fi
if [ -z "$APP_NAME" ]; then
APP_NAME="node-exporter"
else
echo "APP_NAME=$APP_NAME"
fi
dokku apps:create ${APP_NAME}
docker image pull prom/node-exporter:${VERSION}
docker image tag prom/node-exporter:${VERSION} dokku/${APP_NAME}:${VERSION}
dokku config:set --no-restart ${APP_NAME} DOKKU_DOCKERFILE_START_CMD="--collector.textfile.directory=/data --path.procfs=/host/proc --path.sysfs=/host/sys"
sudo mkdir -p /var/lib/dokku/data/storage/${APP_NAME}
sudo chown nobody:nogroup /var/lib/dokku/data/storage/${APP_NAME}
dokku storage:mount ${APP_NAME} /proc:/host/proc:ro
dokku storage:mount ${APP_NAME} /:/rootfs:ro
dokku storage:mount ${APP_NAME} /sys:/host/sys:ro
dokku storage:mount ${APP_NAME} /var/lib/dokku/data/storage/${APP_NAME}:/data
dokku docker-options:add ${APP_NAME} deploy "--net=host"
# Because the container will operate on the host network, zero-downtime deploy checks must be unfortunately disabled,
# otherwise, you’d probably run into an issue where two containers are trying to bind to the same port.
# @see https://www.milanvit.net/post/getting-started-with-server-monitoring-and-alerting/
dokku checks:disable ${APP_NAME}
echo "now deploying"
dokku tags:deploy ${APP_NAME} ${VERSION}
if [ "$DOMAIN" ]; then
dokku domains:add ${APP_NAME} "${APP_NAME}.${DOMAIN}"
dokku proxy:ports-set ${APP_NAME} http:80:9100
fi
if [ "$EMAIL" ]; then
if [[ -z $(dokku letsencrypt:ls | grep ${APP_NAME}) ]]; then
dokku config:set --no-restart ${APP_NAME} DOKKU_LETSENCRYPT_EMAIL=${EMAIL}
dokku letsencrypt ${APP_NAME}
fi
fi
# install plugin http-auth for dokku if not present
url -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_http_auth.sh | bash
dokku http-auth:on ${APP_NAME} ${USERNAME} ${PASSWORD}
#!/usr/bin/env bash
# USAGE (from GIST):
# curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/prometheus.sh | bash -s -- -u admin -p asdfasdf -d dokku.org -e [email protected]
#
# Configure prometheus
# either provide a valid source of a prometheus.yml or edit a default version after this script execution
# under /var/lib/dokku/data/storage/${APP_NAME}/config/prometheus.yml
usage="usage: prometheus.ssh -u prometheus_username
-p prometheus_password
-d dokku-domain
-e mail for letsencrypt
[-c url to prmetheus_config.yml]
[-v prmetheus docker version]
[-n app name on dokku]
[-s skip letsencrypt]
[-h help]"
while getopts "u:p:d:e:c:v:n:l:h" option; do
case "${option}" in
h) echo "$usage"
exit 0
;;
u) USERNAME=${OPTARG};;
p) PASSWORD=${OPTARG};;
d) DOMAIN=${OPTARG};;
e) EMAIL=${OPTARG};;
c) PROMETHEUS_CONFIG=${OPTARG};;
v) VERSION=${OPTARG};;
n) APP_NAME=${OPTARG};;
s) SKIP_LETSENCRYPT=${OPTARG};;
esac
done
if [ -z "$VERSION" ]; then
VERSION="v2.17.1"
else
echo "VERSION=$VERSION"
fi
if [ -z "$APP_NAME" ]; then
APP_NAME="prometheus"
else
echo "APP_NAME=$APP_NAME"
fi
if [ -z "$EMAIL" ]; then
EMAIL="[email protected]"
else
echo "EMAIL=$EMAIL"
fi
if [ -z "$PROMETHEUS_CONFIG" ]; then
PROMETHEUS_CONFIG="https://gist.githubusercontent.com/lebalz/67f1aaa8aeada40d738ae163533c7a71/raw/prometheus_config.yml"
else
echo "PROMETHEUS_CONFIG=$PROMETHEUS_CONFIG"
fi
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_letsencrypt.sh | bash
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_http_auth.sh | bash
dokku apps:create ${APP_NAME}
docker pull prom/prometheus:${VERSION}
docker tag prom/prometheus:${VERSION} dokku/${APP_NAME}:${VERSION}
# enable to remotely reload prometheus configurations (without container restart)
dokku config:set --no-restart ${APP_NAME} DOKKU_DOCKERFILE_START_CMD="--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles --web.enable-lifecycle"
# mount persistent storage
sudo mkdir -p /var/lib/dokku/data/storage/${APP_NAME}/{config,data}
sudo touch /var/lib/dokku/data/storage/${APP_NAME}/config/{alert.rules,prometheus.yml}
curl -s ${PROMETHEUS_CONFIG} -o /var/lib/dokku/data/storage/${APP_NAME}/config/prometheus.yml
sudo chown -R nobody:nogroup /var/lib/dokku/data/storage/${APP_NAME}
dokku storage:mount ${APP_NAME} /var/lib/dokku/data/storage/${APP_NAME}/config:/etc/prometheus
dokku storage:mount ${APP_NAME} /var/lib/dokku/data/storage/${APP_NAME}/data:/prometheus
# deploy
dokku checks:disable ${APP_NAME}
dokku tags:deploy ${APP_NAME} ${VERSION}
dokku domains:add ${APP_NAME} "${APP_NAME}.${DOMAIN}"
dokku proxy:ports-set ${APP_NAME} "http:80:9090"
if [ "$SKIP_LETSENCRYPT" ]; then
if [[ -z $(dokku letsencrypt:ls | grep ${APP_NAME}) ]]; then
dokku config:set --no-restart ${APP_NAME} DOKKU_LETSENCRYPT_EMAIL=${EMAIL}
dokku letsencrypt ${APP_NAME}
fi
fi
# install plugin http-auth for dokku if not present
curl -s https://gist.githubusercontent.com/lebalz/0877cc16ead689a5c785e4bf6626f9ed/raw/install_http_auth.sh | bash
dokku http-auth:on ${APP_NAME} ${USERNAME} ${PASSWORD}
dokku apps:create umami
dokku postgres:create umami
dokku postgres:link umami umami
dokku config:set umami HASH_SALT=$(openssl rand -hex 32)
dokku config:set umami DATABASE_TYPE=postgresql
dokku proxy:ports-remove umami http:80:5000
dokku proxy:ports-add umami http:80:3000
dokku postgres:connect umami
# paste raw content from https://github.com/mikecao/umami/blob/master/sql/schema.postgresql.sql
dokku domains:add umami umami.lebalz.ch
dokku git:from-image umami ghcr.io/mikecao/umami:postgresql-latest
dokku config:set --no-restart umami DOKKU_LETSENCRYPT_EMAIL="[email protected]"
dokku letsencrypt:enable umami
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment