Update readme
This commit is contained in:
parent
f39d3c7f88
commit
ad0205cf76
61
README.md
61
README.md
|
|
@ -14,18 +14,23 @@ Sources
|
||||||
* [Install](https://docs.pipenv.org/#install-pipenv-today) pipenv
|
* [Install](https://docs.pipenv.org/#install-pipenv-today) pipenv
|
||||||
* Create virtualenv in install dependencies `pipenv --python 3.6 install --dev`
|
* Create virtualenv in install dependencies `pipenv --python 3.6 install --dev`
|
||||||
* Create PostgreSQL database & user, needs to be version 10, not 11
|
* Create PostgreSQL database & user, needs to be version 10, not 11
|
||||||
* [Install](https://devcenter.heroku.com/articles/heroku-cli#download-and-install) Heroku cli, run `heroku login` and `heroku git:remote -a skillbox-hep`
|
* [Install](https://devcenter.heroku.com/articles/heroku-cli#download-and-install) Heroku cli, run `heroku login`
|
||||||
|
and `heroku git:remote -a skillbox-hep`
|
||||||
* Create .env in `server` file with `SECRET_KEY` and `DATABASE_URL` (or copy the existing .env.example file)
|
* Create .env in `server` file with `SECRET_KEY` and `DATABASE_URL` (or copy the existing .env.example file)
|
||||||
* Migrate databases: `pipenv run python manage.py migrate`
|
* Migrate databases: `pipenv run python manage.py migrate`
|
||||||
* Create super user: `pipenv run python manage.py createsuperuser`
|
* Create super user: `pipenv run python manage.py createsuperuser`
|
||||||
* Run: `pipenv run python manage.py runserver`
|
* Run: `pipenv run python manage.py runserver`
|
||||||
* Dummy data: `pipenv run python manage.py dummy_data` (restart the development server afterwards) Recreates the db with test data and new superuser: test/test
|
* Dummy data: `pipenv run python manage.py dummy_data` (restart the development server afterwards) Recreates the db with
|
||||||
|
test data and new superuser: test/test
|
||||||
|
|
||||||
#### Dockerize DB
|
#### Dockerize DB
|
||||||
|
|
||||||
* To dockerize the DB, after installing docker, run the following command:
|
* To dockerize the DB, after installing docker, run the following command:
|
||||||
|
|
||||||
```
|
```
|
||||||
docker run --name skillboxdb -d -p 5432:5432 -e POSTGRES_PASSWORD=skillbox -e POSTGRES_USER=skillbox -e POSTGRES_DB=skillbox postgres:10-alpine
|
docker run --name skillboxdb -d -p 5432:5432 -e POSTGRES_PASSWORD=skillbox -e POSTGRES_USER=skillbox -e POSTGRES_DB=skillbox postgres:10-alpine
|
||||||
```
|
```
|
||||||
|
|
||||||
* After a reboot, start the container again with `docker start skillboxdb`
|
* After a reboot, start the container again with `docker start skillboxdb`
|
||||||
|
|
||||||
#### Notes
|
#### Notes
|
||||||
|
|
@ -35,15 +40,20 @@ docker run --name skillboxdb -d -p 5432:5432 -e POSTGRES_PASSWORD=skillbox -e PO
|
||||||
#### Commands
|
#### Commands
|
||||||
|
|
||||||
##### Create a new teacher demo account on prod
|
##### Create a new teacher demo account on prod
|
||||||
|
|
||||||
```
|
```
|
||||||
heroku login # if not already logged in
|
heroku login # if not already logged in
|
||||||
heroku run --remote heroku python server/manage.py create_teacher <firstname> <lastname> <email>
|
heroku run --remote heroku python server/manage.py create_teacher <firstname> <lastname> <email>
|
||||||
```
|
```
|
||||||
|
|
||||||
Tip: create and alias in ~/.bash_aliases:
|
Tip: create and alias in ~/.bash_aliases:
|
||||||
|
|
||||||
```
|
```
|
||||||
alias create_teacher="heroku run --remote heroku python server/manage.py create_teacher"
|
alias create_teacher="heroku run --remote heroku python server/manage.py create_teacher"
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can just run in terminal:
|
Then you can just run in terminal:
|
||||||
|
|
||||||
```
|
```
|
||||||
create_teacher <firstname> <lastname> <email>
|
create_teacher <firstname> <lastname> <email>
|
||||||
```
|
```
|
||||||
|
|
@ -51,18 +61,19 @@ create_teacher <firstname> <lastname> <email>
|
||||||
##### Import a CSV file
|
##### Import a CSV file
|
||||||
|
|
||||||
To import a CSV file locally, run:
|
To import a CSV file locally, run:
|
||||||
|
|
||||||
```
|
```
|
||||||
python manage.py <csv-file>
|
python manage.py <csv-file>
|
||||||
```
|
```
|
||||||
|
|
||||||
To import a CSV file on prod, first upload the CSV file to some public S3 bucket (or make it publicly available some other way)
|
To import a CSV file on prod, first upload the CSV file to some public S3 bucket (or make it publicly available some
|
||||||
|
other way)
|
||||||
|
|
||||||
```
|
```
|
||||||
heroku login # if not already logged in
|
heroku login # if not already logged in
|
||||||
heroku run --remote heroku python server/manage.py import_users --s3 <csv-url>
|
heroku run --remote heroku python server/manage.py import_users --s3 <csv-url>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Client
|
### Client
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
|
|
@ -80,15 +91,15 @@ export NODE_ENV=production && npm install --prefix client && npm run build --pre
|
||||||
```
|
```
|
||||||
|
|
||||||
After running `npm run dev` login to the Django admin view on the same domain as the webpack dev server is running.
|
After running `npm run dev` login to the Django admin view on the same domain as the webpack dev server is running.
|
||||||
Example: The client runs on localhost:8080 and Django on localhost:8000.
|
Example: The client runs on localhost:8080 and Django on localhost:8000. This way you will have a session and a csrf
|
||||||
This way you will have a session and a csrf cookie set and the apollo client will
|
cookie set and the apollo client will be able to make requests.
|
||||||
be able to make requests.
|
|
||||||
|
|
||||||
Production Build
|
Production Build
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
Update the new docker image
|
Update the new docker image
|
||||||
|
|
||||||
- Edit `Dockerfile`
|
- Edit `Dockerfile`
|
||||||
- `docker build -t iterativ/skillbox-test:latest .`
|
- `docker build -t iterativ/skillbox-test:latest .`
|
||||||
- `docker push iterativ/skillbox-test:latest`
|
- `docker push iterativ/skillbox-test:latest`
|
||||||
|
|
@ -125,7 +136,7 @@ The following command will provide a URL to where the backup can be downloaded (
|
||||||
|
|
||||||
`heroku pg:backups:url b001 --app <appname>`
|
`heroku pg:backups:url b001 --app <appname>`
|
||||||
|
|
||||||
To restore a backup, use
|
To restore a backup, use
|
||||||
|
|
||||||
`heroku pg:backups:restore b001 DATABASE_URL --app <appname>`
|
`heroku pg:backups:restore b001 DATABASE_URL --app <appname>`
|
||||||
|
|
||||||
|
|
@ -174,8 +185,8 @@ Change bucket `Permissions` / `Bucket Policy`
|
||||||
|
|
||||||
### Pushing to Production
|
### Pushing to Production
|
||||||
|
|
||||||
Whenever you want to do a release, just merge develop into master and push to origin.
|
Whenever you want to do a release, just merge develop into master and push to origin. The current master will always be
|
||||||
The current master will always be deployed in the evening, if there are new commits that are not yet on Heroku.
|
deployed in the evening, if there are new commits that are not yet on Heroku.
|
||||||
|
|
||||||
### Tagging
|
### Tagging
|
||||||
|
|
||||||
|
|
@ -183,7 +194,8 @@ Whenever you do a new release, please tag the current commit after merging with
|
||||||
|
|
||||||
git tag -a v2019-09-10
|
git tag -a v2019-09-10
|
||||||
|
|
||||||
`git tag -a` creates an annotated tag, which must have a release message (like a commit message). For now, just repeat the current date, like:
|
`git tag -a` creates an annotated tag, which must have a release message (like a commit message). For now, just repeat
|
||||||
|
the current date, like:
|
||||||
|
|
||||||
Release to production on 2019-09-10
|
Release to production on 2019-09-10
|
||||||
|
|
||||||
|
|
@ -195,26 +207,28 @@ You can later see the metadata of the tag with
|
||||||
|
|
||||||
git show release/v2019-09-10
|
git show release/v2019-09-10
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
git tag -ln
|
git tag -ln
|
||||||
|
|
||||||
NB: If there are two releases on the same day, use the pattern `v2020-03-01.x` eg. `v2020-03-01.1` for the subsequent releases
|
NB: If there are two releases on the same day, use the pattern `v2020-03-01.x` eg. `v2020-03-01.1` for the subsequent
|
||||||
|
releases
|
||||||
|
|
||||||
#### Hotfixes
|
#### Hotfixes
|
||||||
|
|
||||||
Please use the pattern `v2020-03-01.hotfix` for hotfix releases
|
Please use the pattern `v2020-03-01.hotfix` for hotfix releases
|
||||||
|
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
## Mocking GraphQL calls
|
## Mocking GraphQL calls
|
||||||
|
|
||||||
We use [cypress-graphql-mock](https://github.com/tgriesser/cypress-graphql-mock) for mocking GraphQL calls in Cypress tests.
|
We use [cypress-graphql-mock](https://github.com/tgriesser/cypress-graphql-mock) for mocking GraphQL calls in Cypress
|
||||||
|
tests.
|
||||||
|
|
||||||
For an example, please see `spellcheck.spec.js`.
|
For an example, please see `spellcheck.spec.js`.
|
||||||
|
|
||||||
There is a schema.json in the fixtures folder. For now it has been generated once, and if there is a significant update to the schema on the server, it has to be regenerated.
|
There is a schema.json in the fixtures folder. For now it has been generated once, and if there is a significant update
|
||||||
|
to the schema on the server, it has to be regenerated.
|
||||||
|
|
||||||
To generate a new schema, use the management command
|
To generate a new schema, use the management command
|
||||||
|
|
||||||
|
|
@ -222,7 +236,6 @@ To generate a new schema, use the management command
|
||||||
python manage.py export_schema_for_cypress
|
python manage.py export_schema_for_cypress
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## GraphQL
|
## GraphQL
|
||||||
|
|
||||||
### Generate GraphQL SDL Document
|
### Generate GraphQL SDL Document
|
||||||
|
|
@ -231,7 +244,6 @@ python manage.py export_schema_for_cypress
|
||||||
python manage.py export_schema_graphql
|
python manage.py export_schema_graphql
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Backup to S3
|
## Backup to S3
|
||||||
|
|
||||||
From https://pawelurbanek.com/heroku-postgresql-s3-backup
|
From https://pawelurbanek.com/heroku-postgresql-s3-backup
|
||||||
|
|
@ -258,3 +270,16 @@ heroku config:set APP_NAME=app-name
|
||||||
```
|
```
|
||||||
heroku config:set PG_BACKUP_PASSWORD=$(openssl rand -base64 32)
|
heroku config:set PG_BACKUP_PASSWORD=$(openssl rand -base64 32)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
heroku addons:create scheduler:standard
|
||||||
|
heroku addons:open scheduler
|
||||||
|
```
|
||||||
|
|
||||||
|
Then schedule the backup for daily at 3:00 UTC, for example
|
||||||
|
|
||||||
|
Command:
|
||||||
|
|
||||||
|
```
|
||||||
|
./bin/pg-backup-to-s3
|
||||||
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue