Compare commits

..

59 Commits

Author SHA1 Message Date
Jose Diaz-Gonzalez
1f187bf6ff Release 1.14.1 2021-09-12 04:51:13 -04:00
Jose Diaz-Gonzalez
fe950d727e dev: add convenience copy-file bin and fix data path used by plugin 2021-09-12 03:28:55 -04:00
Jose Diaz-Gonzalez
b576967efa dev: make devcontainer setup plugin agnostic 2021-09-12 02:39:17 -04:00
Jose Diaz-Gonzalez
b5cb24fc6c chore: show a better error message when the image is missing
Refs dokku/dokku-clickhouse#4
2021-09-12 00:54:23 -04:00
Jose Diaz-Gonzalez
aa1d1757a6 dev: mount the service directory from the host to ensure tests can pass inside of a docker container 2021-09-12 00:53:12 -04:00
Jose Diaz-Gonzalez
c11f1658e3 fix: copy any existing templates and drop unnecessary interactivity 2021-09-12 00:40:22 -04:00
Jose Diaz-Gonzalez
e2311100dd fix: use correct path 2021-09-11 23:45:01 -04:00
Jose Diaz-Gonzalez
f28a340403 fix: copy templates if they exist 2021-09-11 23:18:28 -04:00
Jose Diaz-Gonzalez
6dff5dc994 feat: add devcontainer support
This should make it possible to run tests locally in a lighter way than pulling up a full VM.
2021-09-11 21:06:06 -04:00
Jose Diaz-Gonzalez
7b6c259ff2 docs: regenerate readme 2021-09-11 18:16:51 -04:00
Jose Diaz-Gonzalez
b6394a8a33 Merge pull request #130 from dokku/dependabot/docker/mysql-8.0.26
chore(deps): bump mysql from 8.0.25 to 8.0.26
2021-09-11 18:10:43 -04:00
Jose Diaz-Gonzalez
dbb6dfdf0d chore: drop references to circleci, libera, travis-ci 2021-09-11 17:57:20 -04:00
dependabot[bot]
81b78bd7a0 chore(deps): bump mysql from 8.0.25 to 8.0.26
Bumps mysql from 8.0.25 to 8.0.26.

---
updated-dependencies:
- dependency-name: mysql
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-20 03:08:56 +00:00
Jose Diaz-Gonzalez
94c05b115b Release 1.14.0 2021-07-12 00:56:30 -04:00
Jose Diaz-Gonzalez
a7a900557e Merge pull request #129 from dokku/dependabot/docker/mysql-8.0.25
chore(deps): bump mysql from 5.7.28 to 8.0.25
2021-07-12 00:54:08 -04:00
dependabot[bot]
6b5356a646 chore(deps): bump mysql from 5.7.28 to 8.0.25
Bumps mysql from 5.7.28 to 8.0.25.

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-11 06:19:24 +00:00
Jose Diaz-Gonzalez
9b33948f94 tests: refactor tests to ignore readme generation for Dockerfile changes
Ideally we can trigger a readme update on merge in the future. For now, this will work well.
2021-04-26 11:43:13 -04:00
Jose Diaz-Gonzalez
bb7a6cc03d chore: gitignore bootstrap file and minor cleanup of ci 2021-04-25 02:54:07 -04:00
Jose Diaz-Gonzalez
2c5d67b094 Merge pull request #128 from dokku/github-actions-attempt
tests: migrate to github actions
2021-04-25 01:04:41 -04:00
Jose Diaz-Gonzalez
0dc36897ec tests: skip tests that require tty for github actions 2021-04-25 00:35:42 -04:00
Jose Diaz-Gonzalez
902b72b041 docs: regenerate readme 2021-04-24 14:09:33 -04:00
Jose Diaz-Gonzalez
c18413786f tests: drop copying of test results
Bats will now output the results on stdout so no need to copy results anywhere.
2021-04-24 14:05:47 -04:00
Jose Diaz-Gonzalez
2a171663ab tests: fix job name 2021-04-24 14:04:39 -04:00
Jose Diaz-Gonzalez
843f9748d5 tests: split tests to version and tag 2021-04-24 14:03:01 -04:00
Jose Diaz-Gonzalez
d932f241b0 chore: update min dokku version and only test push on master branch 2021-04-24 13:57:18 -04:00
Jose Diaz-Gonzalez
5c484f96f2 tests: migrate to github actions 2021-04-24 02:20:30 -04:00
Jose Diaz-Gonzalez
ee7c7b80c2 Release 1.13.0 2021-04-24 00:32:09 -04:00
Jose Diaz-Gonzalez
6e8e37fed1 feat: add dependabot config to all repositories 2021-04-24 00:10:33 -04:00
Jose Diaz-Gonzalez
ca0d288282 Merge pull request #126 from dokku/dockerfile-update
Pull image from Dockerfile
2021-04-23 23:55:40 -04:00
Jose Diaz-Gonzalez
2d8a614c89 tests: refactor source again 2021-02-26 00:45:09 -05:00
Jose Diaz-Gonzalez
049718f845 tests: fix path to Dockerfile when sourcing config for tests 2021-02-26 00:27:52 -05:00
Jose Diaz-Gonzalez
5c770e2922 docs: handle image and version correctly 2021-02-26 00:11:16 -05:00
Jose Diaz-Gonzalez
2b07ead40b refactor: move base image reference to Dockerfile
This will allow us to take advantage of automatic update software to auto-pull new versions when they are released to docker hub.
2021-02-25 23:16:23 -05:00
Jose Diaz-Gonzalez
8365999a3f tests: use dash instead of underscore 2021-02-25 20:32:57 -05:00
Jose Diaz-Gonzalez
a309b0d1fe feat: add plugin trigger for service creation and deletion 2021-02-25 19:54:59 -05:00
Jose Diaz-Gonzalez
b609bcdf31 refactor: use pre/post triggers for service-action naming
This is a bit more clear as the links aren't always idempotent and may have errors - this allows users to reconcile at what point a link may have failed so that they can take further action.
2021-02-25 16:05:24 -05:00
Jose Diaz-Gonzalez
4504fb956f feat: add service-action plugin trigger for link/unlink
This can be used to track in alternate systems when a service is linked/unlinked from an app by implementing the custom trigger.
2021-02-25 15:58:31 -05:00
Jose Diaz-Gonzalez
74af0482bf Release 1.12.1 2021-01-17 21:16:14 -05:00
Jose Diaz-Gonzalez
9d318cf26b fix: do not shadow TMPDIR variable
This enables usage of the plugin with libpam-tmpdir.

Refs dokku/dokku#3149
2021-01-17 21:02:28 -05:00
Jose Diaz-Gonzalez
a81da2b3ae Release 1.12.0 2020-09-30 12:49:29 -04:00
Jose Diaz-Gonzalez
b6aec377bc Merge pull request #97 from fruitl00p/patch-1
Faster exporting for innodb tables
2020-09-30 12:49:03 -04:00
Jose Diaz-Gonzalez
d9d44eea45 fix: correct image link 2020-09-27 12:38:50 -04:00
Robin Speekenbrink
c2e58c773e Faster exporting for innodb tables
Since InnoDB is the standard, i'd like to add the option `--single-transaction --quick` to the mysqldump command. This should speed up larger database exports without tearing the environment up whilst doing so... 
(see https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction)

Another way would be to allow for custom config to be loaded which inludes a optional `[mysqldump]` section... 

Another (even better perhaps) solution would be to have non-s3-backup command that utilizes the i.e. percona xtrabackup as the backup mechanism (and restore) but that changes from simple SQL backups to more advanced full database stuff...
2020-09-25 10:20:32 +02:00
Jose Diaz-Gonzalez
296607be93 Merge pull request #117 from dokku/configurable-config
fix: allow config directory to be configurable
2020-05-16 04:52:46 -04:00
Jose Diaz-Gonzalez
49c00a0479 fix: allow config directory to be configurable
For postgres, the config directory doesn't actually exist, so adding this configurability allows the plugin's info command to report correctly.
2020-05-16 02:49:34 -04:00
Jose Diaz-Gonzalez
2405b7ef22 Release 1.11.5 2020-05-15 00:58:46 -04:00
Jose Diaz-Gonzalez
c1e8c4d774 fix: respect the TMPDIR environment variable
Refs dokku/dokku-redis#143
2020-05-15 00:57:21 -04:00
Jose Diaz-Gonzalez
e849268847 Release 1.11.4 2020-05-15 00:53:27 -04:00
Jose Diaz-Gonzalez
9540977fe9 docs: correct help output
Refs dokku/dokku-postgres#197
2020-05-15 00:40:24 -04:00
Jose Diaz-Gonzalez
83fa90a012 docs: correct casing/quoting on sentences 2020-05-15 00:34:37 -04:00
Jose Diaz-Gonzalez
c26e54bc11 chore: run black 2020-05-14 23:57:49 -04:00
Jose Diaz-Gonzalez
3a483f1351 docs: document all flags in readme 2020-05-14 23:37:57 -04:00
Jose Diaz-Gonzalez
7e8008e019 docs: make the gpg passphrase a bit more clear 2020-05-14 23:33:01 -04:00
Jose Diaz-Gonzalez
f11f34287a Release 1.11.3 2020-05-14 22:59:43 -04:00
Jose Diaz-Gonzalez
5e41d13684 chore: update copyright date 2020-05-14 22:57:38 -04:00
Jose Diaz-Gonzalez
f2197fd2a5 docs: switch build shield to circleci 2020-04-05 20:41:00 -04:00
Jose Diaz-Gonzalez
2d6ef274e0 tests: use circleci 2.1 2020-04-05 20:40:20 -04:00
Jose Diaz-Gonzalez
6342be800d Release 1.11.2 2020-04-04 22:27:46 -04:00
Jose Diaz-Gonzalez
37baaaf0b1 fix: store the correct path 2020-04-04 22:25:11 -04:00
29 changed files with 573 additions and 279 deletions

View File

