# cookiecutter-flask
Cookiecutter allows us to template out our boilerplate so we can easily create a new Flask microservice.

## Setup and Usage

Before starting make sure you have python3.6 installed.
An easy way to manage python versions is with pyenv.
```
$ brew update
$ brew install pyenv
$ pyenv install 3.6
$ pyenv local 3.6
```
For your convenience there is already a .python-version file set to 3.6 so
all you have to do is `pyenv install 3.6`.
You have two options for using this repo.

### Option 1 - Create boilerplate directly from Github

1) Create a Python env and activate it
```
$ python -m venv env
$ . env/bin/activate
```
2) Install cookiecutter
```
$ pip install cookiecutter==1.6.0
```

3) Create a new microservice boilerplate
```
$ cookiecutter git@github.com:theorchard/cookiecutter-flask
```

4) Follow the two prompts to enter your repo_name and your app_name.
* **repo_name**: Repository name of your project which will also be used in monitoring services, like Datadog.
You can omit the `ows` prefix. For example, `product-physical` will become `ows-product-physical`.
* **app_name**: Name of project directory which will also be used for imports. For example, `product_physical`.
* **python_version**: Python version to use (3.4 or 3.6). 

If you'd like to use the microservice without any prompts:
```
$ cookiecutter --no-input git@github.com:theorchard/cookiecutter-flask repo_name=product-physical app_name=product_physical
```

5) You can now deactivate your cookiecutter env
```
$ deactivate
```

6) Go to your new project. So, if you set "product-physical" for repo_name in step 4, you can:
```
$ cd ows-product-physical
```

7) Push up your new project to an empty Github repo and start coding!


### Option 2 - Fork cookiecutter-flask
You will use this option when you want to contribute to the boilerplate.

Make sure you have `make` installed. Make can be installed on Mac with Homebrew
```
$ brew install make
```

To build a new project, run the following and follow the prompts.
```
$ make cookies
```

All configuration values are stored in cookiecutter.json in this project.
You will be asked to fill out two prompts:
* **repo_name**: Repository name of your project which will also be used in monitoring services, like Datadog.
You can omit the ows prefix. For example, product-physical will become ows-product-physical.
* **app_name**: Name of project directory which will also be used for imports. For example, product_physical.
* **python_version**: Python version to use (3.4 or 3.6). 

## Contributing to Flask Boilerplate
After forking this repo, you can begin to make boilerplate contributions. You will need to make sure that
you template your changes (in Jinja format) so that cookiecutter knows how to copy them.

All currently supported configurations are stored in `cookicutter.json`. Any piece of code that will need to be replaced with one of these configurations (e.g. `app_name`) will need to be templated using `{{cookiecutter.XXXX}}`. For example, if you're adding a new file which imports from the app directory, you will need to use `personalize` in your import statement.
```
$ from personalize import config
```

If you need to add support for new configurations, you will need to add them to `cookiecutter.json` first.
