Go to file
Ramon Wenger cbf7c10aff Add build step for iterativ academy, update docker image
Squashed commit of the following:

commit 0532315d4e679a145d783fd7a495669beae3f6aa
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Thu Jan 7 17:12:57 2021 +0100

    Add deploy step to correct pipeline

commit 2a54d2f259f821f74d48dd26c803f8cc870ae026
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Thu Jan 7 16:53:43 2021 +0100

    Update dependencies in dockerfile

commit 550869366c009852c9d2856c27ab71e072238e93
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Thu Jan 7 16:17:42 2021 +0100

    Update cypress step

commit 348ec30d6682ba726127d383b87356415cea05bb
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Thu Jan 7 16:06:41 2021 +0100

    Update pipelines

commit f8b1f50f1eaead7a06b336b03f5ad561ab92b278
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Thu Jan 7 15:59:31 2021 +0100

    Change node version

commit be33eafdb0e90bd815efb6a341b9a8e05a4598bb
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Thu Jan 7 15:45:23 2021 +0100

    Remove cypress install step from Dockerfile

commit c28ab32e80cd05e12a420abfdaaf2ac1c4d551a4
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Wed Jan 6 20:43:58 2021 +0100

    Update package-lock

commit 86114b91fae176fe9d8f42bf1e78dced75ea8e51
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Wed Jan 6 20:35:57 2021 +0100

    Update cypress version

commit 11174d92fe36c4d8d0e8bba35fa2da7b64b1c4e2
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Wed Jan 6 16:48:49 2021 +0100

    Update Pipfile.lock

commit 4a302df907eddae34f02c1816ae064c2384385e6
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Wed Jan 6 15:51:42 2021 +0100

    Update python version

commit ac54ec57e7691b5c21459ac40ad20479aade56dd
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Wed Jan 6 15:00:40 2021 +0100

    Remove ipython

commit a9c72d7d2f3c1027d4b04e81d68afd78d0460a8a
Author: Ramon Wenger <ramon.wenger@iterativ.ch>
Date:   Wed Jan 6 13:59:08 2021 +0100

    Add deploy step for iterativ academy
2021-01-07 17:54:49 +01:00
.git-crypt Add 1 git-crypt collaborator 2018-09-19 17:11:39 +02:00
bin initial commit 2018-08-06 23:26:23 +02:00
client Add build step for iterativ academy, update docker image 2021-01-07 17:54:49 +01:00
docs Add documentation for backup (initial version) 2019-07-10 16:36:12 +02:00
server Add connection age to database settings 2020-11-18 21:45:47 +01:00
.editorconfig Show the name of the logged in user in DefaultLayout 2018-10-05 10:49:12 +02:00
.gitignore Add additional pipeline test settings 2020-04-02 16:20:42 +02:00
Dockerfile Add build step for iterativ academy, update docker image 2021-01-07 17:54:49 +01:00
Pipfile Add build step for iterativ academy, update docker image 2021-01-07 17:54:49 +01:00
Pipfile.lock Add build step for iterativ academy, update docker image 2021-01-07 17:54:49 +01:00
Procfile Update max requests 2020-11-19 14:55:38 +01:00
README.md Add build step for iterativ academy, update docker image 2021-01-07 17:54:49 +01:00
bitbucket-pipelines.yml Add build step for iterativ academy, update docker image 2021-01-07 17:54:49 +01:00
build-docker-image.sh Add some configuration for the e2e tests 2019-02-04 09:33:42 +01:00
debug-pipelines.sh Add build step for iterativ academy, update docker image 2021-01-07 17:54:49 +01:00
docker-bash.sh Add some configuration for the e2e tests 2019-02-04 09:33:42 +01:00
docker-compose.yml Fix Postgres version in docker files 2018-10-30 17:52:00 +01:00
docker_dummy_data.sh Update docker configuration 2018-09-03 17:20:02 +02:00
local-setup-for-tests.sh Fix cypress test 2019-02-04 17:42:28 +01:00
package-lock.json Add schema file, also add instructions to readme 2020-01-20 13:02:27 +01:00
package.json remove uploadcare from root package.json 2018-09-20 09:41:05 +02:00
pipenv-cypress.sh Add script for local cypress testing with pipenv 2019-02-14 18:27:33 +01:00
release-tasks.sh Remove dummy data from release tasks 2018-10-17 14:48:45 +02:00
setup-for-tests.sh Add some configuration for the e2e tests 2019-02-04 09:33:42 +01:00

README.md

mySkillbox

Sources

Development

Server

  • Install pipenv
  • Create virtualenv in install dependencies pipenv --python 3.6 install --dev
  • Create PostgreSQL database & user, needs to be version 10, not 11
  • 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)
  • Migrate databases: pipenv run python manage.py migrate
  • Create super user: pipenv run python manage.py createsuperuser
  • 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

Dockerize DB

  • 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
  • After a reboot, start the container again with docker start skillboxdb

Notes

Commands

Create a new teacher demo account on prod
heroku login # if not already logged in
heroku run --remote heroku python server/manage.py create_teacher <firstname> <lastname> <email>

Tip: create and alias in ~/.bash_aliases:

alias create_teacher="heroku run --remote heroku python server/manage.py create_teacher"

Then you can just run in terminal:

create_teacher <firstname> <lastname> <email>
Import a CSV file

To import a CSV file locally, run:

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)

heroku login # if not already logged in
heroku run --remote heroku python server/manage.py import_users --s3 <csv-url>

Client

# install dependencies
npm install --prefix client

# serve with hot reload at localhost:3000
npm run dev --prefix client

# build
npm run build --prefix client

# build for production with minification
export NODE_ENV=production && npm install --prefix client && npm run build --prefix client

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. This way you will have a session and a csrf cookie set and the apollo client will be able to make requests.

Production Build

Docker

Update the new docker image

  • Edit Dockerfile
  • docker build -t iterativ/skillbox-test:latest .
  • docker push iterativ/skillbox-test:latest

Urls

(trailing slashes are required)

Heroku

heroku run python server/manage.py <command> --app <appname>

Rollback

After doing a rollback under https://data.heroku.com/

heroku pg:info --app=<appname>

Change DATABASE URL (e.g after a rollback)

heroku pg:promote HEROKU_POSTGRESQL_PINK

Backup

Create a backup

heroku pg:backups:capture --app <appname>

The following command will provide a URL to where the backup can be downloaded (expires after 60 minutes)

heroku pg:backups:url b001 --app <appname>

To restore a backup, use

heroku pg:backups:restore b001 DATABASE_URL --app <appname>

To see the backup schedule

heroku pg:backus:schedules --app <appname>

AWS

  1. Create user with API Access and add access key id and access key to .env and set USE_AWS=True
  2. Create S3 Bucket in location EU Ireland.

Change bucket Permissions / Bucket Policy

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<bucket-name>/*"
        },
        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "AWS": "<user arn>"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::<bucket-name>/*",
                "arn:aws:s3:::<bucket-name>"
            ]
        }
    ]
}

Release

Pushing to Production

Whenever you want to do a release, just merge develop into master and push to origin. The current master will always be deployed in the evening, if there are new commits that are not yet on Heroku.

Tagging

Whenever you do a new release, please tag the current commit after merging with the current date:

git tag -a release/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:

Release to production on 2019-09-10

You can and should then push the tag to the repo

git push origin release/v2019-09-10

You can later see the metadata of the tag with

git show release/v2019-09-10

Testing

Mocking GraphQL calls

We use cypress-graphql-mock for mocking GraphQL calls in Cypress tests.

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.

To generate a new schema, use the management command

python manage.py export_schema_for_cypress