@@ -1,68 +0,0 @@
version: 2
jobs:
build-master:
environment:
DOKKU_VERSION: master
machine:
docker_layer_caching: false
image: ubuntu-1604:201903-01
steps:
- checkout
- run: pyenv global 3.7.0
- run: make setup
- run: sudo sysctl -w vm.max_map_count=262144
- run:
command: |
make generate;
if [[ $(git diff) ]]; then
echo "Please run `make generate`";
git status --short;
git diff;
exit 1;
fi
- run: make test
- store_artifacts:
path: build
destination: build
- store_artifacts:
path: tmp/test-results
destination: test-results
- store_test_results:
path: test-results
build-version:
environment:
DOKKU_VERSION: v0.19.0
machine:
docker_layer_caching: false
image: ubuntu-1604:201903-01
steps:
- checkout
- run: pyenv global 3.7.0
- run: make setup
- run: sudo sysctl -w vm.max_map_count=262144
- run:
command: |
make generate;
if [[ $(git diff) ]]; then
echo "Please run `make generate`";
git status --short;
git diff;
exit 1;
fi
- run: make test
- store_artifacts:
path: build
destination: build
- store_artifacts:
path: tmp/test-results
destination: test-results
- store_test_results:
path: test-results
workflows:
version: 2
build:
jobs:
- "build-master"
- "build-version"

24
.devcontainer/20_init_plugin Executable file
View File

@@ -0,0 +1,24 @@
#!/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() {
dokku plugin:install
# built in the Dockerfile
PLUGIN_NAME="$(source /tmp/.env && echo "$PLUGIN_NAME")"
PLUGIN_VARIABLE="$(source /tmp/.env && echo "$PLUGIN_VARIABLE")"
echo "export ${PLUGIN_VARIABLE}_HOST_ROOT=${SERVICE_HOST_ROOT}/$PLUGIN_NAME" > /etc/default/dokku
}
main "$@"

26
.devcontainer/Dockerfile Normal file
View File

@@ -0,0 +1,26 @@
FROM dokku/dokku:latest
RUN apt-get update
RUN apt-get install --no-install-recommends -y build-essential && \
apt-get clean autoclean && \
apt-get autoremove --yes && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /mnt/dokku/home/dokku /mnt/dokku/var/lib/dokku/config /mnt/dokku/var/lib/dokku/data /mnt/dokku/var/lib/dokku/services && \
chown -R dokku:dokku /mnt/dokku/home/dokku /mnt/dokku/var/lib/dokku/config /mnt/dokku/var/lib/dokku/data /mnt/dokku/var/lib/dokku/services && \
echo "dokku.me" > /home/dokku/VHOST
ADD https://raw.githubusercontent.com/dokku/dokku/master/tests/dhparam.pem /mnt/dokku/etc/nginx/dhparam.pem
COPY .devcontainer/20_init_plugin /etc/my_init.d/20_init_plugin
COPY .devcontainer/bin/ /usr/local/bin/
COPY . .
RUN source /tmp/config && \
echo "export ${PLUGIN_DISABLE_PULL_VARIABLE}=true" > /tmp/.env && \
echo "export PLUGIN_NAME=${PLUGIN_COMMAND_PREFIX}" >> /tmp/.env && \
echo "export PLUGIN_VARIABLE=${PLUGIN_VARIABLE}" >> /tmp/.env
RUN source /tmp/.env && \
dokku plugin:install file:///tmp --name $PLUGIN_NAME && \
make ci-dependencies

8
.devcontainer/bin/copy-file Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
main() {
PLUGIN_NAME="$(source /tmp/.env && echo "$PLUGIN_NAME")"
cp "$1" "/var/lib/dokku/plugins/enabled/$PLUGIN_NAME/$1"
}
main "$@"

View File

@@ -0,0 +1,16 @@
{
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"containerEnv": {
"SERVICE_HOST_ROOT": "${localWorkspaceFolder}/tmp/data"
},
"initializeCommand": ["mkdir", "-p", "tmp/data"],
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
"source=${localWorkspaceFolder}/tmp/data/,target=/var/lib/dokku/services/,type=bind"
],
"overrideCommand": false,
"runArgs": ["--init"]
}

6
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"

100
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,100 @@
---
name: CI
# yamllint disable-line rule:truthy
on:
pull_request:
branches:
- '*'
push:
branches:
- master
jobs:
unit-tests-master:
name: unit-tests
runs-on: ubuntu-18.04
strategy:
fail-fast: true
env:
DOKKU_VERSION: master
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: '3.7.x'
- run: make setup
- run: sudo sysctl -w vm.max_map_count=262144
- run: |
git fetch -q origin master
changed=$(git --no-pager diff --name-only $GITHUB_SHA..origin/master)
if [ $changed = "Dockerfile" ]; then
echo "Please run 'make generate' to update the image version in the README.md"
else
make generate
if ! git diff --quiet README.md; then
echo "Please run 'make generate'"
git status --short
git --no-pager diff README.md
exit 1
fi
fi
- run: make test
- uses: actions/upload-artifact@v2
if: failure()
with:
name: tmp/test-results
path: test-results
unit-tests-0_19_0:
name: unit-tests-0.19.0
runs-on: ubuntu-18.04
strategy:
fail-fast: true
env:
DOKKU_TAG: v0.19.0
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: '3.7.x'
- run: make setup
- run: sudo sysctl -w vm.max_map_count=262144
- run: |
git fetch -q origin master
changed=$(git --no-pager diff --name-only $GITHUB_SHA..origin/master)
if [ $changed = "Dockerfile" ]; then
echo "Please run 'make generate' to update the image version in the README.md"
else
make generate
if ! git diff --quiet README.md; then
echo "Please run 'make generate'"
git status --short
git --no-pager diff README.md
exit 1
fi
fi
- run: make test
- uses: actions/upload-artifact@v2
if: failure()
with:
name: tmp/test-results
path: test-results

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/tmp /tmp
.vagrant .vagrant
bootstrap.sh

1
Dockerfile Normal file
View File

@@ -0,0 +1 @@
FROM mysql:8.0.26

View File

@@ -1,4 +1,4 @@
Copyright (C) 2018 Jose Diaz-Gonzalez Copyright (C) 2020 Jose Diaz-Gonzalez
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@@ -11,7 +11,7 @@ ifneq ($(shell bats --version >/dev/null 2>&1 ; echo $$?),0)
brew install bats-core brew install bats-core
endif endif
else else
git clone https://github.com/josegonzalez/bats-core.git /tmp/bats git clone https://github.com/bats-core/bats-core.git /tmp/bats
cd /tmp/bats && sudo ./install.sh /usr/local cd /tmp/bats && sudo ./install.sh /usr/local
rm -rf /tmp/bats rm -rf /tmp/bats
endif endif
@@ -63,7 +63,7 @@ unit-tests:
@echo running unit tests... @echo running unit tests...
@mkdir -p tmp/test-results/bats @mkdir -p tmp/test-results/bats
@cd tests && echo "executing tests: $(shell cd tests ; ls *.bats | xargs)" @cd tests && echo "executing tests: $(shell cd tests ; ls *.bats | xargs)"
cd tests && bats --formatter bats-format-junit -e -T -o ../tmp/test-results/bats *.bats cd tests && bats --report-formatter junit --timing -o ../tmp/test-results/bats *.bats
tmp/xunit-reader: tmp/xunit-reader:
mkdir -p tmp mkdir -p tmp
@@ -71,28 +71,15 @@ tmp/xunit-reader:
tar xf tmp/xunit-reader.tgz -C tmp tar xf tmp/xunit-reader.tgz -C tmp
chmod +x tmp/xunit-reader chmod +x tmp/xunit-reader
tmp/xunit-to-github:
mkdir -p tmp
curl -o tmp/xunit-to-github.tgz -sL https://github.com/josegonzalez/go-xunit-to-github/releases/download/v$(XUNIT_TO_GITHUB_VERSION)/xunit-to-github_$(XUNIT_TO_GITHUB_VERSION)_$(SYSTEM_NAME)_$(HARDWARE).tgz
tar xf tmp/xunit-to-github.tgz -C tmp
chmod +x tmp/xunit-to-github
setup: setup:
bash tests/setup.sh bash tests/setup.sh
$(MAKE) ci-dependencies $(MAKE) ci-dependencies
test: lint unit-tests test: lint unit-tests
report: tmp/xunit-reader tmp/xunit-to-github report: tmp/xunit-reader
tmp/xunit-reader -p 'tmp/test-results/bats/*.xml' tmp/xunit-reader -p 'tmp/test-results/bats/*.xml'
tmp/xunit-reader -p 'tmp/test-results/shellcheck/*.xml' tmp/xunit-reader -p 'tmp/test-results/shellcheck/*.xml'
ifdef TRAVIS_REPO_SLUG
ifdef GITHUB_ACCESS_TOKEN
ifneq ($(TRAVIS_PULL_REQUEST),false)
tmp/xunit-to-github --skip-ok --job-url "$(TRAVIS_JOB_WEB_URL)" --pull-request-id "$(TRAVIS_PULL_REQUEST)" --repository-slug "$(TRAVIS_REPO_SLUG)" --title "DOKKU_VERSION=$(DOKKU_VERSION)" tmp/test-results/bats tmp/test-results/shellcheck
endif
endif
endif
.PHONY: clean .PHONY: clean
clean: clean:

View File

