Files
dokku/docs/checks-examples.md

264 lines
9.7 KiB
Markdown
Raw Normal View History

# Zero Downtime Deploys
2016-02-14 18:43:40 -08:00
```
checks <app> Show zero-downtime status
checks:disable <app> Disable zero-downtime checks
checks:enable <app> Enable zero-downtime checks
```
Following a deploy, dokku will now wait `10` seconds before routing traffic to the new container. If the container is not running after this time, then the deploy is failed and your old container will continue serving traffic. You can modify this value globally or on a per-application basis:
```shell
dokku config:set --global DOKKU_DEFAULT_CHECKS_WAIT=30
dokku config:set <app> DOKKU_DEFAULT_CHECKS_WAIT=30
```
You can also choose to skip checks completely on a per-application basis:
```shell
dokku checks:disable <app>
```
Dokku will wait `60` seconds before stopping the old container so that existing connections are given a chance to complete. You can modify this value globally or on a per-application basis:
```shell
dokku config:set --global DOKKU_WAIT_TO_RETIRE=120
dokku config:set <app> DOKKU_WAIT_TO_RETIRE=120
```
> Note that during this time, multiple containers may be running on your server, which can be an issue for memory-hungry applications on memory-constrained servers.
## Checks
If your application needs a longer period to boot up - perhaps to load data into memory, or because of slow boot time - you may also use dokku's `checks` functionality to more precisely check whether an application can serve traffic or not.
To specify checks, add a `CHECKS` file to the root of your project directory. The `CHECKS` file should be plain text and may contain:
* empty lines
* comments (lines starting with #)
* settings (NAME=VALUE)
* check instructions
### Checks Instructions
The format of a check instruction is a path or relative URL, optionally followed by the expected content. For example:
```
/about Our Amazing Team
```
The `CHECKS` file can contain multiple checks, for example:
2015-03-26 18:29:39 -04:00
```
/ My Amazing App
/stylesheets/index.css .body
/scripts/index.js $(function()
/images/logo.png
```
2015-03-26 18:29:39 -04:00
To check an application that supports multiple hostnames, use relative URLs that include the hostname, for example:
2015-03-26 18:29:39 -04:00
```
//admin.example.com Admin Dashboard
//static.example.com/logo.png
```
2015-03-26 18:29:39 -04:00
You can also specify the protocol to explicitly check HTTPS requests.
```
https://admin.example.com Admin Dashboard
https://static.example.com/logo.png
```
### Checks Settings
The default behavior is to wait for `5` seconds before running the checks, to timeout the checks after `30` seconds, and to attempt the checks `5` times. If the checks fail `5` times, the deployment is considered failed and the old container will continue serving traffic.
2015-03-26 18:29:39 -04:00
You can change the default behavior by setting `WAIT`, `TIMEOUT`, and `ATTEMPTS` to different values in the `CHECKS` file. For example:
2015-03-26 18:29:39 -04:00
```
WAIT=30 # Wait 1/2 minute
TIMEOUT=60 # Timeout after a minute
ATTEMPTS=10 # Attempt checks 10 times
/ My Amazing App
```
You may also override the default `WAIT` and `ATTEMPTS` variables for the global dokku installation:
```shell
dokku config:set --global DOKKU_CHECKS_WAIT=15
dokku config:set --global DOKKU_CHECKS_ATTEMPTS=2
```
## Example: Successful Rails Deployment
2015-03-26 18:29:39 -04:00
In this example, a rails applicaiton is successfully deployed to dokku. The initial round of checks fails while the server is starting, but once it starts they succeed and the deployment is successful. `ATTEMPTS` is set to 6, but the third attempt succeeds.
2015-03-26 18:29:39 -04:00
### CHECKS file
2015-03-26 18:29:39 -04:00
````
WAIT=5
ATTEMPTS=6
2015-03-26 18:29:39 -04:00
/check.txt simple_check
````
> check.txt is a text file returning the string 'simple_check'
### Deploy Output
2015-03-26 18:29:39 -04:00
2015-03-26 18:32:50 -04:00
> Note: The output has been trimmed for brevity
2015-03-26 18:29:39 -04:00
````
git push dokku master
-----> Cleaning up...
-----> Building myapp from herokuish...
2015-03-26 18:29:39 -04:00
-----> Adding BUILD_ENV to build environment...
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
.....
-----> Discovering process types
Procfile declares types -> web
-----> Releasing myapp...
-----> Deploying myapp...
-----> Running pre-flight checks
-----> Attempt 1/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/check.txt => "simple_check"
!
curl: (7) Failed to connect to 172.17.0.155 port 5000: Connection refused
! Check attempt 1/6 failed.
2015-03-26 18:29:39 -04:00
-----> Attempt 2/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/check.txt => "simple_check"
!
curl: (7) Failed to connect to 172.17.0.155 port 5000: Connection refused
! Check attempt 2/6 failed.
2015-03-26 18:29:39 -04:00
-----> Attempt 3/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/check.txt => "simple_check"
-----> All checks successful!
=====> myapp container output:
=> Booting Thin
=> Rails 4.2.0 application starting in production on http://0.0.0.0:5000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on 0.0.0.0:5000, CTRL+C to stop
=====> end myapp container output
-----> Running post-deploy
-----> Configuring myapp.dokku.example.com...
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
Reloading nginx
-----> Shutting down old container in 60 seconds
=====> Application deployed:
http://myapp.dokku.example.com
````
## Example: Failing Rails Deployment
2015-03-26 18:29:39 -04:00
In this example, a Rails application fails to deploy. The reason for the failure is that the postgres database connection fails. The initial checks will fail while we wait for the server to start up, just like in the above example. However, once the server does start accepting connections, we will see an error 500 due to the postgres database connection failure.
Once the attempts have been exceeded, the deployment fails and we see the container output, which shows the Postgres connection errors.
2015-03-26 18:29:39 -04:00
### CHECKS file
2015-03-26 18:29:39 -04:00
````
WAIT=5
ATTEMPTS=6
2015-03-26 18:29:39 -04:00
/
````
> The check to the root url '/' would normally access the database.
### Deploy Output
2015-03-26 18:29:39 -04:00
> Note: The output has been trimmed for brevity
````
git push dokku master
-----> Cleaning up...
-----> Building myapp from herokuish...
2015-03-26 18:29:39 -04:00
-----> Adding BUILD_ENV to build environment...
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
.....
Discovering process types
Procfile declares types -> web
Releasing myapp...
Deploying myapp...
Running pre-flight checks
-----> Attempt 1/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/ => ""
!
curl: (7) Failed to connect to 172.17.0.188 port 5000: Connection refused
! Check attempt 1/6 failed.
2015-03-26 18:29:39 -04:00
-----> Attempt 2/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/ => ""
!
2015-03-26 18:29:39 -04:00
curl: (7) Failed to connect to 172.17.0.188 port 5000: Connection refused
! Check attempt 2/6 failed.
2015-03-26 18:29:39 -04:00
-----> Attempt 3/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/ => ""
!
2015-03-26 18:29:39 -04:00
curl: (22) The requested URL returned error: 500 Internal Server Error
! Check attempt 3/6 failed.
2015-03-26 18:29:39 -04:00
-----> Attempt 4/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/ => ""
!
2015-03-26 18:29:39 -04:00
curl: (22) The requested URL returned error: 500 Internal Server Error
! Check attempt 4/6 failed.
2015-03-26 18:29:39 -04:00
-----> Attempt 5/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/ => ""
!
2015-03-26 18:29:39 -04:00
curl: (22) The requested URL returned error: 500 Internal Server Error
! Check attempt 5/6 failed.
2015-03-26 18:29:39 -04:00
-----> Attempt 6/6 Waiting for 5 seconds ...
CHECKS expected result:
http://localhost/ => ""
!
2015-03-26 18:29:39 -04:00
curl: (22) The requested URL returned error: 500 Internal Server Error
Could not start due to 1 failed checks.
! Check attempt 6/6 failed.
2015-03-26 18:29:39 -04:00
=====> myapp container output:
=> Booting Thin
=> Rails 4.2.0 application starting in production on http://0.0.0.0:5000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on 0.0.0.0:5000, CTRL+C to stop
Started GET "/" for 172.17.42.1 at 2015-03-26 21:36:47 +0000
Is the server running on host "172.17.42.1" and accepting
TCP/IP connections on port 5431?
PG::ConnectionBad (could not connect to server: Connection refused
Is the server running on host "172.17.42.1" and accepting
TCP/IP connections on port 5431?
):
vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection
=====> end myapp container output
/usr/local/bin/dokku: line 49: 23409 Killed dokku deploy "$APP"
To dokku@dokku.example.com:myapp
! [remote rejected] dokku -> master (pre-receive hook declined)
error: failed to push some refs to 'dokku@dokku.example.com:myapp'
2015-03-26 19:13:45 -04:00
````