2015-11-20 10:31:28 +00:00
# notifications-admin
2015-11-18 16:32:15 +00:00
2020-05-20 10:52:55 +01:00
GOV.UK Notify admin application - https://www.notifications.service.gov.uk/
2015-11-23 14:37:29 +00:00
2016-02-03 15:18:57 +00:00
## Features of this application
2015-11-23 14:31:14 +00:00
2016-03-03 07:41:53 +00:00
- Register and manage users
- Create and manage services
- Send batch emails and SMS by uploading a CSV
2016-02-03 15:18:57 +00:00
- Show history of notifications
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
2016-02-03 15:18:57 +00:00
## First-time setup
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
2020-05-16 16:00:38 -07:00
### 1. Install Homebrew
2020-05-20 10:52:55 +01:00
Install [Homebrew ](https://brew.sh ), a package manager for OSX:
2020-05-16 16:00:38 -07:00
2017-04-18 14:04:10 +01:00
```shell
2020-05-20 10:52:55 +01:00
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
2017-04-18 14:04:10 +01:00
```
2020-05-20 10:52:55 +01:00
### 2. Make sure you're using correct language versions
2020-05-16 16:00:38 -07:00
2016-03-03 07:41:53 +00:00
Languages needed
2020-05-16 16:00:38 -07:00
- Python 3.6.x
2019-04-01 09:15:09 +01:00
- [Node ](https://nodejs.org/ ) 10.15.3 or greater
- [npm ](https://www.npmjs.com/ ) 6.4.1 or greater
2020-05-16 16:00:38 -07:00
2020-05-20 10:52:55 +01:00
Need to install node? Run:
2020-05-16 16:00:38 -07:00
2017-04-18 14:04:10 +01:00
```shell
2020-05-20 10:52:55 +01:00
brew install node
2017-04-18 14:04:10 +01:00
```
2020-05-20 10:52:55 +01:00
#### 2.1. `pyenv` For Python version management
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
2020-05-20 10:52:55 +01:00
[pyenv ](https://github.com/pyenv/pyenv ) is a program to manage and swap between different versions of Python. To install:
2020-05-16 16:00:38 -07:00
2016-01-14 16:26:56 +00:00
```shell
2020-05-20 10:52:55 +01:00
brew install pyenv
2020-05-16 16:00:38 -07:00
```
2020-05-20 10:52:55 +01:00
And then follow the further installation instructions in https://github.com/pyenv/pyenv#installation to configure it.
2020-05-16 16:00:38 -07:00
2020-05-20 10:52:55 +01:00
#### 2.2. `n` For Node version management
2020-05-16 16:00:38 -07:00
2020-05-20 10:52:55 +01:00
[NPM ](npmjs.org ) is Node's package management tool. `n` is a tool for managing
different versions of Node. The following installs `n` and uses the long term support (LTS)
version of Node.
2020-05-16 16:00:38 -07:00
```shell
2020-05-20 10:52:55 +01:00
npm install -g n
n lts
2016-01-14 16:26:56 +00:00
```
2016-01-12 13:37:50 +00:00
2020-05-20 10:52:55 +01:00
### 3. Install NPM dependencies
2020-05-16 16:00:38 -07:00
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
```shell
2020-05-20 10:52:55 +01:00
npm install
npm rebuild node-sass
2020-05-16 16:00:38 -07:00
```
2020-05-20 10:52:55 +01:00
### 4. Install and use `virtualenvwrapper` (optional)
2020-05-16 16:00:38 -07:00
2020-05-20 10:52:55 +01:00
We suggest using a virtualenv to separate the python dependencies for this project from python dependencies for other projects.
2020-05-16 16:00:38 -07:00
2020-05-20 10:52:55 +01:00
Install [virtualenvwrapper ](https://virtualenvwrapper.readthedocs.io/en/latest/install.html ):
2020-05-16 16:00:38 -07:00
2020-05-20 10:52:55 +01:00
```shell
pip install virtualenvwrapper
2020-05-16 16:00:38 -07:00
```
2020-05-20 10:52:55 +01:00
Then follow the [virtualenvwrapper installation instructions ](https://virtualenvwrapper.readthedocs.io/en/latest/install.html ) docs to configure virtualenvwrapper for your terminal.
2020-05-16 16:00:38 -07:00
2020-05-20 10:52:55 +01:00
Set up your virtualenv:
2020-05-16 16:00:38 -07:00
```shell
2020-05-20 10:52:55 +01:00
mkvirtualenv notifications-admin
2016-03-03 07:41:53 +00:00
```
2020-05-20 10:52:55 +01:00
If you need to specify a certain version of python you can do this using `-p` , for example:
2020-05-16 16:00:38 -07:00
```shell
mkvirtualenv -p ~/.pyenv/versions/3.6.3/bin/python notifications-admin
```
2020-05-20 10:52:55 +01:00
Activate your virtualenv:
2020-05-16 16:00:38 -07:00
2016-03-03 07:41:53 +00:00
```shell
2020-05-20 10:52:55 +01:00
workon notifications-admin
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
```
2020-05-20 10:52:55 +01:00
### 5. Install Python dependencies
Install dependencies and build the frontend assets:
2020-05-16 16:00:38 -07:00
```shell
2020-05-20 10:52:55 +01:00
./scripts/bootstrap.sh
2020-05-16 16:00:38 -07:00
```
2020-05-20 10:52:55 +01:00
**Note:** You may need versions of both Python 3 and Python 2 accessible to build the python dependencies. `pyenv` is great for that, and making both Python versions accessible can be done like so:
2020-05-16 16:00:38 -07:00
2016-02-03 15:18:57 +00:00
```shell
2020-05-20 10:52:55 +01:00
pyenv global 3.6.3 2.7.15
2016-02-03 15:18:57 +00:00
```
2015-12-10 16:47:29 +00:00
2020-05-22 09:48:04 +01:00
### 6. Create a local `environment.sh` file
In the root directory of the application, run:
2016-03-23 14:09:07 +00:00
```
echo "
2016-08-04 18:01:08 +01:00
export NOTIFY_ENVIRONMENT='development'
2017-11-06 13:07:21 +00:00
export FLASK_APP=application.py
export FLASK_DEBUG=1
export WERKZEUG_DEBUG_PIN=off
2016-03-23 14:09:07 +00:00
"> environment.sh
```
2020-05-20 10:52:55 +01:00
### 7. AWS credentials
2016-08-17 15:59:16 +01:00
Your aws credentials should be stored in a folder located at `~/.aws` . Follow [Amazon's instructions ](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files ) for storing them correctly
2016-03-23 14:09:07 +00:00
2020-05-20 10:52:55 +01:00
### 8. Running the application
2020-05-16 16:00:38 -07:00
In the root directory of the application, run:
2016-02-03 15:18:57 +00:00
```shell
2020-05-20 10:52:55 +01:00
./scripts/run_app.sh
2016-02-03 15:18:57 +00:00
```
2015-11-25 15:29:12 +00:00
2016-03-03 07:41:53 +00:00
Then visit [localhost:6012 ](http://localhost:6012 )
2018-07-10 15:16:14 +01:00
## Updating application dependencies
`requirements.txt` file is generated from the `requirements-app.txt` in order to pin
versions of all nested dependencies. If `requirements-app.txt` has been changed (or
we want to update the unpinned nested dependencies) `requirements.txt` should be
regenerated with
```
make freeze-requirements
```
`requirements.txt` should be committed alongside `requirements-app.txt` changes.
2018-12-14 16:25:31 +00:00
2020-05-20 10:52:55 +01:00
## Automatically rebuild the frontend assets
If you want the front end assets to re-compile on changes, leave this running
in a separate terminal from the app
```shell
npm run watch
```
2018-12-21 12:54:19 +00:00
## Working with static assets
2018-12-14 16:25:31 +00:00
2018-12-21 12:54:19 +00:00
When running locally static assets are served by Flask at http://localhost:6012/static/…
2018-12-14 16:25:31 +00:00
When running on preview, staging and production there’ s a bit more to it:
2018-12-21 12:54:19 +00:00