@@ -1,16 +1,16 @@
# dokku mysql [![Build Status](https://img.shields.io/travis/dokku/dokku-mysql.svg?branch=master "Build Status")](https://travis-ci.org/dokku/dokku-mysql) [![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg "IRC Freenode")](https://webchat.freenode.net/?channels=dokku) # dokku mysql [![Build Status](https://img.shields.io/github/workflow/status/dokku/dokku-mysql/CI/master?style=flat-square "Build Status")](https://github.com/dokku/dokku-mysql/actions/workflows/ci.yml?query=branch%3Amaster) [![IRC Network](https://img.shields.io/badge/irc-libera-blue.svg?style=flat-square "IRC Libera")](https://webchat.libera.chat/?channels=dokku)
Official mysql plugin for dokku. Currently defaults to installing [mysql 5.7.28](https://hub.docker.com/_/mysql/). Official mysql plugin for dokku. Currently defaults to installing [mysql 8.0.26](https://hub.docker.com/_/mysql/).
## Requirements ## Requirements
- dokku 0.12.x+ - dokku 0.19.x+
- docker 1.8.x - docker 1.8.x
## Installation ## Installation
```shell ```shell
# on 0.12.x+ # on 0.19.x+
sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql
``` ```
@@ -63,16 +63,24 @@ Help for any commands can be displayed by specifying the command as an argument
dokku mysql:create <service> [--create-flags...] dokku mysql:create <service> [--create-flags...]
``` ```
flags:
- `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with
- `-i|--image IMAGE`: the image name to start the service with
- `-I|--image-version IMAGE_VERSION`: the image version to start the service with
- `-p|--password PASSWORD`: override the user-level service password
- `-r|--root-password PASSWORD`: override the root-level service password
Create a mysql service named lolipop: Create a mysql service named lolipop:
```shell ```shell
dokku mysql:create lolipop dokku mysql:create lolipop
``` ```
You can also specify the image and image version to use for the service. It *must* be compatible with the ${plugin_image} image. You can also specify the image and image version to use for the service. It *must* be compatible with the mysql image.
```shell ```shell
export DATABASE_IMAGE="${PLUGIN_IMAGE}" export DATABASE_IMAGE="mysql"
export DATABASE_IMAGE_VERSION="${PLUGIN_IMAGE_VERSION}" export DATABASE_IMAGE_VERSION="${PLUGIN_IMAGE_VERSION}"
dokku mysql:create lolipop dokku mysql:create lolipop
``` ```
@@ -91,6 +99,19 @@ dokku mysql:create lolipop
dokku mysql:info <service> [--single-info-flag] dokku mysql:info <service> [--single-info-flag]
``` ```
flags:
- `--config-dir`: show the service configuration directory
- `--data-dir`: show the service data directory
- `--dsn`: show the service DSN
- `--exposed-ports`: show service exposed ports
- `--id`: show the service container id
- `--internal-ip`: show the service internal ip
- `--links`: show the service app links
- `--service-root`: show the service root directory
- `--status`: show the service running status
- `--version`: show the service image version
Get connection information as follows: Get connection information as follows:
```shell ```shell
@@ -132,6 +153,10 @@ dokku mysql:list
dokku mysql:logs <service> [-t|--tail] dokku mysql:logs <service> [-t|--tail]
``` ```
flags:
- `-t|--tail`: do not stop when end of the logs are reached and wait for additional output
You can tail logs for a particular service: You can tail logs for a particular service:
```shell ```shell
@@ -151,6 +176,11 @@ dokku mysql:logs lolipop --tail
dokku mysql:link <service> <app> [--link-flags...] dokku mysql:link <service> <app> [--link-flags...]
``` ```
flags:
- `-a|--alias "BLUE_DATABASE"`: an alternative alias to use for linking to an app via environment variable
- `-q|--querystring "pool=5"`: ampersand delimited querystring arguments to append to the service link
A mysql service can be linked to a container. This will use native docker links via the docker-options plugin. Here we link it to our 'playground' app. A mysql service can be linked to a container. This will use native docker links via the docker-options plugin. Here we link it to our 'playground' app.
> NOTE: this will restart your app > NOTE: this will restart your app
@@ -182,14 +212,14 @@ The host exposed here only works internally in docker containers. If you want yo
dokku mysql:link other_service playground dokku mysql:link other_service playground
``` ```
It is possible to change the protocol for database_url by setting the environment variable database_database_scheme on the app. Doing so will after linking will cause the plugin to think the service is not linked, and we advise you to unlink before proceeding. It is possible to change the protocol for `DATABASE_URL` by setting the environment variable `MYSQL_DATABASE_SCHEME` on the app. Doing so will after linking will cause the plugin to think the service is not linked, and we advise you to unlink before proceeding.
```shell ```shell
dokku config:set playground DATABASE_DATABASE_SCHEME=mysql2 dokku config:set playground MYSQL_DATABASE_SCHEME=mysql2
dokku mysql:link lolipop playground dokku mysql:link lolipop playground
``` ```
This will cause database_url to be set as: This will cause `DATABASE_URL` to be set as:
``` ```
mysql2://lolipop:SOME_PASSWORD@dokku-mysql-lolipop:3306/lolipop mysql2://lolipop:SOME_PASSWORD@dokku-mysql-lolipop:3306/lolipop
@@ -253,10 +283,10 @@ dokku mysql:enter lolipop touch /tmp/test
dokku mysql:expose <service> <ports...> dokku mysql:expose <service> <ports...>
``` ```
Expose the service on the service's normal ports, allowing access to it from the public interface (0. 0. 0. 0): Expose the service on the service's normal ports, allowing access to it from the public interface (`0.0.0.0`):
```shell ```shell
dokku mysql:expose lolipop ${PLUGIN_DATASTORE_PORTS[@]} dokku mysql:expose lolipop 3306
``` ```
### unexpose a previously exposed mysql service ### unexpose a previously exposed mysql service
@@ -266,7 +296,7 @@ dokku mysql:expose lolipop ${PLUGIN_DATASTORE_PORTS[@]}
dokku mysql:unexpose <service> dokku mysql:unexpose <service>
``` ```
Unexpose the service, removing access to it from the public interface (0. 0. 0. 0): Unexpose the service, removing access to it from the public interface (`0.0.0.0`):
```shell ```shell
dokku mysql:unexpose lolipop dokku mysql:unexpose lolipop
@@ -293,7 +323,7 @@ You can promote the new service to be the primary one:
dokku mysql:promote other_service playground dokku mysql:promote other_service playground
``` ```
This will replace database_url with the url from other_service and generate another environment variable to hold the previous value if necessary. You could end up with the following for example: This will replace `DATABASE_URL` with the url from other_service and generate another environment variable to hold the previous value if necessary. You could end up with the following for example:
``` ```
DATABASE_URL=mysql://other_service:ANOTHER_PASSWORD@dokku-mysql-other-service:3306/other_service DATABASE_URL=mysql://other_service:ANOTHER_PASSWORD@dokku-mysql-other-service:3306/other_service
@@ -347,6 +377,13 @@ dokku mysql:restart lolipop
dokku mysql:upgrade <service> [--upgrade-flags...] dokku mysql:upgrade <service> [--upgrade-flags...]
``` ```
flags:
- `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with
- `-i|--image IMAGE`: the image name to start the service with
- `-I|--image-version IMAGE_VERSION`: the image version to start the service with
- `-R|--restart-apps "true"`: whether to force an app restart
You can upgrade an existing service to a new image or image-version: You can upgrade an existing service to a new image or image-version:
```shell ```shell
@@ -377,6 +414,14 @@ dokku mysql:app-links playground
dokku mysql:clone <service> <new-service> [--clone-flags...] dokku mysql:clone <service> <new-service> [--clone-flags...]
``` ```
flags:
- `-C|--custom-env "USER=alpha;HOST=beta"`: semi-colon delimited environment variables to start the service with
- `-i|--image IMAGE`: the image name to start the service with
- `-I|--image-version IMAGE_VERSION`: the image version to start the service with
- `-p|--password PASSWORD`: override the user-level service password
- `-r|--root-password PASSWORD`: override the root-level service password
You can clone an existing service to a new one: You can clone an existing service to a new one:
```shell ```shell
@@ -517,7 +562,11 @@ dokku mysql:backup-deauth lolipop
dokku mysql:backup <service> <bucket-name> [--use-iam] dokku mysql:backup <service> <bucket-name> [--use-iam]
``` ```
Backup the 'lolipop' service to the 'my-s3-bucket' bucket on aws: flags:
- `-u|--use-iam`: use the IAM profile associated with the current server
Backup the 'lolipop' service to the 'my-s3-bucket' bucket on ``AWS`:`
```shell ```shell
dokku mysql:backup lolipop my-s3-bucket --use-iam dokku mysql:backup lolipop my-s3-bucket --use-iam
@@ -530,7 +579,7 @@ dokku mysql:backup lolipop my-s3-bucket --use-iam
dokku mysql:backup-set-encryption <service> <passphrase> dokku mysql:backup-set-encryption <service> <passphrase>
``` ```
Set a gpg passphrase for backups: Set the GPG-compatible passphrase for encrypting backups for backups:
```shell ```shell
dokku mysql:backup-set-encryption lolipop dokku mysql:backup-set-encryption lolipop
@@ -543,7 +592,7 @@ dokku mysql:backup-set-encryption lolipop
dokku mysql:backup-unset-encryption <service> dokku mysql:backup-unset-encryption <service>
``` ```
Unset a gpg encryption key for backups: Unset the `GPG` encryption passphrase for backups:
```shell ```shell
dokku mysql:backup-unset-encryption lolipop dokku mysql:backup-unset-encryption lolipop
@@ -556,6 +605,10 @@ dokku mysql:backup-unset-encryption lolipop
dokku mysql:backup-schedule <service> <schedule> <bucket-name> [--use-iam] dokku mysql:backup-schedule <service> <schedule> <bucket-name> [--use-iam]
``` ```
flags:
- `-u|--use-iam`: use the IAM profile associated with the current server
Schedule a backup: Schedule a backup:
> 'schedule' is a crontab expression, eg. "0 3 * * *" for each day at 3am > 'schedule' is a crontab expression, eg. "0 3 * * *" for each day at 3am

View File

@@ -5,50 +5,84 @@ import os
import re import re
def compile(service, version, alias, scheme, ports, unimplemented, dokku_version): def compile(service, version, variable, alias, image, scheme, ports, sponsors, unimplemented, dokku_version):
return "\n\n".join([ prefix = "\n\n".join([
header(service), header(service),
description(service, version), description(service, image, version),
])
if len(sponsors) > 0:
prefix += "\n\n"
prefix += sponsors_section(service, sponsors)
return (
"\n\n".join(
[
prefix,
requirements_section(dokku_version), requirements_section(dokku_version),
installation_section(service, dokku_version), installation_section(service, dokku_version),
commands_section(service, alias, scheme, ports, unimplemented), commands_section(service, variable, alias, image, scheme, ports, unimplemented),
usage_section(service, alias, scheme, ports, unimplemented), usage_section(service, variable, alias, image, scheme, ports, unimplemented),
]).replace("\n\n\n\n\n", "\n").replace("\n\n\n\n", "\n").replace("\n\n\n", "\n\n") ]
)
.replace("\n\n\n\n\n", "\n")
.replace("\n\n\n\n", "\n")
.replace("\n\n\n", "\n\n")
)
def header(service): def header(service):
return " ".join([ return " ".join(
[
f"# dokku {service}", f"# dokku {service}",
f"[![Build Status](https://img.shields.io/travis/dokku/dokku-{service}.svg?branch=master \"Build Status\")](https://travis-ci.org/dokku/dokku-{service})", f'[![Build Status](https://img.shields.io/github/workflow/status/dokku/dokku-{service}/CI/master?style=flat-square "Build Status")](https://github.com/dokku/dokku-{service}/actions/workflows/ci.yml?query=branch%3Amaster)',
f"[![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg \"IRC Freenode\")](https://webchat.freenode.net/?channels=dokku)", f'[![IRC Network](https://img.shields.io/badge/irc-libera-blue.svg?style=flat-square "IRC Libera")](https://webchat.libera.chat/?channels=dokku)',
]) ]
)
def description(service, version): def description(service, full_image, version):
return f"Official {service} plugin for dokku. Currently defaults to installing [{service} {version}](https://hub.docker.com/_/{service}/)." base = "_"
image = full_image
if "/" in full_image:
base = "r/" + full_image.split("/")[0]
image = full_image.split("/")[1]
return f"Official {service} plugin for dokku. Currently defaults to installing [{full_image} {version}](https://hub.docker.com/{base}/{image}/)."
def sponsors_section(service, sponsors):
if len(sponsors) == 0:
return ""
sponsor_data = ["## Sponsors", "", f"The {service} plugin was generously sponsored by the following:", ""]
sponsor_data.extend([f"- [{s}](https://github.com/{s})" for s in sponsors])
return "\n".join(
sponsor_data
)
def requirements_section(dokku_version): def requirements_section(dokku_version):
return "\n".join([ return "\n".join(
"## Requirements", ["## Requirements", "", f"- dokku {dokku_version}", "- docker 1.8.x",]
"", )
f"- dokku {dokku_version}",
"- docker 1.8.x",
])
def installation_section(service, dokku_version): def installation_section(service, dokku_version):
return "\n".join([ return "\n".join(
[
"## Installation", "## Installation",
"", "",
"```shell", "```shell",
f"# on {dokku_version}", f"# on {dokku_version}",
f"sudo dokku plugin:install https://github.com/dokku/dokku-{service}.git {service}", f"sudo dokku plugin:install https://github.com/dokku/dokku-{service}.git {service}",
"```", "```",
]) ]
)
def commands_section(service, alias, scheme, ports, unimplemented): def commands_section(service, variable, alias, image, scheme, ports, unimplemented):
content = [ content = [
"## Commands", "## Commands",
"", "",
@@ -63,7 +97,7 @@ def commands_section(service, alias, scheme, ports, unimplemented):
for filename in subcommands: for filename in subcommands:
if filename in unimplemented: if filename in unimplemented:
continue continue
data = command_data(filename, service, alias, scheme, ports) data = command_data(filename, service, variable, alias, image, scheme, ports)
description = data["description"] description = data["description"]
arguments = data["arguments_string"] arguments = data["arguments_string"]
@@ -81,28 +115,42 @@ def commands_section(service, alias, scheme, ports, unimplemented):
return "\n".join(content) return "\n".join(content)
def usage_section(service, alias, scheme, ports, unimplemented): def usage_section(service, variable, alias, image, scheme, ports, unimplemented):
return "\n\n".join([ return "\n\n".join(
[
"## Usage", "## Usage",
f"Help for any commands can be displayed by specifying the command as an argument to {service}:help. Please consult the `{service}:help` command for any undocumented commands.", f"Help for any commands can be displayed by specifying the command as an argument to {service}:help. Please consult the `{service}:help` command for any undocumented commands.",
usage_intro(service, alias, scheme, ports, unimplemented), usage_intro(service, variable, alias, image, scheme, ports, unimplemented),
usage_lifecycle(service, alias, scheme, ports, unimplemented), usage_lifecycle(service, variable, alias, image, scheme, ports, unimplemented),
usage_automation(service, alias, scheme, ports, unimplemented), usage_automation(service, variable, alias, image, scheme, ports, unimplemented),
usage_data_management(service, alias, scheme, ports, unimplemented), usage_data_management(service, variable, alias, image, scheme, ports, unimplemented),
usage_backup(service, alias, scheme, ports, unimplemented), usage_backup(service, variable, alias, image, scheme, ports, unimplemented),
usage_docker_pull(service, alias, scheme, ports, unimplemented), usage_docker_pull(service, variable, alias, image, scheme, ports, unimplemented),
]) ]
)
def usage_intro(service, alias, scheme, ports, unimplemented): def usage_intro(service, variable, alias, image, scheme, ports, unimplemented):
commands = ["create", "info", "list", "logs", "link", "unlink"] commands = ["create", "info", "list", "logs", "link", "unlink"]
content = ["### Basic Usage"] content = ["### Basic Usage"]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, variable, alias, image, scheme, ports, unimplemented, commands, content
)
def usage_lifecycle(service, alias, scheme, ports, unimplemented): def usage_lifecycle(service, variable, alias, image, scheme, ports, unimplemented):
commands = ["connect", "enter", "expose", "unexpose", "promote", "start", "stop", "restart", "upgrade"] commands = [
"connect",
"enter",
"expose",
"unexpose",
"promote",
"start",
"stop",
"restart",
"upgrade",
]
content = [ content = [
"### Service Lifecycle", "### Service Lifecycle",
"", "",
@@ -110,10 +158,12 @@ def usage_lifecycle(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, variable, alias, image, scheme, ports, unimplemented, commands, content
)
def usage_automation(service, alias, scheme, ports, unimplemented): def usage_automation(service, variable, alias, image, scheme, ports, unimplemented):
commands = ["app-links", "clone", "exists", "linked", "links"] commands = ["app-links", "clone", "exists", "linked", "links"]
content = [ content = [
"### Service Automation", "### Service Automation",
@@ -122,10 +172,12 @@ def usage_automation(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, variable, alias, image, scheme, ports, unimplemented, commands, content
)
def usage_data_management(service, alias, scheme, ports, unimplemented): def usage_data_management(service, variable, alias, image, scheme, ports, unimplemented):
commands = ["import", "export"] commands = ["import", "export"]
content = [ content = [
"### Data Management", "### Data Management",
@@ -134,11 +186,22 @@ def usage_data_management(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, variable, alias, image, scheme, ports, unimplemented, commands, content
)
def usage_backup(service, alias, scheme, ports, unimplemented): def usage_backup(service, variable, alias, image, scheme, ports, unimplemented):
commands = ["backup-auth", "backup-deauth", "backup", "backup-set-encryption", "backup-unset-encryption", "backup-schedule", "backup-schedule-cat", "backup-unschedule",] commands = [
"backup-auth",
"backup-deauth",
"backup",
"backup-set-encryption",
"backup-unset-encryption",
"backup-schedule",
"backup-schedule-cat",
"backup-unschedule",
]
content = [ content = [
"### Backups", "### Backups",
"", "",
@@ -150,24 +213,30 @@ def usage_backup(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, variable, alias, image, scheme, ports, unimplemented, commands, content
)
def usage_docker_pull(service, alias, scheme, ports, unimplemented): def usage_docker_pull(service, variable, alias, image, scheme, ports, unimplemented):
service_prefix = service.upper() service_prefix = service.upper()
return "\n".join([ return "\n".join(
[
"### Disabling `docker pull` calls", "### Disabling `docker pull` calls",
"", "",
f"If you wish to disable the `docker pull` calls that the plugin triggers, you may set the `{service_prefix}_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.", f"If you wish to disable the `docker pull` calls that the plugin triggers, you may set the `{service_prefix}_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.",
"", "",
"Please ensure the proper images are in place when `docker pull` is disabled.", "Please ensure the proper images are in place when `docker pull` is disabled.",
]) ]
)
def fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content): def fetch_commands_content(
service, variable, alias, image, scheme, ports, unimplemented, commands, content
):
i = 0 i = 0
for command in commands: for command in commands:
output = command_help(command, service, alias, scheme, ports, unimplemented) output = command_help(command, service, variable, alias, image, scheme, ports, unimplemented)
if output == "": if output == "":
continue continue
content.append(output) content.append(output)
@@ -205,11 +274,11 @@ def parse_args(line):
return " ".join(arguments) return " ".join(arguments)
def command_help(command, service, alias, scheme, ports, unimplemented): def command_help(command, service, variable, alias, image, scheme, ports, unimplemented):
if command in unimplemented: if command in unimplemented:
return "" return ""
data = command_data(command, service, alias, scheme, ports) data = command_data(command, service, variable, alias, image, scheme, ports)
content = [ content = [
f"### {data['description']}", f"### {data['description']}",
"", "",
@@ -226,12 +295,12 @@ def command_help(command, service, alias, scheme, ports, unimplemented):
# for argument in data["arguments"]: # for argument in data["arguments"]:
# content.append(f"- {argument}") # content.append(f"- {argument}")
# if len(data["flags"]) > 0: if len(data["flags"]) > 0:
# content.append("") content.append("")
# content.append("flags:") content.append("flags:")
# content.append("") content.append("")
# for flag in data["flags"]: for flag in data["flags"]:
# content.append(f"- {flag}") content.append(f"- {flag}")
if len(data["examples"]) > 0: if len(data["examples"]) > 0:
content.append("") content.append("")
@@ -240,7 +309,7 @@ def command_help(command, service, alias, scheme, ports, unimplemented):
return "\n" + "\n".join(content) return "\n" + "\n".join(content)
def command_data(command, service, alias, scheme, ports): def command_data(command, service, variable, alias, image, scheme, ports):
description = None description = None
arguments = [] arguments = []
arguments_string = "" arguments_string = ""
@@ -252,9 +321,12 @@ def command_data(command, service, alias, scheme, ports):
line = line.replace("$PLUGIN_SERVICE", service) line = line.replace("$PLUGIN_SERVICE", service)
line = line.replace("$PLUGIN_COMMAND_PREFIX", service) line = line.replace("$PLUGIN_COMMAND_PREFIX", service)
line = line.replace("${PLUGIN_COMMAND_PREFIX}", service) line = line.replace("${PLUGIN_COMMAND_PREFIX}", service)
line = line.replace("${PLUGIN_VARIABLE}", variable)
line = line.replace("${PLUGIN_DEFAULT_ALIAS}", alias) line = line.replace("${PLUGIN_DEFAULT_ALIAS}", alias)
line = line.replace("${PLUGIN_IMAGE}", image)
line = line.replace("${PLUGIN_SCHEME}", scheme) line = line.replace("${PLUGIN_SCHEME}", scheme)
line = line.replace("${PLUGIN_DATASTORE_PORTS[0]}", ports[0]) line = line.replace("${PLUGIN_DATASTORE_PORTS[0]}", ports[0])
line = line.replace("${PLUGIN_DATASTORE_PORTS[@]}", " ".join(ports))
if "declare desc" in line: if "declare desc" in line:
description = re.search('"(.+)"', line).group(1) description = re.search('"(.+)"', line).group(1)
@@ -350,10 +422,35 @@ def command_data(command, service, alias, scheme, ports):
def process_sentence(sentence_lines): def process_sentence(sentence_lines):
sentence_lines = " ".join(sentence_lines) sentence_lines = " ".join(sentence_lines)
sentences = ". ".join(i.strip().capitalize() for i in sentence_lines.split(".")).strip() sentences = ". ".join(
upperfirst(i.strip()) for i in sentence_lines.split(".")
).strip()
if not sentences.endswith(".") and not sentences.endswith(":"): if not sentences.endswith(".") and not sentences.endswith(":"):
sentences += ":" sentences += ":"
return sentences
text = []
for sentence in sentences.split("."):
parts = []
for word in sentence.strip().split(" "):
if word.isupper() and len(word) > 1:
for ending in [':', '.']:
if word.endswith(ending):
word = '`{0}`{1}'.format(word[:-1], ending)
else:
word = '`{0}`'.format(word)
parts.append(word)
text.append(" ".join(parts))
text = ". ".join(text)
# some cleanup
text = text.replace("(0. 0. 0. 0)", "(`0.0.0.0`)")
return text
def upperfirst(x):
return x[:1].upper() + x[1:]
def process_blockquote(blockquote_lines): def process_blockquote(blockquote_lines):
@@ -373,31 +470,48 @@ def process_codeblock(codeblock_lines):
def main(): def main():
service = None service = None
version = None version = None
variable = None
image = None
alias = None alias = None
unimplemented = [] unimplemented = []
with open("Dockerfile") as f:
for line in f.readlines():
if "FROM " in line:
image, version = line.split(" ")[1].split(":")
image = image.strip()
version = version.strip()
with open("config") as f: with open("config") as f:
for line in f.readlines(): for line in f.readlines():
if "IMAGE_VERSION=${" in line:
version = re.search('"(.+)"', line).group(1)
if "PLUGIN_COMMAND_PREFIX=" in line: if "PLUGIN_COMMAND_PREFIX=" in line:
service = re.search('"(.+)"', line).group(1) service = re.search('"(.+)"', line).group(1)
if "PLUGIN_DEFAULT_ALIAS=" in line: if "PLUGIN_DEFAULT_ALIAS=" in line:
alias = re.search('"(.+)"', line).group(1) alias = re.search('"(.+)"', line).group(1)
if "PLUGIN_VARIABLE=" in line:
variable = re.search('"(.+)"', line).group(1)
if "PLUGIN_SCHEME=" in line: if "PLUGIN_SCHEME=" in line:
scheme = re.search('"(.+)"', line).group(1) scheme = re.search('"(.+)"', line).group(1)
if "PLUGIN_DATASTORE_PORTS=" in line: if "PLUGIN_DATASTORE_PORTS=" in line:
ports = re.search('\((.+)\)', line).group(1).split(" ") ports = re.search("\((.+)\)", line).group(1).split(" ")
if "PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=" in line: if "PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=" in line:
match = re.search('\((.+)\)', line) match = re.search("\((.+)\)", line)
if match is not None: if match is not None:
unimplemented = [s.strip('"') for s in match.group(1).split(" ")] unimplemented = [s.strip('"') for s in match.group(1).split(" ")]
text = compile(service, version, alias, scheme, ports, unimplemented, "0.12.x+") sponsors = []
with open("plugin.toml") as f:
for line in f.readlines():
if line.startswith("sponsors"):
sponsors = re.search("\[([\"\w\s,_-]+)\]", line).group(1)
sponsors = [s.strip("\"") for s in sponsors.split(",")]
text = compile(service, version, variable, alias, image, scheme, ports, sponsors, unimplemented, "0.19.x+")
base_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) base_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
readme_file = os.path.join(base_path, 'README.md') readme_file = os.path.join(base_path, "README.md")
with open(readme_file, 'w') as f: with open(readme_file, "w") as f:
f.write(text) f.write(text + "\n")
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -120,7 +120,7 @@ retry-docker-command() {
local i=0 success=false local i=0 success=false
until [ $i -ge 100 ]; do until [ $i -ge 100 ]; do
set +e set +e
docker exec -it "$ID" sh -c "$COMMAND" 2>/dev/null suppress_output docker exec "$ID" sh -c "$COMMAND"
exit_code=$? exit_code=$?
set -e set -e
if [[ "$exit_code" == 0 ]]; then if [[ "$exit_code" == 0 ]]; then
@@ -188,18 +188,18 @@ service_backup() {
dokku_log_fail "Provide AWS credentials or use the --use-iam flag" dokku_log_fail "Provide AWS credentials or use the --use-iam flag"
fi fi
TMPDIR=$(mktemp -d) BACKUP_TMPDIR=$(mktemp -d --tmpdir)
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT trap 'rm -rf "$BACKUP_TMPDIR" > /dev/null' RETURN INT TERM EXIT
docker inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist" docker inspect "$ID" &>/dev/null || dokku_log_fail "Service container does not exist"
is_container_status "$ID" "Running" || dokku_log_fail "Service container is not running" is_container_status "$ID" "Running" || dokku_log_fail "Service container is not running"
(service_export "$SERVICE" >"${TMPDIR}/export") (service_export "$SERVICE" >"${BACKUP_TMPDIR}/export")
# Build parameter list for s3backup tool # Build parameter list for s3backup tool
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e BUCKET_NAME=$BUCKET_NAME" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e BUCKET_NAME=$BUCKET_NAME"
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e BACKUP_NAME=${PLUGIN_COMMAND_PREFIX}-${SERVICE}" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e BACKUP_NAME=${PLUGIN_COMMAND_PREFIX}-${SERVICE}"
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -v ${TMPDIR}:/backup" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -v ${BACKUP_TMPDIR}:/backup"
if [[ -f "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION" ]]; then if [[ -f "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_DEFAULT_REGION=$(cat "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION")" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_DEFAULT_REGION=$(cat "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION")"
@@ -383,7 +383,7 @@ service_info() {
local flag key valid_flags local flag key valid_flags
local flag_map=( local flag_map=(
"--config-dir: ${SERVICE_ROOT}/config" "--config-dir: ${SERVICE_ROOT}/${PLUGIN_CONFIG_SUFFIX}"
"--data-dir: ${SERVICE_ROOT}/data" "--data-dir: ${SERVICE_ROOT}/data"
"--dsn: ${SERVICE_URL}" "--dsn: ${SERVICE_URL}"
"--exposed-ports: $(service_exposed_ports "$SERVICE")" "--exposed-ports: $(service_exposed_ports "$SERVICE")"
@@ -453,6 +453,7 @@ service_link() {
fi fi
[[ -n $LINK ]] && dokku_log_fail "Already linked as $LINK" [[ -n $LINK ]] && dokku_log_fail "Already linked as $LINK"
plugn trigger service-action pre-link "$SERVICE" "$APP"
touch "$LINKS_FILE" touch "$LINKS_FILE"
echo "$APP" >>"$LINKS_FILE" echo "$APP" >>"$LINKS_FILE"
sort "$LINKS_FILE" -u -o "$LINKS_FILE" sort "$LINKS_FILE" -u -o "$LINKS_FILE"
@@ -465,7 +466,9 @@ service_link() {
dokku docker-options:add "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_DNS_HOSTNAME" dokku docker-options:add "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_DNS_HOSTNAME"
fi fi
[[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}" [[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}"
plugn trigger service-action post-link "$SERVICE" "$APP"
config_set "$APP" "${ALIAS}_URL=$SERVICE_URL" config_set "$APP" "${ALIAS}_URL=$SERVICE_URL"
plugn trigger service-action post-link-complete "$SERVICE" "$APP"
} }
service_linked_apps() { service_linked_apps() {
@@ -771,6 +774,7 @@ service_unlink() {
local SERVICE_DNS_HOSTNAME=$(service_dns_hostname "$SERVICE") local SERVICE_DNS_HOSTNAME=$(service_dns_hostname "$SERVICE")
local LINK=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true local LINK=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true
plugn trigger service-action pre-unlink "$SERVICE" "$APP"
remove_from_links_file "$SERVICE" "$APP" remove_from_links_file "$SERVICE" "$APP"
if declare -f -F add_passed_docker_option >/dev/null; then if declare -f -F add_passed_docker_option >/dev/null; then
@@ -782,7 +786,9 @@ service_unlink() {
fi fi
[[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP" [[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP"
plugn trigger service-action post-unlink "$SERVICE" "$APP"
config_unset "$APP" "${LINK[*]}" config_unset "$APP" "${LINK[*]}"
plugn trigger service-action post-unlink-complete "$SERVICE" "$APP"
} }
service_version() { service_version() {

6
config
View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
export MYSQL_IMAGE=${MYSQL_IMAGE:="mysql"} _DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export MYSQL_IMAGE_VERSION=${MYSQL_IMAGE_VERSION:="5.7.28"} export MYSQL_IMAGE=${MYSQL_IMAGE:="$(awk -F '[ :]' '{print $2}' "${_DIR}/Dockerfile")"}
export MYSQL_IMAGE_VERSION=${MYSQL_IMAGE_VERSION:="$(awk -F '[ :]' '{print $3}' "${_DIR}/Dockerfile")"}
export MYSQL_ROOT=${MYSQL_ROOT:="$DOKKU_LIB_ROOT/services/mysql"} export MYSQL_ROOT=${MYSQL_ROOT:="$DOKKU_LIB_ROOT/services/mysql"}
export MYSQL_HOST_ROOT=${MYSQL_HOST_ROOT:=$MYSQL_ROOT} export MYSQL_HOST_ROOT=${MYSQL_HOST_ROOT:=$MYSQL_ROOT}
@@ -21,6 +22,7 @@ export PLUGIN_SCHEME="mysql"
export PLUGIN_SERVICE="MySQL" export PLUGIN_SERVICE="MySQL"
export PLUGIN_VARIABLE="MYSQL" export PLUGIN_VARIABLE="MYSQL"
export PLUGIN_BASE_PATH="$PLUGIN_PATH" export PLUGIN_BASE_PATH="$PLUGIN_PATH"
export PLUGIN_CONFIG_SUFFIX="config"
if [[ -n $DOKKU_API_VERSION ]]; then if [[ -n $DOKKU_API_VERSION ]]; then
export PLUGIN_BASE_PATH="$PLUGIN_ENABLED_PATH" export PLUGIN_BASE_PATH="$PLUGIN_ENABLED_PATH"
fi fi

View File

@@ -41,13 +41,14 @@ service_create() {
docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed" docker pull "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" || dokku_log_fail "$PLUGIN_SERVICE image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION pull failed"
fi fi
plugn trigger service-action pre-create "$SERVICE"
mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory" mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory"
mkdir -p "$SERVICE_ROOT/data" || dokku_log_fail "Unable to create service data directory" mkdir -p "$SERVICE_ROOT/data" || dokku_log_fail "Unable to create service data directory"
mkdir -p "$SERVICE_ROOT/config" || dokku_log_fail "Unable to create service config directory" mkdir -p "$SERVICE_ROOT/$PLUGIN_CONFIG_SUFFIX" || dokku_log_fail "Unable to create service config directory"
touch "$LINKS_FILE" touch "$LINKS_FILE"
echo -e "[mysqld]\nperformance_schema = 0" >"$SERVICE_ROOT/config/disable_performance_schema.cnf" echo -e "[mysqld]\nperformance_schema = 0" >"$SERVICE_ROOT/$PLUGIN_CONFIG_SUFFIX/disable_performance_schema.cnf"
echo -e "[mysqld]\ncharacter-set-server = utf8\ncollation-server = utf8_general_ci" >"$SERVICE_ROOT/config/charset_utf8.cnf" echo -e "[mysqld]\ncharacter-set-server = utf8\ncollation-server = utf8_general_ci" >"$SERVICE_ROOT/$PLUGIN_CONFIG_SUFFIX/charset_utf8.cnf"
ROOTPASSWORD=$(openssl rand -hex 8) ROOTPASSWORD=$(openssl rand -hex 8)
PASSWORD=$(openssl rand -hex 8) PASSWORD=$(openssl rand -hex 8)
if [[ -n "$SERVICE_PASSWORD" ]]; then if [[ -n "$SERVICE_PASSWORD" ]]; then
@@ -70,7 +71,9 @@ service_create() {
fi fi
write_database_name "$SERVICE" write_database_name "$SERVICE"
plugn trigger service-action post-create "$SERVICE"
service_create_container "$SERVICE" service_create_container "$SERVICE"
plugn trigger service-action post-create-complete "$SERVICE"
} }
service_create_container() { service_create_container() {
@@ -82,7 +85,7 @@ service_create_container() {
local PASSWORD="$(service_password "$SERVICE")" local PASSWORD="$(service_password "$SERVICE")"
local DATABASE_NAME="$(get_database_name "$SERVICE")" local DATABASE_NAME="$(get_database_name "$SERVICE")"
ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_HOST_ROOT/data:/var/lib/mysql" -v "$SERVICE_HOST_ROOT/config:/etc/mysql/conf.d" -e "MYSQL_ROOT_PASSWORD=$ROOTPASSWORD" -e MYSQL_USER=mysql -e "MYSQL_PASSWORD=$PASSWORD" -e "MYSQL_DATABASE=$DATABASE_NAME" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=mysql "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION") ID=$(docker run --name "$SERVICE_NAME" -v "$SERVICE_HOST_ROOT/data:/var/lib/mysql" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/etc/mysql/conf.d" -e "MYSQL_ROOT_PASSWORD=$ROOTPASSWORD" -e MYSQL_USER=mysql -e "MYSQL_PASSWORD=$PASSWORD" -e "MYSQL_DATABASE=$DATABASE_NAME" --env-file="$SERVICE_ROOT/ENV" -d --restart always --label dokku=service --label dokku.service=mysql "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION")
echo "$ID" >"$SERVICE_ROOT/ID" echo "$ID" >"$SERVICE_ROOT/ID"
dokku_log_verbose_quiet "Waiting for container to be ready" dokku_log_verbose_quiet "Waiting for container to be ready"
@@ -101,7 +104,7 @@ service_export() {
[[ -n $SSH_TTY ]] && stty -opost [[ -n $SSH_TTY ]] && stty -opost
docker exec "$SERVICE_NAME" bash -c "printf '[client]\npassword=$PASSWORD\n' > /root/credentials.cnf" docker exec "$SERVICE_NAME" bash -c "printf '[client]\npassword=$PASSWORD\n' > /root/credentials.cnf"
docker exec "$SERVICE_NAME" mysqldump --defaults-extra-file=/root/credentials.cnf --user=mysql "$DATABASE_NAME" docker exec "$SERVICE_NAME" mysqldump --defaults-extra-file=/root/credentials.cnf --user=mysql --single-transaction --quick "$DATABASE_NAME"
docker exec "$SERVICE_NAME" rm /root/credentials.cnf docker exec "$SERVICE_NAME" rm /root/credentials.cnf
status=$? status=$?
[[ -n $SSH_TTY ]] && stty opost [[ -n $SSH_TTY ]] && stty opost
@@ -148,9 +151,13 @@ service_start() {
dokku_log_info2 "Container started" dokku_log_info2 "Container started"
elif service_image_exists "$SERVICE" && [[ -n "$ROOTPASSWORD" ]] && [[ -n "$PASSWORD" ]]; then elif service_image_exists "$SERVICE" && [[ -n "$ROOTPASSWORD" ]] && [[ -n "$PASSWORD" ]]; then
service_create_container "$SERVICE" service_create_container "$SERVICE"
else
if ! service_image_exists "$SERVICE"; then
dokku_log_verbose_quiet "Missing image $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION for $SERVICE"
else else
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE" dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
fi fi
fi
} }
service_url() { service_url() {

View File

@@ -76,10 +76,10 @@ fn-help-contents() {
fn-help-contents-subcommand() { fn-help-contents-subcommand() {
declare SUBCOMMAND="$1" FULL_OUTPUT="$2" declare SUBCOMMAND="$1" FULL_OUTPUT="$2"
local TMPDIR=$(mktemp -d) local HELP_TMPDIR=$(mktemp -d --tmpdir)
local UNCLEAN_FILE="${TMPDIR}/cmd-unclean" CLEAN_FILE="${TMPDIR}/cmd-clean" local UNCLEAN_FILE="${HELP_TMPDIR}/cmd-unclean" CLEAN_FILE="${HELP_TMPDIR}/cmd-clean"
local BOLD CMD_OUTPUT CYAN EXAMPLE LIGHT_GRAY NORMAL local BOLD CMD_OUTPUT CYAN EXAMPLE LIGHT_GRAY NORMAL
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT trap 'rm -rf "$HELP_TMPDIR" > /dev/null' RETURN INT TERM EXIT
rm -rf "$UNCLEAN_FILE" "$CLEAN_FILE" rm -rf "$UNCLEAN_FILE" "$CLEAN_FILE"
cat "$SUBCOMMAND_ROOT/$SUBCOMMAND" >"$UNCLEAN_FILE" cat "$SUBCOMMAND_ROOT/$SUBCOMMAND" >"$UNCLEAN_FILE"
@@ -164,8 +164,8 @@ fn-help-list-example() {
# shellcheck disable=SC2034 # shellcheck disable=SC2034
declare desc="return $PLUGIN_COMMAND_PREFIX plugin help content" declare desc="return $PLUGIN_COMMAND_PREFIX plugin help content"
cat <<help_list cat <<help_list
NAME, VERSION, STATUS, EXPOSED PORTS, LINKS $PLUGIN_SERVICE services
service-name, $PLUGIN_COMMAND_PREFIX:$PLUGIN_IMAGE_VERSION, running, -, app-name service-name
help_list help_list
} }

View File

@@ -1,4 +1,4 @@
[plugin] [plugin]
description = "dokku mysql service plugin" description = "dokku mysql service plugin"
version = "1.11.1" version = "1.14.1"
[plugin.config] [plugin.config]

View File

@@ -6,7 +6,7 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-backup-set-encryption-cmd() { service-backup-set-encryption-cmd() {
#E set a GPG passphrase for backups #E set the GPG-compatible passphrase for encrypting backups for backups
#E dokku $PLUGIN_COMMAND_PREFIX:backup-set-encryption lolipop #E dokku $PLUGIN_COMMAND_PREFIX:backup-set-encryption lolipop
#A service, service to run command against #A service, service to run command against
#A passphrase, a GPG-compatible passphrase #A passphrase, a GPG-compatible passphrase

View File

@@ -6,7 +6,7 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-backup-unset-encryption-cmd() { service-backup-unset-encryption-cmd() {
#E unset a GPG encryption key for backups #E unset the GPG encryption passphrase for backups
#E dokku $PLUGIN_COMMAND_PREFIX:backup-unset-encryption lolipop #E dokku $PLUGIN_COMMAND_PREFIX:backup-unset-encryption lolipop
#A service, service to run command against #A service, service to run command against
declare desc="unsets encryption for future backups of the $PLUGIN_SERVICE service" declare desc="unsets encryption for future backups of the $PLUGIN_SERVICE service"

View File

@@ -41,13 +41,15 @@ service-destroy-cmd() {
fi fi
dokku_log_info2_quiet "Deleting $SERVICE" dokku_log_info2_quiet "Deleting $SERVICE"
plugn trigger service-action pre-delete "$SERVICE"
service_backup_unschedule "$SERVICE" service_backup_unschedule "$SERVICE"
service_container_rm "$SERVICE" service_container_rm "$SERVICE"
dokku_log_verbose_quiet "Removing data" dokku_log_verbose_quiet "Removing data"
docker run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/config:/config" "$PLUGIN_BUSYBOX_IMAGE" chmod 777 -R /config /data docker run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/$PLUGIN_CONFIG_SUFFIX:/config" "$PLUGIN_BUSYBOX_IMAGE" chmod 777 -R /config /data
rm -rf "$SERVICE_ROOT" rm -rf "$SERVICE_ROOT"
plugn trigger service-action post-delete "$SERVICE"
dokku_log_info2 "$PLUGIN_SERVICE container deleted: $SERVICE" dokku_log_info2 "$PLUGIN_SERVICE container deleted: $SERVICE"
} }

View File

@@ -30,10 +30,10 @@ service-link-cmd() {
#E use the 'expose' subcommand. another service can be linked to your app: #E use the 'expose' subcommand. another service can be linked to your app:
#E dokku $PLUGIN_COMMAND_PREFIX:link other_service playground #E dokku $PLUGIN_COMMAND_PREFIX:link other_service playground
#E it is possible to change the protocol for ${PLUGIN_DEFAULT_ALIAS}_URL by setting the #E it is possible to change the protocol for ${PLUGIN_DEFAULT_ALIAS}_URL by setting the
#E environment variable ${PLUGIN_DEFAULT_ALIAS}_DATABASE_SCHEME on the app. doing so will #E environment variable ${PLUGIN_VARIABLE}_DATABASE_SCHEME on the app. doing so will
#E after linking will cause the plugin to think the service is not #E after linking will cause the plugin to think the service is not
#E linked, and we advise you to unlink before proceeding. #E linked, and we advise you to unlink before proceeding.
#E dokku config:set playground ${PLUGIN_DEFAULT_ALIAS}_DATABASE_SCHEME=${PLUGIN_SCHEME}2 #E dokku config:set playground ${PLUGIN_VARIABLE}_DATABASE_SCHEME=${PLUGIN_SCHEME}2
#E dokku $PLUGIN_COMMAND_PREFIX:link lolipop playground #E dokku $PLUGIN_COMMAND_PREFIX:link lolipop playground
#E this will cause ${PLUGIN_DEFAULT_ALIAS}_URL to be set as: #E this will cause ${PLUGIN_DEFAULT_ALIAS}_URL to be set as:
#E #E

View File

@@ -2,18 +2,18 @@
load test_helper load test_helper
setup() { setup() {
dokku apps:create my_app dokku apps:create my-app
dokku "$PLUGIN_COMMAND_PREFIX:create" l dokku "$PLUGIN_COMMAND_PREFIX:create" l
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app >&2 dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app >&2
} }
teardown() { teardown() {
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app >&2 dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app >&2
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l
} }
@test "($PLUGIN_COMMAND_PREFIX:hook:pre-delete) removes app from links file when destroying app" { @test "($PLUGIN_COMMAND_PREFIX:hook:pre-delete) removes app from links file when destroying app" {
[[ -n $(< "$PLUGIN_DATA_ROOT/l/LINKS") ]] [[ -n $(< "$PLUGIN_DATA_ROOT/l/LINKS") ]]
dokku --force apps:destroy my_app dokku --force apps:destroy my-app
[[ -z $(< "$PLUGIN_DATA_ROOT/l/LINKS") ]] [[ -z $(< "$PLUGIN_DATA_ROOT/l/LINKS") ]]
} }

View File

@@ -20,6 +20,9 @@ teardown() {
} }
@test "($PLUGIN_COMMAND_PREFIX:export) success with SSH_TTY" { @test "($PLUGIN_COMMAND_PREFIX:export) success with SSH_TTY" {
if [[ -n "$GITHUB_WORKFLOW" ]]; then
skip "No tty is available on Github Actions"
fi
export SSH_TTY=`tty` export SSH_TTY=`tty`
run dokku "$PLUGIN_COMMAND_PREFIX:export" l run dokku "$PLUGIN_COMMAND_PREFIX:export" l
echo "output: $output" echo "output: $output"

View File

@@ -24,6 +24,9 @@ teardown() {
} }
@test "($PLUGIN_COMMAND_PREFIX:import) error when data is not provided" { @test "($PLUGIN_COMMAND_PREFIX:import) error when data is not provided" {
if [[ -n "$GITHUB_WORKFLOW" ]]; then
skip "No tty is available on Github Actions"
fi
run dokku "$PLUGIN_COMMAND_PREFIX:import" l run dokku "$PLUGIN_COMMAND_PREFIX:import" l
assert_contains "${lines[*]}" "No data provided on stdin" assert_contains "${lines[*]}" "No data provided on stdin"
assert_failure assert_failure

View File

@@ -4,13 +4,13 @@ load test_helper
setup() { setup() {
dokku "$PLUGIN_COMMAND_PREFIX:create" l dokku "$PLUGIN_COMMAND_PREFIX:create" l
dokku "$PLUGIN_COMMAND_PREFIX:create" m dokku "$PLUGIN_COMMAND_PREFIX:create" m
dokku apps:create my_app dokku apps:create my-app
} }
teardown() { teardown() {
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" m dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" m
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l
dokku --force apps:destroy my_app dokku --force apps:destroy my-app
} }
@@ -39,7 +39,7 @@ teardown() {
} }
@test "($PLUGIN_COMMAND_PREFIX:link) error when the service does not exist" { @test "($PLUGIN_COMMAND_PREFIX:link) error when the service does not exist" {
run dokku "$PLUGIN_COMMAND_PREFIX:link" not_existing_service my_app run dokku "$PLUGIN_COMMAND_PREFIX:link" not_existing_service my-app
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_contains "${lines[*]}" "service not_existing_service does not exist" assert_contains "${lines[*]}" "service not_existing_service does not exist"
@@ -47,73 +47,73 @@ teardown() {
} }
@test "($PLUGIN_COMMAND_PREFIX:link) error when the service is already linked to app" { @test "($PLUGIN_COMMAND_PREFIX:link) error when the service is already linked to app" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app
run dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app run dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_contains "${lines[*]}" "Already linked as DATABASE_URL" assert_contains "${lines[*]}" "Already linked as DATABASE_URL"
assert_failure assert_failure
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:link) exports DATABASE_URL to app" { @test "($PLUGIN_COMMAND_PREFIX:link) exports DATABASE_URL to app" {
run dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app run dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
url=$(dokku config:get my_app DATABASE_URL) url=$(dokku config:get my-app DATABASE_URL)
password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
assert_contains "$url" "mysql://mysql:$password@dokku-mysql-l:3306/l" assert_contains "$url" "mysql://mysql:$password@dokku-mysql-l:3306/l"
assert_success assert_success
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:link) generates an alternate config url when DATABASE_URL already in use" { @test "($PLUGIN_COMMAND_PREFIX:link) generates an alternate config url when DATABASE_URL already in use" {
dokku config:set my_app DATABASE_URL=mysql://user:pass@host:3306/db dokku config:set my-app DATABASE_URL=mysql://user:pass@host:3306/db
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app
run dokku config my_app run dokku config my-app
assert_contains "${lines[*]}" "DOKKU_MYSQL_AQUA_URL" assert_contains "${lines[*]}" "DOKKU_MYSQL_AQUA_URL"
assert_success assert_success
dokku "$PLUGIN_COMMAND_PREFIX:link" m my_app dokku "$PLUGIN_COMMAND_PREFIX:link" m my-app
run dokku config my_app run dokku config my-app
assert_contains "${lines[*]}" "DOKKU_MYSQL_BLACK_URL" assert_contains "${lines[*]}" "DOKKU_MYSQL_BLACK_URL"
assert_success assert_success
dokku "$PLUGIN_COMMAND_PREFIX:unlink" m my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" m my-app
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:link) links to app with docker-options" { @test "($PLUGIN_COMMAND_PREFIX:link) links to app with docker-options" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app
run dokku docker-options:report my_app run dokku docker-options:report my-app
assert_contains "${lines[*]}" "--link dokku.mysql.l:dokku-mysql-l" assert_contains "${lines[*]}" "--link dokku.mysql.l:dokku-mysql-l"
assert_success assert_success
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:link) uses apps MYSQL_DATABASE_SCHEME variable" { @test "($PLUGIN_COMMAND_PREFIX:link) uses apps MYSQL_DATABASE_SCHEME variable" {
dokku config:set my_app MYSQL_DATABASE_SCHEME=mysql2 dokku config:set my-app MYSQL_DATABASE_SCHEME=mysql2
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app
url=$(dokku config:get my_app DATABASE_URL) url=$(dokku config:get my-app DATABASE_URL)
password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
assert_contains "$url" "mysql2://mysql:$password@dokku-mysql-l:3306/l" assert_contains "$url" "mysql2://mysql:$password@dokku-mysql-l:3306/l"
assert_success assert_success
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:link) adds a querystring" { @test "($PLUGIN_COMMAND_PREFIX:link) adds a querystring" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app --querystring "pool=5" dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app --querystring "pool=5"
url=$(dokku config:get my_app DATABASE_URL) url=$(dokku config:get my-app DATABASE_URL)
assert_contains "$url" "?pool=5" assert_contains "$url" "?pool=5"
assert_success assert_success
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:link) uses a specified config url when alias is specified" { @test "($PLUGIN_COMMAND_PREFIX:link) uses a specified config url when alias is specified" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app --alias "ALIAS" dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app --alias "ALIAS"
url=$(dokku config:get my_app ALIAS_URL) url=$(dokku config:get my-app ALIAS_URL)
password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
assert_contains "$url" "mysql://mysql:$password@dokku-mysql-l:3306/l" assert_contains "$url" "mysql://mysql:$password@dokku-mysql-l:3306/l"
assert_success assert_success
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
} }

View File

@@ -3,14 +3,14 @@ load test_helper
setup() { setup() {
dokku "$PLUGIN_COMMAND_PREFIX:create" l dokku "$PLUGIN_COMMAND_PREFIX:create" l
dokku apps:create my_app dokku apps:create my-app
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app
} }
teardown() { teardown() {
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l
dokku --force apps:destroy my_app dokku --force apps:destroy my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:promote) error when there are no arguments" { @test "($PLUGIN_COMMAND_PREFIX:promote) error when there are no arguments" {
@@ -29,35 +29,35 @@ teardown() {
} }
@test "($PLUGIN_COMMAND_PREFIX:promote) error when the service does not exist" { @test "($PLUGIN_COMMAND_PREFIX:promote) error when the service does not exist" {
run dokku "$PLUGIN_COMMAND_PREFIX:promote" not_existing_service my_app run dokku "$PLUGIN_COMMAND_PREFIX:promote" not_existing_service my-app
assert_contains "${lines[*]}" "service not_existing_service does not exist" assert_contains "${lines[*]}" "service not_existing_service does not exist"
} }
@test "($PLUGIN_COMMAND_PREFIX:promote) error when the service is already promoted" { @test "($PLUGIN_COMMAND_PREFIX:promote) error when the service is already promoted" {
run dokku "$PLUGIN_COMMAND_PREFIX:promote" l my_app run dokku "$PLUGIN_COMMAND_PREFIX:promote" l my-app
assert_contains "${lines[*]}" "already promoted as DATABASE_URL" assert_contains "${lines[*]}" "already promoted as DATABASE_URL"
} }
@test "($PLUGIN_COMMAND_PREFIX:promote) changes DATABASE_URL" { @test "($PLUGIN_COMMAND_PREFIX:promote) changes DATABASE_URL" {
password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
dokku config:set my_app "DATABASE_URL=mysql://u:p@host:3306/db" "DOKKU_MYSQL_BLUE_URL=mysql://mysql:$password@dokku-mysql-l:3306/l" dokku config:set my-app "DATABASE_URL=mysql://u:p@host:3306/db" "DOKKU_MYSQL_BLUE_URL=mysql://mysql:$password@dokku-mysql-l:3306/l"
dokku "$PLUGIN_COMMAND_PREFIX:promote" l my_app dokku "$PLUGIN_COMMAND_PREFIX:promote" l my-app
url=$(dokku config:get my_app DATABASE_URL) url=$(dokku config:get my-app DATABASE_URL)
assert_equal "$url" "mysql://mysql:$password@dokku-mysql-l:3306/l" assert_equal "$url" "mysql://mysql:$password@dokku-mysql-l:3306/l"
} }
@test "($PLUGIN_COMMAND_PREFIX:promote) creates new config url when needed" { @test "($PLUGIN_COMMAND_PREFIX:promote) creates new config url when needed" {
password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
dokku config:set my_app "DATABASE_URL=mysql://u:p@host:3306/db" "DOKKU_MYSQL_BLUE_URL=mysql://mysql:$password@dokku-mysql-l:3306/l" dokku config:set my-app "DATABASE_URL=mysql://u:p@host:3306/db" "DOKKU_MYSQL_BLUE_URL=mysql://mysql:$password@dokku-mysql-l:3306/l"
dokku "$PLUGIN_COMMAND_PREFIX:promote" l my_app dokku "$PLUGIN_COMMAND_PREFIX:promote" l my-app
run dokku config my_app run dokku config my-app
assert_contains "${lines[*]}" "DOKKU_MYSQL_" assert_contains "${lines[*]}" "DOKKU_MYSQL_"
} }
@test "($PLUGIN_COMMAND_PREFIX:promote) uses MYSQL_DATABASE_SCHEME variable" { @test "($PLUGIN_COMMAND_PREFIX:promote) uses MYSQL_DATABASE_SCHEME variable" {
password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" password="$(sudo cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
dokku config:set my_app "MYSQL_DATABASE_SCHEME=mysql2" "DATABASE_URL=mysql://u:p@host:3306/db" "DOKKU_MYSQL_BLUE_URL=mysql2://mysql:$password@dokku-mysql-l:3306/l" dokku config:set my-app "MYSQL_DATABASE_SCHEME=mysql2" "DATABASE_URL=mysql://u:p@host:3306/db" "DOKKU_MYSQL_BLUE_URL=mysql2://mysql:$password@dokku-mysql-l:3306/l"
dokku "$PLUGIN_COMMAND_PREFIX:promote" l my_app dokku "$PLUGIN_COMMAND_PREFIX:promote" l my-app
url=$(dokku config:get my_app DATABASE_URL) url=$(dokku config:get my-app DATABASE_URL)
assert_contains "$url" "mysql2://mysql:$password@dokku-mysql-l:3306/l" assert_contains "$url" "mysql2://mysql:$password@dokku-mysql-l:3306/l"
} }

View File

@@ -2,13 +2,13 @@
load test_helper load test_helper
setup() { setup() {
dokku apps:create my_app dokku apps:create my-app
dokku "$PLUGIN_COMMAND_PREFIX:create" l dokku "$PLUGIN_COMMAND_PREFIX:create" l
} }
teardown() { teardown() {
dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l dokku --force "$PLUGIN_COMMAND_PREFIX:destroy" l
dokku --force apps:destroy my_app dokku --force apps:destroy my-app
} }
@test "($PLUGIN_COMMAND_PREFIX:unlink) error when there are no arguments" { @test "($PLUGIN_COMMAND_PREFIX:unlink) error when there are no arguments" {
@@ -27,27 +27,27 @@ teardown() {
} }
@test "($PLUGIN_COMMAND_PREFIX:unlink) error when the service does not exist" { @test "($PLUGIN_COMMAND_PREFIX:unlink) error when the service does not exist" {
run dokku "$PLUGIN_COMMAND_PREFIX:unlink" not_existing_service my_app run dokku "$PLUGIN_COMMAND_PREFIX:unlink" not_existing_service my-app
assert_contains "${lines[*]}" "service not_existing_service does not exist" assert_contains "${lines[*]}" "service not_existing_service does not exist"
} }
@test "($PLUGIN_COMMAND_PREFIX:unlink) error when service not linked to app" { @test "($PLUGIN_COMMAND_PREFIX:unlink) error when service not linked to app" {
run dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app run dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
assert_contains "${lines[*]}" "Not linked to app my_app" assert_contains "${lines[*]}" "Not linked to app my-app"
} }
@test "($PLUGIN_COMMAND_PREFIX:unlink) removes link from docker-options" { @test "($PLUGIN_COMMAND_PREFIX:unlink) removes link from docker-options" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app >&2 dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app >&2
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
check_value="Docker options build: Docker options deploy: --restart=on-failure:10 Docker options run:" check_value="Docker options build: Docker options deploy: --restart=on-failure:10 Docker options run:"
options=$(dokku --quiet docker-options:report my_app | xargs) options=$(dokku --quiet docker-options:report my-app | xargs)
assert_equal "$options" "$check_value" assert_equal "$options" "$check_value"
} }
@test "($PLUGIN_COMMAND_PREFIX:unlink) unsets config url from app" { @test "($PLUGIN_COMMAND_PREFIX:unlink) unsets config url from app" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app >&2 dokku "$PLUGIN_COMMAND_PREFIX:link" l my-app >&2
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my-app
config=$(dokku config:get my_app DATABASE_URL || true) config=$(dokku config:get my-app DATABASE_URL || true)
assert_equal "$config" "" assert_equal "$config" ""
} }

View File

@@ -19,12 +19,15 @@ echo "Dokku version $DOKKU_VERSION"
export DOKKU_LIB_ROOT="/var/lib/dokku" export DOKKU_LIB_ROOT="/var/lib/dokku"
export DOKKU_PLUGINS_ROOT="$DOKKU_LIB_ROOT/plugins/available" export DOKKU_PLUGINS_ROOT="$DOKKU_LIB_ROOT/plugins/available"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" pushd "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")" >/dev/null
source "config"
popd >/dev/null
sudo rm -rf "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX" sudo rm -rf "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX"
sudo mkdir -p "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX" "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/subcommands" "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/scripts" sudo mkdir -p "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX" "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/subcommands" "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/scripts" "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/templates"
sudo find ./ -maxdepth 1 -type f -exec cp '{}' "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX" \; sudo find ./ -maxdepth 1 -type f -exec cp '{}' "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX" \;
[[ -d "./scripts" ]] && sudo find ./scripts -maxdepth 1 -type f -exec cp '{}' "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/scripts" \; [[ -d "./scripts" ]] && sudo find ./scripts -maxdepth 1 -type f -exec cp '{}' "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/scripts" \;
[[ -d "./subcommands" ]] && sudo find ./subcommands -maxdepth 1 -type f -exec cp '{}' "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/subcommands" \; [[ -d "./subcommands" ]] && sudo find ./subcommands -maxdepth 1 -type f -exec cp '{}' "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/subcommands" \;
[[ -d "./templates" ]] && sudo find ./templates -maxdepth 1 -type f -exec cp '{}' "$DOKKU_PLUGINS_ROOT/$PLUGIN_COMMAND_PREFIX/templates" \;
sudo mkdir -p "$PLUGIN_CONFIG_ROOT" "$PLUGIN_DATA_ROOT" sudo mkdir -p "$PLUGIN_CONFIG_ROOT" "$PLUGIN_DATA_ROOT"
sudo dokku plugin:enable "$PLUGIN_COMMAND_PREFIX" sudo dokku plugin:enable "$PLUGIN_COMMAND_PREFIX"
sudo dokku plugin:install sudo dokku plugin:install