Merge pull request #3109 from dokku/scheduler
Refactor container scheduling into it's own plugin
This commit is contained in:
31
Makefile
31
Makefile
@@ -26,7 +26,7 @@ endif
|
||||
|
||||
include common.mk
|
||||
|
||||
.PHONY: all apt-update install version copyfiles man-db plugins dependencies sshcommand plugn docker aufs stack count dokku-installer vagrant-acl-add vagrant-dokku go-build
|
||||
.PHONY: all apt-update install version copyfiles copyplugin man-db plugins dependencies sshcommand plugn docker aufs stack count dokku-installer vagrant-acl-add vagrant-dokku go-build
|
||||
|
||||
include tests.mk
|
||||
include deb.mk
|
||||
@@ -76,24 +76,29 @@ copyfiles:
|
||||
rm -rf ${CORE_PLUGINS_PATH}/*
|
||||
test -d ${CORE_PLUGINS_PATH}/enabled || PLUGIN_PATH=${CORE_PLUGINS_PATH} plugn init
|
||||
test -d ${PLUGINS_PATH}/enabled || PLUGIN_PATH=${PLUGINS_PATH} plugn init
|
||||
find plugins/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read plugin; do \
|
||||
rm -Rf ${CORE_PLUGINS_PATH}/available/$$plugin && \
|
||||
rm -Rf ${PLUGINS_PATH}/available/$$plugin && \
|
||||
rm -rf ${CORE_PLUGINS_PATH}/$$plugin && \
|
||||
rm -rf ${PLUGINS_PATH}/$$plugin && \
|
||||
cp -R plugins/$$plugin ${CORE_PLUGINS_PATH}/available && \
|
||||
rm -rf ${CORE_PLUGINS_PATH}/available/$$plugin/src && \
|
||||
ln -s ${CORE_PLUGINS_PATH}/available/$$plugin ${PLUGINS_PATH}/available; \
|
||||
find /var/lib/dokku/ -xtype l -delete;\
|
||||
PLUGIN_PATH=${CORE_PLUGINS_PATH} plugn enable $$plugin ;\
|
||||
PLUGIN_PATH=${PLUGINS_PATH} plugn enable $$plugin ;\
|
||||
done
|
||||
find plugins/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | while read plugin; do $(MAKE) copyplugin PLUGIN_NAME=$$plugin; done
|
||||
ifndef SKIP_GO_CLEAN
|
||||
$(MAKE) go-clean
|
||||
endif
|
||||
chown dokku:dokku -R ${PLUGINS_PATH} ${CORE_PLUGINS_PATH} || true
|
||||
$(MAKE) addman
|
||||
|
||||
copyplugin:
|
||||
ifndef PLUGIN_NAME
|
||||
$(error PLUGIN_NAME not specified)
|
||||
endif
|
||||
rm -Rf ${CORE_PLUGINS_PATH}/available/$(PLUGIN_NAME) && \
|
||||
rm -Rf ${PLUGINS_PATH}/available/$(PLUGIN_NAME) && \
|
||||
rm -rf ${CORE_PLUGINS_PATH}/$(PLUGIN_NAME) && \
|
||||
rm -rf ${PLUGINS_PATH}/$(PLUGIN_NAME) && \
|
||||
cp -R plugins/$(PLUGIN_NAME) ${CORE_PLUGINS_PATH}/available && \
|
||||
rm -rf ${CORE_PLUGINS_PATH}/available/$(PLUGIN_NAME)/src && \
|
||||
ln -s ${CORE_PLUGINS_PATH}/available/$(PLUGIN_NAME) ${PLUGINS_PATH}/available; \
|
||||
find /var/lib/dokku/ -xtype l -delete;\
|
||||
PLUGIN_PATH=${CORE_PLUGINS_PATH} plugn enable $(PLUGIN_NAME) ;\
|
||||
PLUGIN_PATH=${PLUGINS_PATH} plugn enable $(PLUGIN_NAME)
|
||||
chown dokku:dokku -R ${PLUGINS_PATH} ${CORE_PLUGINS_PATH} || true
|
||||
|
||||
addman: help2man man-db
|
||||
mkdir -p /usr/local/share/man/man1
|
||||
help2man -Nh help -v version -n "configure and get information from your dokku installation" -o /usr/local/share/man/man1/dokku.1 dokku
|
||||
|
||||
31
docs/advanced-usage/schedulers/docker-local.md
Normal file
31
docs/advanced-usage/schedulers/docker-local.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Docker Local Scheduler
|
||||
|
||||
> New as of 0.12.0
|
||||
|
||||
Dokku natively includes functionality to manage application lifecycles for a single server using the `scheduler-docker-local` plugin. It is the default scheduler, but as with all schedulers, it is set on a per-application basis. The scheduler can currently be overridden by running the following command:
|
||||
|
||||
```shell
|
||||
dokku config:set node-js-app DOCKER_SCHEDULER=docker-local
|
||||
```
|
||||
|
||||
As it is the default, unsetting the `DOCKER_SCHEDULER` config variable is also a valid way to reset the scheduler.
|
||||
|
||||
```shell
|
||||
dokku config:unset node-js-app DOCKER_SCHEDULER
|
||||
```
|
||||
|
||||
## Implemented Triggers
|
||||
|
||||
This plugin implements various functionality through `plugn` triggers to integrate with Docker for running apps on a single server. The following functionality is supported by the `scheduler-docker-local` plugin.
|
||||
|
||||
- `check-deploy`
|
||||
- `core-post-deploy`
|
||||
- `post-delete`
|
||||
- `pre-deploy`
|
||||
- `pre-restore`
|
||||
- `scheduler-deploy`
|
||||
- `scheduler-docker-cleanup`
|
||||
- `scheduler-run`
|
||||
- `scheduler-stop`
|
||||
- `scheduler-tags-create`
|
||||
- `scheduler-tags-destroy`
|
||||
@@ -106,7 +106,7 @@ esac
|
||||
|
||||
> To avoid issues with community plugins, this plugin trigger should be used *only* for core plugins. Please avoid using this trigger in your own plugins.
|
||||
|
||||
- Description: Allows running of commands after an application's processes have been scaled up, but before old containers are torn down. Dokku core currently uses this to switch traffic on nginx.
|
||||
- Description: Allows running of commands after an app's processes have been scaled up, but before old containers are torn down. Dokku core currently uses this to switch traffic on nginx.
|
||||
- Invoked by: `dokku deploy`
|
||||
- Arguments: `$APP $INTERNAL_PORT $INTERNAL_IP_ADDRESS $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -426,7 +426,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `network-get-property`
|
||||
|
||||
- Description: Return the network value for an application's property
|
||||
- Description: Return the network value for an app's property
|
||||
- Invoked by: `internally triggered by a deploy`
|
||||
- Arguments: `$APP $KEY`
|
||||
- Example:
|
||||
@@ -471,14 +471,14 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `nginx-hostname`
|
||||
|
||||
- Description: Allows you to customize the hostname for a given application.
|
||||
- Description: Allows you to customize the hostname for a given app
|
||||
- Invoked by: `dokku domains:setup`
|
||||
- Arguments: `$APP $SUBDOMAIN $VHOST`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
# Reverses the hostname for the application
|
||||
# Reverses the hostname for the app
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
@@ -507,7 +507,7 @@ nginx -t
|
||||
|
||||
### `post-app-clone`
|
||||
|
||||
- Description: Allows you to run commands after an application was cloned.
|
||||
- Description: Allows you to run commands after an app was cloned.
|
||||
- Invoked by: `dokku apps:clone`
|
||||
- Arguments: `$OLD_APP_NAME $NEW_APP_NAME`
|
||||
- Example:
|
||||
@@ -522,7 +522,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `post-app-rename`
|
||||
|
||||
- Description: Allows you to run commands after an application was renamed.
|
||||
- Description: Allows you to run commands after an app was renamed.
|
||||
- Invoked by: `dokku apps:rename`
|
||||
- Arguments: `$OLD_APP_NAME $NEW_APP_NAME`
|
||||
- Example:
|
||||
@@ -537,7 +537,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `post-build-buildpack`
|
||||
|
||||
- Description: Allows you to run commands after the build image is create for a given app. Only applies to applications using buildpacks.
|
||||
- Description: Allows you to run commands after the build image is create for a given app. Only applies to apps using buildpacks.
|
||||
- Invoked by: `internal function dokku_build() (build phase)`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
@@ -552,7 +552,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `post-build-dockerfile`
|
||||
|
||||
- Description: Allows you to run commands after the build image is create for a given app. Only applies to applications using a dockerfile.
|
||||
- Description: Allows you to run commands after the build image is create for a given app. Only applies to apps using a dockerfile.
|
||||
- Invoked by: `internal function dokku_build() (build phase)`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
@@ -616,7 +616,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `post-create`
|
||||
|
||||
- Description: Can be used to run commands after an application is created.
|
||||
- Description: Can be used to run commands after an app is created.
|
||||
- Invoked by: `dokku apps:create`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
@@ -637,7 +637,7 @@ dokku postgres:link $POSTGRES $APP
|
||||
|
||||
### `post-delete`
|
||||
|
||||
- Description: Can be used to run commands after an application is deleted.
|
||||
- Description: Can be used to run commands after an app is deleted.
|
||||
- Invoked by: `dokku apps:destroy`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -658,7 +658,7 @@ dokku postgres:destroy $APP
|
||||
|
||||
> Please see [core-post-deploy](#core-post-deploy) if contributing a core plugin with the `post-deploy` hook.
|
||||
|
||||
- Description: Allows running of commands after an application's processes have been scaled up, but before old containers are torn down. Dokku calls this _after_ `core-post-deploy`. Deployment Tasks are also invoked by this plugin trigger.
|
||||
- Description: Allows running of commands after an app's processes have been scaled up, but before old containers are torn down. Dokku calls this _after_ `core-post-deploy`. Deployment Tasks are also invoked by this plugin trigger.
|
||||
- Invoked by: `dokku deploy`
|
||||
- Arguments: `$APP $INTERNAL_PORT $INTERNAL_IP_ADDRESS $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -674,7 +674,7 @@ curl "http://httpstat.us/200"
|
||||
|
||||
### `post-domains-update`
|
||||
|
||||
- Description: Allows you to run commands once the domain for an application has been updated. It also sends in the command that has been used. This can be "add", "clear" or "remove". The third argument will be the optional list of domains
|
||||
- Description: Allows you to run commands once the domain for an app has been updated. It also sends in the command that has been used. This can be "add", "clear" or "remove". The third argument will be the optional list of domains
|
||||
- Invoked by: `dokku domains:add`, `dokku domains:clear`, `dokku domains:remove`, `dokku domains:set`
|
||||
- Arguments: `$APP` `action name` `domains`
|
||||
- Example:
|
||||
@@ -691,7 +691,7 @@ sudo service haproxy reload
|
||||
|
||||
### `post-extract`
|
||||
|
||||
- Description: Allows you to modify the contents of an application *after* it has been extracted from git/tarball but *before* the image source type is detected.
|
||||
- Description: Allows you to modify the contents of an app *after* it has been extracted from git/tarball but *before* the image source type is detected.
|
||||
- Invoked by: `dokku tar:in`, `dokku tar:from` and the `receive-app` plugin trigger
|
||||
- Arguments: `$APP` `$TMP_WORK_DIR` `$REV`
|
||||
- Example:
|
||||
@@ -713,7 +713,7 @@ echo "clock: some-command" >> Procfile
|
||||
|
||||
### `post-proxy-ports-update`
|
||||
|
||||
- Description: Allows you to run commands once the proxy port mappings for an application have been updated. It also sends the invoking command. This can be "add", "clear" or "remove".
|
||||
- Description: Allows you to run commands once the proxy port mappings for an app have been updated. It also sends the invoking command. This can be "add", "clear" or "remove".
|
||||
- Invoked by: `dokku proxy:ports-add`, `dokku proxy:ports-clear`, `dokku proxy:ports-remove`
|
||||
- Arguments: `$APP` `action name`
|
||||
- Example:
|
||||
@@ -733,7 +733,7 @@ haproxy-build-config "$APP"
|
||||
|
||||
### `post-release-buildpack`
|
||||
|
||||
- Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using buildpacks.
|
||||
- Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to apps using buildpacks.
|
||||
- Invoked by: `internal function dokku_release() (release phase)`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -760,7 +760,7 @@ docker commit $ID $IMAGE > /dev/null
|
||||
|
||||
### `post-release-dockerfile`
|
||||
|
||||
- Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile.
|
||||
- Description: Allows you to run commands after environment variables are set for the release step of the deploy. Only applies to apps using a dockerfile.
|
||||
- Invoked by: `internal function dokku_release() (release phase)`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -778,14 +778,14 @@ verify_app_name "$APP"
|
||||
|
||||
### `post-stop`
|
||||
|
||||
- Description: Can be used to run commands after an application is manually stopped
|
||||
- Description: Can be used to run commands after an app is manually stopped
|
||||
- Invoked by: `dokku ps:stop` and `dokku ps:stopall`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
# Marks an application as manually stopped
|
||||
# Marks an app as manually stopped
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
@@ -796,7 +796,7 @@ dokku config:set --no-restart $APP MANUALLY_STOPPED=1
|
||||
|
||||
### `pre-build-buildpack`
|
||||
|
||||
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to applications using buildpacks.
|
||||
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to apps using buildpacks.
|
||||
- Invoked by: `internal function dokku_build() (build phase)`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
@@ -811,7 +811,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `pre-build-dockerfile`
|
||||
|
||||
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to applications using a dockerfile.
|
||||
- Description: Allows you to run commands before the build image is created for a given app. For instance, this can be useful to add env vars to your container. Only applies to apps using a dockerfile.
|
||||
- Invoked by: `internal function dokku_build() (build phase)`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
@@ -833,7 +833,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
# Clears out the gulp asset build cache for applications
|
||||
# Clears out the gulp asset build cache for apps
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
@@ -848,7 +848,7 @@ fi
|
||||
|
||||
### `pre-deploy`
|
||||
|
||||
- Description: Allows the running of code before the application's processes are scaled up and after the docker images are prepared.
|
||||
- Description: Allows the running of code before the app's processes are scaled up and after the docker images are prepared.
|
||||
- Invoked by: `dokku deploy`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -905,7 +905,7 @@ APP="$1"; verify_app_name "$APP"
|
||||
|
||||
### `pre-receive-app`
|
||||
|
||||
- Description: Allows you to customize the contents of an application directory before they are processed for deployment. The `IMAGE_SOURCE_TYPE` can be any of `[herokuish, dockerfile]`
|
||||
- Description: Allows you to customize the contents of an app directory before they are processed for deployment. The `IMAGE_SOURCE_TYPE` can be any of `[herokuish, dockerfile]`
|
||||
- Invoked by: `dokku git-hook`, `dokku tar-build-locked`
|
||||
- Arguments: `$APP $IMAGE_SOURCE_TYPE $TMP_WORK_DIR $REV`
|
||||
- Example:
|
||||
@@ -913,7 +913,7 @@ APP="$1"; verify_app_name "$APP"
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
# Adds a file called `dokku-is-awesome` to the repository
|
||||
# the contents will be the application name
|
||||
# the contents will be the app name
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
@@ -924,7 +924,7 @@ echo "$APP" > "$TMP_WORK_DIR/dokku-is-awesome"
|
||||
|
||||
### `pre-release-buildpack`
|
||||
|
||||
- Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using buildpacks.
|
||||
- Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to apps using buildpacks.
|
||||
- Invoked by: `internal function dokku_release() (release phase)`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -951,7 +951,7 @@ docker commit $ID $IMAGE > /dev/null
|
||||
|
||||
### `pre-release-dockerfile`
|
||||
|
||||
- Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to applications using a dockerfile.
|
||||
- Description: Allows you to run commands before environment variables are set for the release step of the deploy. Only applies to apps using a dockerfile.
|
||||
- Invoked by: `internal function dokku_release() (release phase)`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
@@ -967,16 +967,32 @@ verify_app_name "$APP"
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `pre-restore`
|
||||
|
||||
- Description: Allows you to run commands before all containers are restored
|
||||
- Invoked by: `dokku ps:restore`
|
||||
- Arguments: `$DOKKU_SCHEDULER`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
DOKKU_SCHEDULER="$1"
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `pre-start`
|
||||
|
||||
- Description: Can be used to run commands before an application is started
|
||||
- Description: Can be used to run commands before an app is started
|
||||
- Invoked by: `dokku ps:start`
|
||||
- Arguments: `$APP`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
# Notifies an example url that an application is starting
|
||||
# Notifies an example url that an app is starting
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
@@ -1032,7 +1048,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
### `receive-app`
|
||||
|
||||
- Description: Allows you to customize what occurs when an app is received. Normally just triggers an application build.
|
||||
- Description: Allows you to customize what occurs when an app is received. Normally just triggers an app build.
|
||||
- Invoked by: `dokku git-hook`, `dokku ps:rebuild`
|
||||
- Arguments: `$APP $REV` (`$REV` may not be included in cases where a repository is not pushed)
|
||||
- Example:
|
||||
@@ -1089,16 +1105,112 @@ APP="$1"; HOSTNAME=$(hostname -s)
|
||||
mail -s "$APP containers on $HOSTNAME failed to retire" ops@example.com
|
||||
```
|
||||
|
||||
### `scheduler-deploy`
|
||||
|
||||
- Description: Allows you to run scheduler commands when an app is deployed
|
||||
- Invoked by: `dokku deploy`
|
||||
- Arguments: `$DOKKU_SCHEDULER APP IMAGE_TAG`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
DOKKU_SCHEDULER="$1"; APP="$2"; IMAGE_TAG="$3";
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `scheduler-docker-cleanup`
|
||||
|
||||
- Description: Allows you to run scheduler commands when dokku cleanup is invoked
|
||||
- Invoked by: `dokku deploy, dokku cleanup`
|
||||
- Arguments: `$DOKKU_SCHEDULER APP FORCE_CLEANUP`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
DOKKU_SCHEDULER="$1"; APP="$2"; FORCE_CLEANUP="$3";
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `scheduler-run`
|
||||
|
||||
- Description: Allows you to run scheduler commands when a command is executed for your app
|
||||
- Invoked by: `dokku run`
|
||||
- Arguments: `$DOKKU_SCHEDULER APP ...ARGS`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
DOKKU_SCHEDULER="$1"; APP="$2"; ARGS="${@:3}";
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `scheduler-stop`
|
||||
|
||||
- Description: Allows you to run scheduler commands when a tag is destroyed
|
||||
- Invoked by: `dokku apps:destroy, dokku ps:stop`
|
||||
- Arguments: `$DOKKU_SCHEDULER APP REMOVE_CONTAINERS`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
DOKKU_SCHEDULER="$1"; APP="$2"; REMOVE_CONTAINERS="$3";
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `scheduler-tags-create`
|
||||
|
||||
- Description: Allows you to run scheduler commands when a tag is created
|
||||
- Invoked by: `dokku tags:create`
|
||||
- Arguments: `$DOKKU_SCHEDULER APP SOURCE_IMAGE TARGET_IMAGE`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
DOKKU_SCHEDULER="$1" APP="$2" SOURCE_IMAGE="$3" TARGET_IMAGE="$4"
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `scheduler-tags-destroy`
|
||||
|
||||
- Description: Allows you to run scheduler commands when a tag is destroyed
|
||||
- Invoked by: `dokku tags:destroy`
|
||||
- Arguments: `$DOKKU_SCHEDULER APP IMAGE_REPO IMAGE_TAG`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
DOKKU_SCHEDULER="$1"; APP="$2"; IMAGE_REPO="$3"; IMAGE_TAG="$4";
|
||||
|
||||
# TODO
|
||||
```
|
||||
|
||||
### `tags-create`
|
||||
|
||||
- Description: Allows you to run commands once a tag for an application image has been added
|
||||
- Description: Allows you to run commands once a tag for an app image has been added
|
||||
- Invoked by: `dokku tags:create`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
|
||||
```shell
|
||||
#!/usr/bin/env bash
|
||||
# Upload an application image to docker hub
|
||||
# Upload an app image to docker hub
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
|
||||
@@ -1110,7 +1222,7 @@ docker push $DOCKER_HUB_USER/$APP:$IMAGE_TAG
|
||||
|
||||
### `tags-destroy`
|
||||
|
||||
- Description: Allows you to run commands once a tag for an application image has been removed
|
||||
- Description: Allows you to run commands once a tag for an app image has been removed
|
||||
- Invoked by: `dokku tags:destroy`
|
||||
- Arguments: `$APP $IMAGE_TAG`
|
||||
- Example:
|
||||
|
||||
@@ -158,6 +158,10 @@
|
||||
<a href="/{{NAME}}/advanced-usage/plugin-management/" class="list-group-item">Plugin Management</a>
|
||||
<a href="/{{NAME}}/advanced-usage/repository-management/" class="list-group-item">Repository Management</a>
|
||||
|
||||
<a href="#" class="list-group-item disabled">Schedulers</a>
|
||||
|
||||
<a href="/{{NAME}}/advanced-usage/schedulers/docker-local/" class="list-group-item">Docker Local</a>
|
||||
|
||||
<a href="#" class="list-group-item disabled">Development</a>
|
||||
|
||||
<a href="/{{NAME}}/development/plugin-creation/" class="list-group-item">Plugin Creation</a>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
cleanup_container_state() {
|
||||
declare desc="core post-deploy state cleanup"
|
||||
local trigger="core-post-deploy cleanup_container_state"
|
||||
local APP="$1"; local PROCTYPES="$(egrep -v "^#" "$DOKKU_ROOT/$APP/DOKKU_SCALE" | awk -F '=' '{ print $1 }' | xargs)"
|
||||
local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 3 -n | xargs)"
|
||||
|
||||
local CONTAINER_FILE
|
||||
for CONTAINER_FILE in $CONTAINER_FILES; do
|
||||
local CONTAINER_TYPE="$(awk -F '.' '{ print $2 }' <<< "$CONTAINER_FILE")"
|
||||
if [[ "$(is_val_in_list "$CONTAINER_TYPE" "$PROCTYPES" " ")" == "false" ]]; then
|
||||
dokku_log_info1 "Container type ($CONTAINER_TYPE) is no longer defined. Removing state"
|
||||
local IP_FILE="${CONTAINER_FILE//CONTAINER/IP}"
|
||||
local PORT_FILE="${CONTAINER_FILE//CONTAINER/PORT}"
|
||||
rm -f "$DOKKU_ROOT/$APP/$CONTAINER_FILE" "$DOKKU_ROOT/$APP/$IP_FILE" "$DOKKU_ROOT/$APP/$PORT_FILE"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
cleanup_container_state "$@"
|
||||
@@ -2,7 +2,6 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/00_dokku-standard/exec-app-json-scripts"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
exec_app_json_scripts() {
|
||||
declare desc="core app.json scripts execution"
|
||||
@@ -13,32 +12,4 @@ exec_app_json_scripts() {
|
||||
execute_script "$APP" "$IMAGE_TAG" "$PHASE_SCRIPT_KEY"
|
||||
}
|
||||
|
||||
app_user_pre_deploy_trigger() {
|
||||
local desc="app user pre-deploy trigger"
|
||||
local APP="$1"; local IMAGE_TAG="$2"; local IMAGE; local DOCKER_ARGS
|
||||
local DOKKU_APP_TYPE DOKKU_APP_USER APP_PATHS CONTAINER_PATHS
|
||||
declare -a ARG_ARRAY
|
||||
|
||||
IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
|
||||
|
||||
DOKKU_APP_TYPE=$(config_get "$APP" DOKKU_APP_TYPE || true)
|
||||
DOKKU_APP_USER=$(config_get "$APP" DOKKU_APP_USER || true)
|
||||
DOKKU_APP_USER=${DOKKU_APP_USER:="herokuishuser"}
|
||||
APP_PATHS=$(dokku --quiet storage:list "$APP" || true)
|
||||
|
||||
if [[ -n "$APP_PATHS" ]]; then
|
||||
CONTAINER_PATHS=$(echo "$APP_PATHS" | awk -F ':' '{ print $2 }' | xargs)
|
||||
DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG")
|
||||
# strip --restart args from DOCKER_ARGS
|
||||
DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<< "$DOCKER_ARGS")
|
||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||
fi
|
||||
|
||||
if [[ "$DOKKU_APP_TYPE" == "herokuish" ]] && [[ -n "$CONTAINER_PATHS" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
docker run $DOKKU_GLOBAL_RUN_ARGS "${ARG_ARRAY[@]}" $IMAGE /bin/bash -c "find $CONTAINER_PATHS -not -user $DOKKU_APP_USER -print0 | xargs -0 -r chown -R $DOKKU_APP_USER" || true
|
||||
fi
|
||||
}
|
||||
|
||||
exec_app_json_scripts "$@"
|
||||
app_user_pre_deploy_trigger "$@"
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
dokku_cleanup_cmd(){
|
||||
dokku_cleanup_cmd() {
|
||||
declare desc="cleans up old deployment cruft"
|
||||
local cmd="cleanup"
|
||||
declare cmd="cleanup"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
declare APP="$1"
|
||||
|
||||
docker_cleanup "$APP" "true"
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
dokku_ls_cmd() {
|
||||
declare desc="lists installed apps with status"
|
||||
local cmd="ls"
|
||||
local installed_apps=$(dokku_apps)
|
||||
local dokku_app
|
||||
|
||||
dokku_col_log_info1_quiet "App Name" "Container Type" "Container Id" "Status"
|
||||
|
||||
for dokku_app in $installed_apps; do
|
||||
local APP=$(basename "$dokku_app")
|
||||
local DOKKU_APP_CIDS=$(get_app_container_ids "$APP")
|
||||
local DOCKER_RUNNING_CONTAINERS=$(docker ps -q --no-trunc)
|
||||
if [[ -n $DOKKU_APP_CIDS ]]; then
|
||||
local DOKKU_APP_CID
|
||||
for DOKKU_APP_CID in $DOKKU_APP_CIDS; do
|
||||
local DOKKU_APP_CONTAINER_STATUS="stopped"
|
||||
[[ $DOCKER_RUNNING_CONTAINERS =~ $DOKKU_APP_CID ]] && local DOKKU_APP_CONTAINER_STATUS="running"
|
||||
local DOKKU_APP_CONTAINER_TYPE=$(grep -l "$DOKKU_APP_CID" "$DOKKU_ROOT/$APP"/CONTAINER.* | awk -F '/' '{ print $5 }' | awk -F '.' '{ print $2 }')
|
||||
dokku_col_log_msg "$APP" "$DOKKU_APP_CONTAINER_TYPE" "${DOKKU_APP_CID:0:12}" "$DOKKU_APP_CONTAINER_STATUS"
|
||||
done
|
||||
else
|
||||
dokku_col_log_msg "$APP" "NOT_DEPLOYED" "NOT_DEPLOYED" "NOT_DEPLOYED"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
dokku_ls_cmd "$@"
|
||||
@@ -1,53 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
dokku_run_cmd() {
|
||||
declare desc="runs command in container based on app image"
|
||||
local cmd="run"
|
||||
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
local APP="$2"; local IMAGE_TAG=$(get_running_image_tag "$APP"); local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
||||
declare cmd="run" APP="$2"
|
||||
verify_app_name "$APP"
|
||||
|
||||
shift 2
|
||||
|
||||
if [[ -z "$DOKKU_RM_CONTAINER" ]]; then
|
||||
local DOKKU_APP_RM_CONTAINER=$(config_get "$APP" DOKKU_RM_CONTAINER || true)
|
||||
local DOKKU_GLOBAL_RM_CONTAINER=$(config_get --global DOKKU_RM_CONTAINER || true)
|
||||
local DOKKU_RM_CONTAINER=${DOKKU_APP_RM_CONTAINER:="$DOKKU_GLOBAL_RM_CONTAINER"}
|
||||
fi
|
||||
|
||||
local DOCKER_ARGS=$(: | plugn trigger docker-args-run "$APP" "$IMAGE_TAG")
|
||||
[[ "$DOKKU_TRACE" ]] && local DOCKER_ARGS+=" -e TRACE=true "
|
||||
|
||||
declare -a ARG_ARRAY
|
||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||
|
||||
local DOKKU_RUN_OPTS=" -e DYNO=run.$RANDOM"
|
||||
if [[ "$DOKKU_RM_CONTAINER" ]]; then
|
||||
DOKKU_RUN_OPTS+=" --rm"
|
||||
elif [[ "$DOKKU_DETACH_CONTAINER" ]]; then
|
||||
DOKKU_RUN_OPTS+=" --detach"
|
||||
fi
|
||||
|
||||
has_tty && DOKKU_RUN_OPTS+=" -i -t"
|
||||
is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec"
|
||||
|
||||
DOKKU_QUIET_OUTPUT=1 extract_procfile "$APP"
|
||||
|
||||
POTENTIAL_PROCFILE_KEY="$1"
|
||||
PROC_CMD=$(get_cmd_from_procfile "$APP" "$POTENTIAL_PROCFILE_KEY" || echo '')
|
||||
remove_procfile "$APP"
|
||||
|
||||
if [ ! -z "$PROC_CMD" ]; then
|
||||
dokku_log_info1 "Found '$POTENTIAL_PROCFILE_KEY' in Procfile, running that command"
|
||||
set -- "$PROC_CMD" "${@:2}"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
docker run $DOKKU_GLOBAL_RUN_ARGS $DOKKU_RUN_OPTS "${ARG_ARRAY[@]}" $IMAGE $EXEC_CMD "$@"
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
plugn trigger scheduler-run "$DOKKU_SCHEDULER" "$APP" "$@"
|
||||
}
|
||||
|
||||
dokku_run_cmd "$@"
|
||||
|
||||
1
plugins/20_events/pre-restore
Symbolic link
1
plugins/20_events/pre-restore
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/20_events/scheduler-deploy
Symbolic link
1
plugins/20_events/scheduler-deploy
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/20_events/scheduler-docker-cleanup
Symbolic link
1
plugins/20_events/scheduler-docker-cleanup
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/20_events/scheduler-run
Symbolic link
1
plugins/20_events/scheduler-run
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/20_events/scheduler-stop
Symbolic link
1
plugins/20_events/scheduler-stop
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/20_events/scheduler-tags-create
Symbolic link
1
plugins/20_events/scheduler-tags-create
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/20_events/scheduler-tags-destroy
Symbolic link
1
plugins/20_events/scheduler-tags-destroy
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
@@ -32,21 +32,11 @@ apps_destroy() {
|
||||
fi
|
||||
|
||||
echo "Destroying $APP (including all add-ons)"
|
||||
|
||||
plugn trigger pre-delete "$APP" "$IMAGE_TAG"
|
||||
local DOKKU_APP_CIDS=$(get_app_container_ids "$APP")
|
||||
local DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
|
||||
[[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
|
||||
|
||||
if [[ -n $DOKKU_APP_CIDS ]]; then
|
||||
local cid
|
||||
for cid in $DOKKU_APP_CIDS; do
|
||||
# shellcheck disable=SC2086
|
||||
docker stop $DOCKER_STOP_TIME_ARG "$cid" > /dev/null || true
|
||||
docker rm "$cid" > /dev/null || true
|
||||
done
|
||||
fi
|
||||
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
local REMOVE_CONTAINERS="true"
|
||||
plugn trigger scheduler-stop "$DOKKU_SCHEDULER" "$APP" "$REMOVE_CONTAINERS"
|
||||
plugn trigger post-delete "$APP" "$IMAGE_TAG"
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,6 @@ app_post_delete() {
|
||||
rm -rf "${DOKKU_ROOT:?}/$APP" > /dev/null
|
||||
fi
|
||||
|
||||
# remove all application containers & images
|
||||
# shellcheck disable=SC2046
|
||||
docker rm -f $(docker ps -a --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs) &>/dev/null || true
|
||||
# shellcheck disable=SC2046
|
||||
docker rmi $(docker images -q "$IMAGE_REPO" | xargs) &>/dev/null || true
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName st
|
||||
|
||||
imageName = fmt.Sprintf("%s%s:%s", imageRemoteRepository, imageRepo, imageTag)
|
||||
if !VerifyImage(imageName) {
|
||||
LogFail(fmt.Sprintf("app image (%s) not found", imageName))
|
||||
LogFail(fmt.Sprintf("App image (%s) not found", imageName))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -221,7 +221,7 @@ func GetAppImageName(appName, imageTag, imageRepo string) (imageName string) {
|
||||
} else {
|
||||
imageName = fmt.Sprintf("%v:%v", imageRepo, imageTag)
|
||||
if !VerifyImage(imageName) {
|
||||
LogFail(fmt.Sprintf("app image (%s) not found", imageName))
|
||||
LogFail(fmt.Sprintf("App image (%s) not found", imageName))
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@@ -192,7 +192,7 @@ get_deploying_app_image_name() {
|
||||
[[ -z "$IMAGE_TAG" ]] && IMAGE_TAG="latest"
|
||||
|
||||
local IMAGE="${IMAGE_REMOTE_REPOSITORY}${IMAGE_REPO}:${IMAGE_TAG}"
|
||||
verify_image "$IMAGE" || dokku_log_fail "app image ($IMAGE) not found"
|
||||
verify_image "$IMAGE" || dokku_log_fail "App image ($IMAGE) not found"
|
||||
echo "$IMAGE"
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ get_app_image_name() {
|
||||
|
||||
if [[ -n "$IMAGE_TAG" ]]; then
|
||||
local IMAGE="$IMAGE_REPO:$IMAGE_TAG"
|
||||
verify_image "$IMAGE" || dokku_log_fail "app image ($IMAGE) not found"
|
||||
verify_image "$IMAGE" || dokku_log_fail "App image ($IMAGE) not found"
|
||||
else
|
||||
local IMAGE="$IMAGE_REPO:latest"
|
||||
fi
|
||||
@@ -347,8 +347,7 @@ get_app_running_container_ids() {
|
||||
CIDS=$(get_app_container_ids "$APP" "$CONTAINER_TYPE")
|
||||
|
||||
for CID in $CIDS; do
|
||||
local APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" 2>/dev/null || true)
|
||||
[[ "$APP_CONTAINER_STATUS" == "true" ]] && local APP_RUNNING_CONTAINER_IDS+="$CID "
|
||||
(is_container_status "$CID" "Running") && local APP_RUNNING_CONTAINER_IDS+="$CID "
|
||||
done
|
||||
|
||||
echo "$APP_RUNNING_CONTAINER_IDS"
|
||||
@@ -399,23 +398,11 @@ is_deployed() {
|
||||
fi
|
||||
}
|
||||
|
||||
is_container_running() {
|
||||
declare desc="return 0 if given docker container id is in running state"
|
||||
local CID=$1
|
||||
local CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" || true)
|
||||
|
||||
if [[ "$CONTAINER_STATUS" == "true" ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_container_status() {
|
||||
declare desc="return 0 if given docker container id is in given state"
|
||||
local CID=$1
|
||||
local TEMPLATE="{{.State.$2}}"
|
||||
local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" || true)
|
||||
local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" 2> /dev/null || true)
|
||||
|
||||
if [[ "$CONTAINER_STATUS" == "true" ]]; then
|
||||
return 0
|
||||
@@ -542,170 +529,10 @@ dokku_release() {
|
||||
|
||||
dokku_deploy_cmd() {
|
||||
declare desc="deploy phase"
|
||||
local cmd="deploy"
|
||||
source "$PLUGIN_AVAILABLE_PATH/checks/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
declare APP="$1" IMAGE_TAG="$2"
|
||||
|
||||
[[ -z $1 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
local APP="$1" IMAGE_TAG="$2"
|
||||
local DOKKU_DOCKER_STOP_TIMEOUT DOKKU_HEROKUISH DOKKU_NETWORK_BIND_ALL IMAGE
|
||||
DOKKU_HEROKUISH=false
|
||||
IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
||||
verify_app_name "$APP"
|
||||
plugn trigger pre-deploy "$APP" "$IMAGE_TAG"
|
||||
|
||||
is_image_herokuish_based "$IMAGE" && DOKKU_HEROKUISH=true
|
||||
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
local oldids=$(get_app_container_ids "$APP")
|
||||
|
||||
DOKKU_NETWORK_BIND_ALL="$(plugn trigger network-get-property "$APP" bind-all-interfaces)"
|
||||
DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
|
||||
[[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
|
||||
|
||||
local line; local PROC_TYPE; local PROC_COUNT; local CONTAINER_INDEX
|
||||
while read -r line || [[ -n "$line" ]]; do
|
||||
[[ "$line" =~ ^#.* ]] && continue
|
||||
line="$(strip_inline_comments "$line")"
|
||||
PROC_TYPE=${line%%=*}
|
||||
PROC_COUNT=${line#*=}
|
||||
CONTAINER_INDEX=1
|
||||
|
||||
if [[ "$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" == "true" ]]; then
|
||||
dokku_log_info1 "zero downtime is disabled for app ($APP.$PROC_TYPE). stopping currently running containers"
|
||||
local cid proctype_oldids="$(get_app_running_container_ids "$APP" "$PROC_TYPE")"
|
||||
for cid in $proctype_oldids; do
|
||||
dokku_log_info2 "stopping $APP.$PROC_TYPE ($cid)"
|
||||
# shellcheck disable=SC2086
|
||||
docker stop $DOCKER_STOP_TIME_ARG "$cid" &> /dev/null
|
||||
# remove cid from oldids to skip the old container finish processing
|
||||
oldids="$(remove_val_from_list "$cid" "$oldids" " ")"
|
||||
done
|
||||
fi
|
||||
|
||||
while [[ $CONTAINER_INDEX -le $PROC_COUNT ]]; do
|
||||
local cid=""; local port=""; local ipaddr=""
|
||||
local DOKKU_CONTAINER_ID_FILE="$DOKKU_ROOT/$APP/CONTAINER.$PROC_TYPE.$CONTAINER_INDEX"
|
||||
|
||||
# start the app
|
||||
local DOCKER_ARGS
|
||||
DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG" "$PROC_TYPE" "$CONTAINER_INDEX")
|
||||
DOCKER_ARGS+=" -e DYNO=$PROC_TYPE.$CONTAINER_INDEX "
|
||||
[[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true "
|
||||
|
||||
declare -a ARG_ARRAY
|
||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||
|
||||
[[ "$DOKKU_HEROKUISH" == "true" ]] && local START_CMD="/start $PROC_TYPE"
|
||||
|
||||
if [[ "$DOKKU_HEROKUISH" == "false" ]]; then
|
||||
local DOKKU_DOCKERFILE_START_CMD=$(config_get "$APP" DOKKU_DOCKERFILE_START_CMD || true)
|
||||
local DOKKU_PROCFILE_START_CMD=$(get_cmd_from_procfile "$APP" "$PROC_TYPE")
|
||||
local START_CMD=${DOKKU_DOCKERFILE_START_CMD:-$DOKKU_PROCFILE_START_CMD}
|
||||
fi
|
||||
|
||||
if [[ "$PROC_TYPE" == "web" ]]; then
|
||||
ports=($(plugn trigger network-compute-ports "$APP" "$PROC_TYPE" "$DOKKU_HEROKUISH"))
|
||||
local DOKKU_DOCKER_PORT_ARGS=""
|
||||
local DOKKU_PORT=""
|
||||
for p in "${ports[@]}"; do
|
||||
if [[ ! "$p" =~ .*udp.* ]]; then
|
||||
DOKKU_PORT=${DOKKU_PORT:="$p"}
|
||||
fi
|
||||
DOKKU_DOCKER_PORT_ARGS+=" -p $p "
|
||||
done
|
||||
|
||||
if [[ "$DOKKU_NETWORK_BIND_ALL" == "false" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $DOKKU_DOCKER_PORT_ARGS -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
|
||||
fi
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
|
||||
fi
|
||||
|
||||
ipaddr=$(plugn trigger network-get-ipaddr "$APP" "$PROC_TYPE" "$cid")
|
||||
port=$(plugn trigger network-get-port "$APP" "$PROC_TYPE" "$DOKKU_HEROKUISH" "$cid")
|
||||
|
||||
kill_new() {
|
||||
declare desc="wrapper function to kill newly started app container"
|
||||
local cid="$1"
|
||||
docker inspect "$cid" &> /dev/null && docker stop "$cid" > /dev/null && docker kill "$cid" &> /dev/null
|
||||
trap - INT TERM EXIT
|
||||
kill -9 $$
|
||||
}
|
||||
|
||||
# run checks first, then post-deploy hooks, which switches proxy traffic
|
||||
trap 'kill_new $cid' INT TERM EXIT
|
||||
if [[ "$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" == "false" ]]; then
|
||||
dokku_log_info1 "Attempting pre-flight checks"
|
||||
plugn trigger check-deploy "$APP" "$cid" "$PROC_TYPE" "$port" "$ipaddr"
|
||||
fi
|
||||
trap - INT TERM EXIT
|
||||
|
||||
# now using the new container
|
||||
[[ -n "$cid" ]] && echo "$cid" > "$DOKKU_CONTAINER_ID_FILE"
|
||||
[[ -n "$ipaddr" ]] && plugn trigger network-write-ipaddr "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$ipaddr"
|
||||
[[ -n "$port" ]] && plugn trigger network-write-port "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$port"
|
||||
|
||||
# cleanup pre-migration files
|
||||
rm -f "$DOKKU_ROOT/$APP/CONTAINER" "$DOKKU_ROOT/$APP/IP" "$DOKKU_ROOT/$APP/PORT"
|
||||
|
||||
local CONTAINER_INDEX=$(( CONTAINER_INDEX + 1 ))
|
||||
done
|
||||
# cleanup when we scale down
|
||||
if [[ "$PROC_COUNT" == 0 ]]; then
|
||||
local CONTAINER_IDX_OFFSET=0
|
||||
else
|
||||
local CONTAINER_IDX_OFFSET=$((PROC_COUNT + 1))
|
||||
fi
|
||||
local container_state_filetype
|
||||
for container_state_filetype in CONTAINER IP PORT; do
|
||||
cd "$DOKKU_ROOT/$APP"
|
||||
find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f
|
||||
done
|
||||
done < "$DOKKU_SCALE_FILE"
|
||||
|
||||
dokku_log_info1 "Running post-deploy"
|
||||
plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
|
||||
plugn trigger post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
|
||||
|
||||
# kill the old container
|
||||
if [[ -n "$oldids" ]]; then
|
||||
|
||||
if [[ -z "$DOKKU_WAIT_TO_RETIRE" ]]; then
|
||||
local DOKKU_APP_DOKKU_WAIT_TO_RETIRE=$(config_get "$APP" DOKKU_WAIT_TO_RETIRE || true)
|
||||
local DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE=$(config_get --global DOKKU_WAIT_TO_RETIRE || true)
|
||||
local DOKKU_WAIT_TO_RETIRE=${DOKKU_APP_DOKKU_WAIT_TO_RETIRE:="$DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE"}
|
||||
fi
|
||||
|
||||
# Let the old container finish processing requests, before terminating it
|
||||
local WAIT="${DOKKU_WAIT_TO_RETIRE:-60}"
|
||||
dokku_log_info1 "Shutting down old containers in $WAIT seconds"
|
||||
local oldid
|
||||
for oldid in $oldids; do
|
||||
dokku_log_info2 "$oldid"
|
||||
done
|
||||
(
|
||||
exec >/dev/null 2>/dev/null </dev/null
|
||||
trap '' INT HUP
|
||||
sleep "$WAIT"
|
||||
for oldid in $oldids; do
|
||||
# Attempt to stop, if that fails, then force a kill as docker seems
|
||||
# to not send SIGKILL as the docs would indicate. If that fails, move
|
||||
# on to the next.
|
||||
# shellcheck disable=SC2086
|
||||
docker stop $DOCKER_STOP_TIME_ARG "$oldid" \
|
||||
|| docker kill "$oldid" \
|
||||
|| plugn trigger retire-container-failed "$APP" # plugin trigger for event logging
|
||||
done
|
||||
) & disown -a
|
||||
# Use trap since disown/nohup don't seem to keep child alive
|
||||
# Give child process just enough time to set the traps
|
||||
sleep 0.1
|
||||
fi
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
plugn trigger scheduler-deploy "$DOKKU_SCHEDULER" "$APP" "$IMAGE_TAG"
|
||||
}
|
||||
|
||||
release_and_deploy() {
|
||||
@@ -767,6 +594,7 @@ docker_cleanup() {
|
||||
declare desc="cleans up all exited/dead containers and removes all dangling images"
|
||||
declare APP="$1" FORCE_CLEANUP="$2"
|
||||
local DOKKU_APP_SKIP_CLEANUP
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
if [[ "$FORCE_CLEANUP" != "true" ]]; then
|
||||
[[ -z "$APP" ]] && DOKKU_APP_SKIP_CLEANUP="$(config_get "$APP" DOKKU_SKIP_CLEANUP || true)"
|
||||
@@ -777,6 +605,9 @@ docker_cleanup() {
|
||||
fi
|
||||
|
||||
dokku_log_info1 "Cleaning up..."
|
||||
local DOKKU_SCHEDULER="docker-local"
|
||||
[[ -n "$APP" ]] && DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
plugn trigger scheduler-docker-cleanup "$DOKKU_SCHEDULER" "$APP" "$FORCE_CLEANUP"
|
||||
|
||||
# delete all non-running containers
|
||||
# shellcheck disable=SC2046
|
||||
|
||||
@@ -45,8 +45,7 @@ enter_default_cmd() {
|
||||
fi
|
||||
fi
|
||||
|
||||
docker inspect "$ID" &> /dev/null || dokku_log_fail "Container does not exist"
|
||||
docker inspect -f '{{ .State.Running }}' "$ID" | grep -q "true" > /dev/null || dokku_log_fail "Container is not running"
|
||||
(is_container_status "$ID" "Running") || dokku_log_fail "Container is not running"
|
||||
|
||||
local DOKKU_APP_SHELL="/bin/bash"
|
||||
DOKKU_APP_SHELL="$(config_get --global DOKKU_APP_SHELL || echo "$DOKKU_APP_SHELL")"
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
[plugin]
|
||||
description = "dokku core named containers plugin"
|
||||
version = "0.11.6"
|
||||
[plugin.config]
|
||||
@@ -108,21 +108,13 @@ ps_start() {
|
||||
ps_stop() {
|
||||
declare desc="stops app"
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids "$APP")
|
||||
|
||||
! (is_deployed "$APP") && echo "App $APP has not been deployed" && exit 0
|
||||
|
||||
if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then
|
||||
local DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
|
||||
[[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
|
||||
|
||||
echo "Stopping $APP ..."
|
||||
# shellcheck disable=SC2086
|
||||
docker stop $DOCKER_STOP_TIME_ARG $DOKKU_APP_RUNNING_CONTAINER_IDS > /dev/null || true
|
||||
plugn trigger post-stop "$APP"
|
||||
else
|
||||
echo "App $APP already stopped"
|
||||
fi
|
||||
echo "Stopping $APP ..."
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
plugn trigger scheduler-stop "$DOKKU_SCHEDULER" "$APP"
|
||||
plugn trigger post-stop "$APP"
|
||||
}
|
||||
|
||||
ps_rebuild() {
|
||||
|
||||
@@ -13,8 +13,11 @@ report_single_app() {
|
||||
local APP_CIDS=$(get_app_container_ids "$APP"); local PROCS=0; local RUNNING=""
|
||||
|
||||
for CID in $APP_CIDS; do
|
||||
local APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" 2>/dev/null || true)
|
||||
if [[ "$APP_CONTAINER_STATUS" == "true" ]]; then RUNNING+="0"; else RUNNING+="1"; fi
|
||||
if (is_container_status "$CID" "Running"); then
|
||||
RUNNING+="0"
|
||||
else
|
||||
RUNNING+="1"
|
||||
fi
|
||||
PROCS=$((PROCS + 1))
|
||||
done
|
||||
|
||||
@@ -37,8 +40,8 @@ report_single_app() {
|
||||
local APP_CONTAINER_STATUS
|
||||
for CONTAINER_FILE in $CONTAINER_FILES; do
|
||||
CID=$(< "$DOKKU_ROOT/$APP/$CONTAINER_FILE")
|
||||
APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' "$CID" 2> /dev/null)
|
||||
[[ -z "$APP_CONTAINER_STATUS" ]] && APP_CONTAINER_STATUS="dead"
|
||||
APP_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' "$CID" 2> /dev/null || true)
|
||||
[[ -z "$APP_CONTAINER_STATUS" ]] && APP_CONTAINER_STATUS="missing"
|
||||
STATUSES+=("${CONTAINER_FILE#*.}:$APP_CONTAINER_STATUS#${CID:0:12}")
|
||||
done
|
||||
local flag_map=(
|
||||
|
||||
@@ -9,6 +9,9 @@ ps_restore_cmd() {
|
||||
local cmd="ps:restore"
|
||||
local APP="$2"
|
||||
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
plugn trigger pre-restore "$DOKKU_SCHEDULER"
|
||||
|
||||
if [[ -n "$APP" ]]; then
|
||||
if ! (is_deployed "$APP"); then
|
||||
dokku_log_warn "App $APP has not been deployed"
|
||||
|
||||
@@ -38,10 +38,16 @@ source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/checks/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
checks_check_deploy() {
|
||||
declare desc="checks check-deploy plugin trigger"
|
||||
local trigger="checks_check_deploy"
|
||||
scheduler-docker-local-check-deploy() {
|
||||
declare desc="scheduler-docker-local check-deploy plugin trigger"
|
||||
local trigger="scheduler-docker-local-check-deploy"
|
||||
local APP="$1"; local DOKKU_APP_CONTAINER_ID="$2"; local DOKKU_APP_CONTAINER_TYPE="$3"; local DOKKU_APP_LISTEN_PORT="$4"; local DOKKU_APP_LISTEN_IP="$5"
|
||||
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -z "$DOKKU_APP_LISTEN_PORT" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT" ]]; then
|
||||
local DOKKU_APP_LISTEN_PORT=$(< "$DOKKU_ROOT/$APP/PORT")
|
||||
fi
|
||||
@@ -107,7 +113,7 @@ checks_check_deploy() {
|
||||
dokku_log_info1 "Waiting for $DOKKU_DEFAULT_CHECKS_WAIT seconds ..."
|
||||
sleep "$DOKKU_DEFAULT_CHECKS_WAIT"
|
||||
|
||||
! (is_container_running "$DOKKU_APP_CONTAINER_ID") && dokku_log_fail "App container failed to start!!"
|
||||
! (is_container_status "$DOKKU_APP_CONTAINER_ID" "Running") && dokku_log_fail "App container failed to start!!"
|
||||
local container_restarts="$(docker inspect -f "{{ .RestartCount }}" "$DOKKU_APP_CONTAINER_ID")"
|
||||
if [[ $container_restarts -ne 0 ]]; then
|
||||
docker stop "$DOKKU_APP_CONTAINER_ID" || true
|
||||
@@ -236,4 +242,4 @@ checks_check_deploy() {
|
||||
dokku_log_info1 "All checks successful!"
|
||||
}
|
||||
|
||||
checks_check_deploy "$@"
|
||||
scheduler-docker-local-check-deploy "$@"
|
||||
@@ -1,18 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
named_containers_core_post_deploy() {
|
||||
declare desc="names deployed app container is consistent manner"
|
||||
local trigger="named_containers_core_post_deploy"
|
||||
local APP="$1"; local APP_ROOT="$DOKKU_ROOT/$APP"
|
||||
local container
|
||||
scheduler-docker-local-core-post-deploy() {
|
||||
declare desc="scheduler-docker-local core-post-deploy state cleanup"
|
||||
declare trigger="scheduler-docker-local core-post-deploy"
|
||||
declare APP="$1";
|
||||
local APP_ROOT="$DOKKU_ROOT/$APP"
|
||||
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local PROCTYPES="$(egrep -v "^#" "$DOKKU_ROOT/$APP/DOKKU_SCALE" | awk -F '=' '{ print $1 }' | xargs)"
|
||||
local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 3 -n | xargs)"
|
||||
|
||||
local CONTAINER_FILE
|
||||
for CONTAINER_FILE in $CONTAINER_FILES; do
|
||||
local CONTAINER_TYPE="$(awk -F '.' '{ print $2 }' <<< "$CONTAINER_FILE")"
|
||||
if [[ "$(is_val_in_list "$CONTAINER_TYPE" "$PROCTYPES" " ")" == "false" ]]; then
|
||||
dokku_log_info1 "Container type ($CONTAINER_TYPE) is no longer defined. Removing state"
|
||||
local IP_FILE="${CONTAINER_FILE//CONTAINER/IP}"
|
||||
local PORT_FILE="${CONTAINER_FILE//CONTAINER/PORT}"
|
||||
rm -f "$DOKKU_ROOT/$APP/$CONTAINER_FILE" "$DOKKU_ROOT/$APP/$IP_FILE" "$DOKKU_ROOT/$APP/$PORT_FILE"
|
||||
fi
|
||||
done
|
||||
|
||||
shopt -s nullglob
|
||||
local container
|
||||
for container in $APP_ROOT/CONTAINER.*; do
|
||||
local DYNO=$(echo "$container" | sed -r 's/.*CONTAINER\.(.*)/\1/') || true
|
||||
local NAME="$APP.$DYNO"
|
||||
local CURRENT_CONTAINER_ID="$(< "$container")"
|
||||
# TODO: Ensure these are from the current service
|
||||
local PREVIOUS_CIDS=$(docker ps -a -q -f name="^.?$NAME\$" | xargs) || true
|
||||
if [[ -n $PREVIOUS_CIDS ]]; then
|
||||
dokku_log_info1_quiet "Found previous container(s) ($PREVIOUS_CIDS) named $NAME"
|
||||
@@ -24,7 +46,7 @@ named_containers_core_post_deploy() {
|
||||
if [[ "$PREVIOUS_CONTAINER_STATUS" != "dead" ]]; then
|
||||
local CONTAINER_DATE_NAME="$NAME.$(date +%s)"
|
||||
dokku_log_info2_quiet "Renaming container ($cid) ${NAME} to $CONTAINER_DATE_NAME"
|
||||
docker rename "$NAME" "$CONTAINER_DATE_NAME" > /dev/null
|
||||
docker rename "$NAME" "$CONTAINER_DATE_NAME" > /dev/null 2>&1 || dokku_log_warn "Unable to rename container"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -38,4 +60,4 @@ named_containers_core_post_deploy() {
|
||||
shopt -u nullglob
|
||||
}
|
||||
|
||||
named_containers_core_post_deploy "$@"
|
||||
scheduler-docker-local-core-post-deploy "$@"
|
||||
4
plugins/scheduler-docker-local/plugin.toml
Normal file
4
plugins/scheduler-docker-local/plugin.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[plugin]
|
||||
description = "dokku core scheduler-docker-local plugin"
|
||||
version = "0.11.3"
|
||||
[plugin.config]
|
||||
30
plugins/scheduler-docker-local/post-delete
Executable file
30
plugins/scheduler-docker-local/post-delete
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
scheduler-docker-local-post-delete() {
|
||||
declare desc="scheduler-docker-local post-delete plugin trigger"
|
||||
declare trigger="scheduler-docker-local post-delete"
|
||||
declare APP="$1"
|
||||
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local IMAGE_REPO=$(get_app_image_repo "$APP")
|
||||
|
||||
# remove all application containers & images
|
||||
# shellcheck disable=SC2046
|
||||
local DOKKU_APP_CIDS=$(docker ps -a --no-trunc | egrep "dokku/${APP}:" | awk '{ print $1 }' | xargs)
|
||||
if [[ -n "$DOKKU_APP_CIDS" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
docker rm -f $DOKKU_APP_CIDS > /dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
docker rmi $(docker images -q "$IMAGE_REPO" | xargs) &>/dev/null || true
|
||||
}
|
||||
|
||||
scheduler-docker-local-post-delete "$@"
|
||||
39
plugins/scheduler-docker-local/pre-deploy
Executable file
39
plugins/scheduler-docker-local/pre-deploy
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
scheduler-docker-local-pre-deploy() {
|
||||
declare desc="scheduler-docker-local pre-deploy plugin trigger"
|
||||
declare trigger="scheduler-docker-local pre-deploy"
|
||||
declare APP="$1" IMAGE_TAG="$2"
|
||||
local IMAGE DOCKER_ARGS DOKKU_APP_TYPE DOKKU_APP_USER APP_PATHS CONTAINER_PATHS
|
||||
declare -a ARG_ARRAY
|
||||
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG")
|
||||
|
||||
DOKKU_APP_TYPE=$(config_get "$APP" DOKKU_APP_TYPE || true)
|
||||
DOKKU_APP_USER=$(config_get "$APP" DOKKU_APP_USER || true)
|
||||
DOKKU_APP_USER=${DOKKU_APP_USER:="herokuishuser"}
|
||||
APP_PATHS=$(dokku --quiet storage:list "$APP" || true)
|
||||
|
||||
if [[ -n "$APP_PATHS" ]]; then
|
||||
CONTAINER_PATHS=$(echo "$APP_PATHS" | awk -F ':' '{ print $2 }' | xargs)
|
||||
DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG")
|
||||
# strip --restart args from DOCKER_ARGS
|
||||
DOCKER_ARGS=$(sed -e "s/--restart=[[:graph:]]\+[[:blank:]]\?//g" <<< "$DOCKER_ARGS")
|
||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||
fi
|
||||
|
||||
if [[ "$DOKKU_APP_TYPE" == "herokuish" ]] && [[ -n "$CONTAINER_PATHS" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
docker run $DOKKU_GLOBAL_RUN_ARGS "${ARG_ARRAY[@]}" $IMAGE /bin/bash -c "find $CONTAINER_PATHS -not -user $DOKKU_APP_USER -print0 | xargs -0 -r chown -R $DOKKU_APP_USER" || true
|
||||
fi
|
||||
}
|
||||
|
||||
scheduler-docker-local-pre-deploy "$@"
|
||||
19
plugins/scheduler-docker-local/pre-restore
Executable file
19
plugins/scheduler-docker-local/pre-restore
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
scheduler-docker-local-pre-restore() {
|
||||
declare desc="scheduler-docker-local pre-restore plugin trigger"
|
||||
declare trigger="scheduler-docker-local pre-restore"
|
||||
declare DOKKU_SCHEDULER="$1"
|
||||
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# delete all "old" containers
|
||||
# shellcheck disable=SC2046
|
||||
docker rm $(docker ps --format "{{.Names}}" -a -f "label=$DOKKU_CONTAINER_LABEL" -q | grep -E '(.+\..+\.[0-9]+\.[0-9]+$)') &> /dev/null || true
|
||||
}
|
||||
|
||||
scheduler-docker-local-pre-restore "$@"
|
||||
176
plugins/scheduler-docker-local/scheduler-deploy
Executable file
176
plugins/scheduler-docker-local/scheduler-deploy
Executable file
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/checks/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
scheduler-docker-local-scheduler-deploy() {
|
||||
declare desc="deploys an image tag for a given application"
|
||||
declare trigger="scheduler-docker-local scheduler-deploy"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2" IMAGE_TAG="$3"
|
||||
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local DOKKU_DOCKER_STOP_TIMEOUT DOKKU_HEROKUISH DOKKU_NETWORK_BIND_ALL IMAGE
|
||||
DOKKU_HEROKUISH=false
|
||||
IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
||||
verify_app_name "$APP"
|
||||
plugn trigger pre-deploy "$APP" "$IMAGE_TAG"
|
||||
|
||||
is_image_herokuish_based "$IMAGE" && DOKKU_HEROKUISH=true
|
||||
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
|
||||
local oldids=$(get_app_container_ids "$APP")
|
||||
|
||||
DOKKU_NETWORK_BIND_ALL="$(plugn trigger network-get-property "$APP" bind-all-interfaces)"
|
||||
DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
|
||||
[[ $DOKKU_DOCKER_STOP_TIMEOUT ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
|
||||
|
||||
local line; local PROC_TYPE; local PROC_COUNT; local CONTAINER_INDEX
|
||||
while read -r line || [[ -n "$line" ]]; do
|
||||
[[ "$line" =~ ^#.* ]] && continue
|
||||
line="$(strip_inline_comments "$line")"
|
||||
PROC_TYPE=${line%%=*}
|
||||
PROC_COUNT=${line#*=}
|
||||
CONTAINER_INDEX=1
|
||||
|
||||
if [[ "$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" == "true" ]]; then
|
||||
dokku_log_info1 "zero downtime is disabled for app ($APP.$PROC_TYPE). stopping currently running containers"
|
||||
local cid proctype_oldids="$(get_app_running_container_ids "$APP" "$PROC_TYPE")"
|
||||
for cid in $proctype_oldids; do
|
||||
dokku_log_info2 "stopping $APP.$PROC_TYPE ($cid)"
|
||||
# shellcheck disable=SC2086
|
||||
docker stop $DOCKER_STOP_TIME_ARG "$cid" &> /dev/null
|
||||
# remove cid from oldids to skip the old container finish processing
|
||||
oldids="$(remove_val_from_list "$cid" "$oldids" " ")"
|
||||
done
|
||||
fi
|
||||
|
||||
while [[ $CONTAINER_INDEX -le $PROC_COUNT ]]; do
|
||||
local cid=""; local port=""; local ipaddr=""
|
||||
local DOKKU_CONTAINER_ID_FILE="$DOKKU_ROOT/$APP/CONTAINER.$PROC_TYPE.$CONTAINER_INDEX"
|
||||
|
||||
# start the app
|
||||
local DOCKER_ARGS
|
||||
DOCKER_ARGS=$(: | plugn trigger docker-args-deploy "$APP" "$IMAGE_TAG" "$PROC_TYPE" "$CONTAINER_INDEX")
|
||||
DOCKER_ARGS+=" -e DYNO=$PROC_TYPE.$CONTAINER_INDEX "
|
||||
[[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true "
|
||||
|
||||
declare -a ARG_ARRAY
|
||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||
|
||||
[[ "$DOKKU_HEROKUISH" == "true" ]] && local START_CMD="/start $PROC_TYPE"
|
||||
|
||||
if [[ "$DOKKU_HEROKUISH" == "false" ]]; then
|
||||
local DOKKU_DOCKERFILE_START_CMD=$(config_get "$APP" DOKKU_DOCKERFILE_START_CMD || true)
|
||||
local DOKKU_PROCFILE_START_CMD=$(get_cmd_from_procfile "$APP" "$PROC_TYPE")
|
||||
local START_CMD=${DOKKU_DOCKERFILE_START_CMD:-$DOKKU_PROCFILE_START_CMD}
|
||||
fi
|
||||
|
||||
if [[ "$PROC_TYPE" == "web" ]]; then
|
||||
ports=($(plugn trigger network-compute-ports "$APP" "$PROC_TYPE" "$DOKKU_HEROKUISH"))
|
||||
local DOKKU_DOCKER_PORT_ARGS=""
|
||||
local DOKKU_PORT=""
|
||||
for p in "${ports[@]}"; do
|
||||
if [[ ! "$p" =~ .*udp.* ]]; then
|
||||
DOKKU_PORT=${DOKKU_PORT:="$p"}
|
||||
fi
|
||||
DOKKU_DOCKER_PORT_ARGS+=" -p $p "
|
||||
done
|
||||
|
||||
if [[ "$DOKKU_NETWORK_BIND_ALL" == "false" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d $DOKKU_DOCKER_PORT_ARGS -e PORT=$DOKKU_PORT "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
|
||||
fi
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
cid=$(docker run $DOKKU_GLOBAL_RUN_ARGS -d "${ARG_ARRAY[@]}" $IMAGE $START_CMD)
|
||||
fi
|
||||
|
||||
ipaddr=$(plugn trigger network-get-ipaddr "$APP" "$PROC_TYPE" "$cid")
|
||||
port=$(plugn trigger network-get-port "$APP" "$PROC_TYPE" "$DOKKU_HEROKUISH" "$cid")
|
||||
|
||||
kill_new() {
|
||||
declare desc="wrapper function to kill newly started app container"
|
||||
local cid="$1"
|
||||
docker inspect "$cid" &> /dev/null && docker stop "$cid" > /dev/null && docker kill "$cid" &> /dev/null
|
||||
trap - INT TERM EXIT
|
||||
kill -9 $$
|
||||
}
|
||||
|
||||
# run checks first, then post-deploy hooks, which switches proxy traffic
|
||||
trap 'kill_new $cid' INT TERM EXIT
|
||||
if [[ "$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")" == "false" ]]; then
|
||||
dokku_log_info1 "Attempting pre-flight checks"
|
||||
plugn trigger check-deploy "$APP" "$cid" "$PROC_TYPE" "$port" "$ipaddr"
|
||||
fi
|
||||
trap - INT TERM EXIT
|
||||
|
||||
# now using the new container
|
||||
[[ -n "$cid" ]] && echo "$cid" > "$DOKKU_CONTAINER_ID_FILE"
|
||||
[[ -n "$ipaddr" ]] && plugn trigger network-write-ipaddr "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$ipaddr"
|
||||
[[ -n "$port" ]] && plugn trigger network-write-port "$APP" "$PROC_TYPE" "$CONTAINER_INDEX" "$port"
|
||||
|
||||
# cleanup pre-migration files
|
||||
rm -f "$DOKKU_ROOT/$APP/CONTAINER" "$DOKKU_ROOT/$APP/IP" "$DOKKU_ROOT/$APP/PORT"
|
||||
|
||||
local CONTAINER_INDEX=$(( CONTAINER_INDEX + 1 ))
|
||||
done
|
||||
# cleanup when we scale down
|
||||
if [[ "$PROC_COUNT" == 0 ]]; then
|
||||
local CONTAINER_IDX_OFFSET=0
|
||||
else
|
||||
local CONTAINER_IDX_OFFSET=$((PROC_COUNT + 1))
|
||||
fi
|
||||
local container_state_filetype
|
||||
for container_state_filetype in CONTAINER IP PORT; do
|
||||
cd "$DOKKU_ROOT/$APP"
|
||||
find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f
|
||||
done
|
||||
done < "$DOKKU_SCALE_FILE"
|
||||
|
||||
dokku_log_info1 "Running post-deploy"
|
||||
plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
|
||||
plugn trigger post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
|
||||
|
||||
# kill the old container
|
||||
if [[ -n "$oldids" ]]; then
|
||||
|
||||
if [[ -z "$DOKKU_WAIT_TO_RETIRE" ]]; then
|
||||
local DOKKU_APP_DOKKU_WAIT_TO_RETIRE=$(config_get "$APP" DOKKU_WAIT_TO_RETIRE || true)
|
||||
local DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE=$(config_get --global DOKKU_WAIT_TO_RETIRE || true)
|
||||
local DOKKU_WAIT_TO_RETIRE=${DOKKU_APP_DOKKU_WAIT_TO_RETIRE:="$DOKKU_GLOBAL_DOKKU_WAIT_TO_RETIRE"}
|
||||
fi
|
||||
|
||||
# Let the old container finish processing requests, before terminating it
|
||||
local WAIT="${DOKKU_WAIT_TO_RETIRE:-60}"
|
||||
dokku_log_info1 "Shutting down old containers in $WAIT seconds"
|
||||
local oldid
|
||||
for oldid in $oldids; do
|
||||
dokku_log_info2 "$oldid"
|
||||
done
|
||||
(
|
||||
exec >/dev/null 2>/dev/null </dev/null
|
||||
trap '' INT HUP
|
||||
sleep "$WAIT"
|
||||
for oldid in $oldids; do
|
||||
# Attempt to stop, if that fails, then force a kill as docker seems
|
||||
# to not send SIGKILL as the docs would indicate. If that fails, move
|
||||
# on to the next.
|
||||
# shellcheck disable=SC2086
|
||||
docker stop $DOCKER_STOP_TIME_ARG "$oldid" \
|
||||
|| docker kill "$oldid" \
|
||||
|| plugn trigger retire-container-failed "$APP" # plugin trigger for event logging
|
||||
done
|
||||
) & disown -a
|
||||
# Use trap since disown/nohup don't seem to keep child alive
|
||||
# Give child process just enough time to set the traps
|
||||
sleep 0.1
|
||||
fi
|
||||
}
|
||||
|
||||
scheduler-docker-local-scheduler-deploy "$@"
|
||||
27
plugins/scheduler-docker-local/scheduler-docker-cleanup
Executable file
27
plugins/scheduler-docker-local/scheduler-docker-cleanup
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
scheduler-docker-local-scheduler-docker-cleanup() {
|
||||
declare desc="scheduler-docker-local scheduler-docker-cleanup plugin trigger"
|
||||
declare trigger="scheduler-docker-local scheduler-docker-cleanup"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2" FORCE_CLEANUP="$3"
|
||||
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# delete all non-running containers
|
||||
# shellcheck disable=SC2046
|
||||
docker rm $(docker ps -a -f "status=exited" -f "label=$DOKKU_CONTAINER_LABEL" -q) &> /dev/null || true
|
||||
|
||||
# delete all dead containers
|
||||
# shellcheck disable=SC2046
|
||||
docker rm $(docker ps -a -f "status=dead" -f "label=$DOKKU_CONTAINER_LABEL" -q) &> /dev/null || true
|
||||
|
||||
# delete unused images
|
||||
# shellcheck disable=SC2046
|
||||
docker rmi $(docker images -f 'dangling=true' -q) &> /dev/null &
|
||||
}
|
||||
|
||||
scheduler-docker-local-scheduler-docker-cleanup "$@"
|
||||
57
plugins/scheduler-docker-local/scheduler-run
Executable file
57
plugins/scheduler-docker-local/scheduler-run
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
scheduler-docker-local-scheduler-run() {
|
||||
declare desc="runs command in container based on app image"
|
||||
declare trigger="scheduler-docker-local scheduler-run"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2"
|
||||
shift 2
|
||||
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local IMAGE_TAG=$(get_running_image_tag "$APP")
|
||||
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
||||
|
||||
if [[ -z "$DOKKU_RM_CONTAINER" ]]; then
|
||||
local DOKKU_APP_RM_CONTAINER=$(config_get "$APP" DOKKU_RM_CONTAINER || true)
|
||||
local DOKKU_GLOBAL_RM_CONTAINER=$(config_get --global DOKKU_RM_CONTAINER || true)
|
||||
local DOKKU_RM_CONTAINER=${DOKKU_APP_RM_CONTAINER:="$DOKKU_GLOBAL_RM_CONTAINER"}
|
||||
fi
|
||||
|
||||
local DOCKER_ARGS=$(: | plugn trigger docker-args-run "$APP" "$IMAGE_TAG")
|
||||
[[ "$DOKKU_TRACE" ]] && local DOCKER_ARGS+=" -e TRACE=true "
|
||||
|
||||
declare -a ARG_ARRAY
|
||||
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
||||
|
||||
local DOKKU_RUN_OPTS=" -e DYNO=run.$RANDOM"
|
||||
if [[ "$DOKKU_RM_CONTAINER" ]]; then
|
||||
DOKKU_RUN_OPTS+=" --rm"
|
||||
elif [[ "$DOKKU_DETACH_CONTAINER" ]]; then
|
||||
DOKKU_RUN_OPTS+=" --detach"
|
||||
fi
|
||||
|
||||
has_tty && DOKKU_RUN_OPTS+=" -i -t"
|
||||
is_image_herokuish_based "$IMAGE" && local EXEC_CMD="/exec"
|
||||
|
||||
DOKKU_QUIET_OUTPUT=1 extract_procfile "$APP"
|
||||
|
||||
POTENTIAL_PROCFILE_KEY="$1"
|
||||
PROC_CMD=$(get_cmd_from_procfile "$APP" "$POTENTIAL_PROCFILE_KEY" || echo '')
|
||||
remove_procfile "$APP"
|
||||
|
||||
if [ ! -z "$PROC_CMD" ]; then
|
||||
dokku_log_info1 "Found '$POTENTIAL_PROCFILE_KEY' in Procfile, running that command"
|
||||
set -- "$PROC_CMD" "${@:2}"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
docker run $DOKKU_GLOBAL_RUN_ARGS $DOKKU_RUN_OPTS "${ARG_ARRAY[@]}" $IMAGE $EXEC_CMD "$@"
|
||||
}
|
||||
|
||||
scheduler-docker-local-scheduler-run "$@"
|
||||
36
plugins/scheduler-docker-local/scheduler-stop
Executable file
36
plugins/scheduler-docker-local/scheduler-stop
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
scheduler-docker-local-scheduler-stop() {
|
||||
declare desc="scheduler-docker-local scheduler-stop plugin trigger"
|
||||
declare trigger="scheduler-docker-local scheduler-stop"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2" REMOVE_CONTAINERS="$3"
|
||||
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local DOKKU_APP_RUNNING_CONTAINER_IDS=$(get_app_running_container_ids "$APP")
|
||||
local DOKKU_DOCKER_STOP_TIMEOUT="$(config_get "$APP" DOKKU_DOCKER_STOP_TIMEOUT || true)"
|
||||
|
||||
[[ -n "$DOKKU_DOCKER_STOP_TIMEOUT" ]] && DOCKER_STOP_TIME_ARG="--time=${DOKKU_DOCKER_STOP_TIMEOUT}"
|
||||
|
||||
if [[ -n "$DOKKU_APP_RUNNING_CONTAINER_IDS" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
docker stop $DOCKER_STOP_TIME_ARG $DOKKU_APP_RUNNING_CONTAINER_IDS > /dev/null || true
|
||||
fi
|
||||
|
||||
if [[ "$REMOVE_CONTAINERS" == "true" ]]; then
|
||||
local DOKKU_APP_CIDS=$(get_app_container_ids "$APP")
|
||||
|
||||
if [[ -n "$DOKKU_APP_CIDS" ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
docker rm -f $DOKKU_APP_CIDS > /dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
scheduler-docker-local-scheduler-stop "$@"
|
||||
@@ -2,6 +2,21 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
scheduler-docker-local-scheduler-tags-create() {
|
||||
declare desc="scheduler-docker-local scheduler-tags-create plugin trigger"
|
||||
declare trigger="scheduler-docker-local scheduler-tags-create"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2" SOURCE_IMAGE="$3" TARGET_IMAGE="$4"
|
||||
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local TAG_OPTS=""
|
||||
[[ $(is_tag_force_available) ]] && TAG_OPTS="-f"
|
||||
# shellcheck disable=SC2086
|
||||
docker tag $TAG_OPTS "$SOURCE_IMAGE" "$TARGET_IMAGE"
|
||||
}
|
||||
|
||||
is_tag_force_available() {
|
||||
CLIENT_VERSION_STRING="$(get_docker_version)"
|
||||
MAJOR_VERSION=$(echo "$CLIENT_VERSION_STRING" | awk '{split($0,a,"."); print a[1]}')
|
||||
@@ -18,9 +33,4 @@ is_tag_force_available() {
|
||||
fi
|
||||
}
|
||||
|
||||
tag_image() {
|
||||
declare desc="convenience method for docker tag interface"
|
||||
[[ $(is_tag_force_available) ]] && TAG_OPTS="-f"
|
||||
# shellcheck disable=SC2086
|
||||
docker tag $TAG_OPTS "$1" "$2"
|
||||
}
|
||||
scheduler-docker-local-scheduler-tags-create "$@"
|
||||
17
plugins/scheduler-docker-local/scheduler-tags-destroy
Executable file
17
plugins/scheduler-docker-local/scheduler-tags-destroy
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
scheduler-docker-local-scheduler-tags-destroy() {
|
||||
declare desc="scheduler-docker-local scheduler-tags-destroy plugin trigger"
|
||||
declare trigger="scheduler-docker-local scheduler-tags-destroy"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2" IMAGE_REPO="$3" IMAGE_TAG="$4"
|
||||
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
docker rmi "$IMAGE_REPO:$IMAGE_TAG"
|
||||
}
|
||||
|
||||
scheduler-docker-local-scheduler-tags-destroy "$@"
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/tags/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
tags_create_cmd() {
|
||||
declare desc="creates an images tag for app via command line"
|
||||
@@ -10,7 +10,9 @@ tags_create_cmd() {
|
||||
local APP="$2"; local IMAGE_TAG="$3"; local IMAGE_REPO=$(get_app_image_repo "$APP")
|
||||
verify_app_name "$APP"
|
||||
|
||||
tag_image "$IMAGE_REPO:latest" "$IMAGE_REPO:$IMAGE_TAG"
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
plugn trigger scheduler-tags-create "$DOKKU_SCHEDULER" "$APP" "$IMAGE_REPO:latest" "$IMAGE_REPO:$IMAGE_TAG"
|
||||
|
||||
dokku_log_info2_quiet "Added $IMAGE_TAG tag to $IMAGE_REPO"
|
||||
plugn trigger tags-create "$APP" "$IMAGE_TAG"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/tags/functions"
|
||||
|
||||
tags_main_cmd() {
|
||||
declare desc="shows docker images tags for app via command line"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/tags/functions"
|
||||
|
||||
tags_deploy_cmd() {
|
||||
declare desc="deploys an app with a given tagged image via command line"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/tags/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
tags_destroy_cmd() {
|
||||
declare desc="destroys an app image tag via command line"
|
||||
@@ -16,7 +16,8 @@ tags_destroy_cmd() {
|
||||
;;
|
||||
|
||||
*)
|
||||
docker rmi "$IMAGE_REPO:$IMAGE_TAG"
|
||||
local DOKKU_SCHEDULER=$(config_get "$APP" DOKKU_SCHEDULER || echo "docker-local")
|
||||
plugn trigger scheduler-tags-destroy "$DOKKU_SCHEDULER" "$APP" "$IMAGE_REPO" "$IMAGE_TAG"
|
||||
;;
|
||||
esac
|
||||
plugn trigger tags-destroy "$APP" "$IMAGE_TAG"
|
||||
|
||||
@@ -142,17 +142,12 @@ teardown() {
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
run bash -c "dokku --trace ps:restore"
|
||||
run bash -c "dokku ps:restore"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
run bash -c "dokku ls"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
run bash -c "dokku --quiet ls | grep $TEST_APP | grep -q stopped"
|
||||
run bash -c "dokku --quiet ps:report $TEST_APP | grep -q exited"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
Reference in New Issue
Block a user