<commit_before># Deploying your Will

Will's happy to run on your machine all day, every day.  But he really shines out in production where he can run independently of anything you do with your local machine.  Here are some best practices for deploying will.

## Deploy on Heroku

Heroku is our recommended platform for deployment because it's simple, easy, and free. That's a tough combination to beat.  You're in no way locked in to running will on heroku, though - run him wherever you want!

#### Step 1: Set up your heroku app, and a redis addon.

Assuming you have the [heroku toolbelt](https://toolbelt.heroku.com/) installed and all set up, it's as easy as this:
    
```bash
heroku create our-will-name
heroku addons:add rediscloud
```

A note on rediscloud: you can also use redistogo, openredis, or anyone else.  We use rediscloud and like them.


#### Step 2: Add all the needed environment variables:

You'll want to take all the variables that live in your virtualenv's `postactivate` file that feed into your will environment, and provide them to your heroku app.

At minimum, that's
```bash
heroku config:set \
WILL_PUBLIC_URL="http://our-will-name.herokuapp.com" \
WILL_USERNAME='<EMAIL>' \
WILL_PASSWORD='<PASSWORD>' \
WILL_V2_TOKEN='asdf<PASSWORD>' \
```

If you have more than 30 chat rooms, you must also set the V1 token to avoid hipchat rate limits:
```bash
heroku config:set WILL_V1_TOKEN='<KEY>'
```

Finally, for will's schedule to be correct, you need to set him to the time zone you want:

```bash
heroku config:set TZ="America/Los_Angeles"
```

**Note:** You don't have to worry about setting the `REDIS_URL` or `HTTPSERVER_PORT`.  Will auto-detects those and takes care of it.

#### Step 3: Deploy!

You're all set to deploy your will. Ready? Go!


```bash
git push heroku
```

You app is now up on heroku.  Finally, turn it on!

`heroku scale web=1`

That should be it - head over to [http://our-will-name.herokuapp.com](http://our-will-name.herokuapp.com), and you should see will's smiling face.

If so, pop into chat, and give a:

![Hi, Hello, username!](img/hi_hello.gif)


#### Deploying future updates

Just commit your updates, then

```bash
git push heroku
```

Simple.  For best-practices, see our continuous deployment recommendations below.


## Deploy Everywhere Else

#### Will is Just Python

That says it all. Will is just python, and you can deploy him *anywhere* you have python, an open port, and access to redis.

In your chosen deploy environment and setup, you'll want to do a couple things:

#### Replicate your environment settings<commit_msg>update documentation for deploy with docker<commit_after># Deploying your Will

Will's happy to run on your machine all day, every day.  But he really shines out in production where he can run independently of anything you do with your local machine.  Here are some best practices for deploying will.

## Deploy on Heroku

Heroku is our recommended platform for deployment because it's simple, easy, and free. That's a tough combination to beat.  You're in no way locked in to running will on heroku, though - run him wherever you want!

#### Step 1: Set up your heroku app, and a redis addon.

Assuming you have the [heroku toolbelt](https://toolbelt.heroku.com/) installed and all set up, it's as easy as this:
    
```bash
heroku create our-will-name
heroku addons:add rediscloud
```

A note on rediscloud: you can also use redistogo, openredis, or anyone else.  We use rediscloud and like them.


#### Step 2: Add all the needed environment variables:

You'll want to take all the variables that live in your virtualenv's `postactivate` file that feed into your will environment, and provide them to your heroku app.

At minimum, that's
```bash
heroku config:set \
WILL_PUBLIC_URL="http://our-will-name.herokuapp.com" \
WILL_USERNAME='<EMAIL>' \
WILL_PASSWORD='<PASSWORD>' \
WILL_V2_TOKEN='<PASSWORD>' \
```

If you have more than 30 chat rooms, you must also set the V1 token to avoid hipchat rate limits:
```bash
heroku config:set WILL_V1_TOKEN='<KEY>'
```

Finally, for will's schedule to be correct, you need to set him to the time zone you want:

```bash
heroku config:set TZ="America/Los_Angeles"
```

**Note:** You don't have to worry about setting the `REDIS_URL` or `HTTPSERVER_PORT`.  Will auto-detects those and takes care of it.

#### Step 3: Deploy!

You're all set to deploy your will. Ready? Go!


```bash
git push heroku
```

You app is now up on heroku.  Finally, turn it on!

`heroku scale web=1`

That should be it - head over to [http://our-will-name.herokuapp.com](http://our-will-name.herokuapp.com), and you should see will's smiling face.

If so, pop into chat, and give a:

![Hi, Hello, username!](img/hi_hello.gif)


#### Deploying future updates

Just commit your updates, then

```bash
git push heroku
```

Simple.  For best-practices, see our continuous deployment recommendations below.


## Depoly in Docker
Will is packaged with a Dockerfile and docker-compose files to allow deploying in a container with redis. 

### Pre-requisites
You should have docker already installed; additionally, the instructions require docker-compose.  If you're not using docker-compose, you must start the image via the docker command with the correct arguments.

### Step 1: Configure your container's environment variables
In will's docker directory, update the default.env file with your environment's settings.  At a minimum, this should contain:
```bash 
WILL_USERNAME
WILL_PASSWORD
WILL_V2_TOKEN
```
Note, we've pre-defined the redis url and the HTTP Server port; if you update these values, make sure you update the docker-compose file accordingly. 

### Step 2: Deploy your plugins and templates
If you have any custom templates, create directories for your plugins and templates, and load your plugins and templates they'll be mounted when the container starts up giving your contanerized bot access to your templates.
```bash 
mkdir ./plugins ./templates
```

### Step 3: Build will.
Run build your docker image locally.
```bash
docker-compose build 
```

### Step 4: Start the container
Start your image from docker-compose using:
```bash
docker-compose up 
```
or to run the container in the background,
```bash
docker-compose up -d
```

## Deploy Everywhere Else

#### Will is Just Python

That says it all. Will is just python, and you can deploy him *anywhere* you have python, an open port, and access to redis.

In your chosen deploy environment and setup, you'll want to do a couple things:

#### Replicate your environment settings
{'fraction_non_alphanumeric': 0.0874466788543571, 'fraction_numerical': 0.0035039609993906154, 'mean_word_length': 4.341741253051262, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4282832', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1885, 'n_words': 936}