Install Docker
https://www.docker.com/get-started
Create a .env file in the top of your directory and set SECRET_KEY
to a long, random string.
SECRET_KEY=''
To build the project
docker-compose up -d --build
To run the project
docker-compose up
create a superuser for admin access
docker-compose run web python /code/crt_portal/manage.py createsuperuser
To add some test data after you log in at http://0.0.0.0:8000/admin/login
; Then you can check out http://0.0.0.0:8000/form/
.
in another terminal if you are doing front end work:
gulp watch
Also note, that the staticfiles folder is the destination of all static assets when you or a script runs manage.py collectstatic
so don't make your changes there, or they will be overwritten.
In Django, when you update the data models you need to create migrations and then apply those migrations, you can do that with:
docker-compose run web python /code/crt_portal/manage.py makemigrations
docker-compose run web python /code/crt_portal/manage.py migrate
To ssh into your local docker container run:
docker exec -it crt-django_web_1 /bin/bash
To install a new python package run:
docker-compose run web pipenv install name-of-package
Tests run automatically with repos that are integrated with Circle CI. You can run those tests locally with the following instructions.
You can also run project tests using docker with:
docker-compose run web python /code/crt_portal/manage.py test cts_forms
For accessibility testing with Pa11y, you can run that locally, if you have npm installed locally with:
npm run test:a11y
You can scan the code for potential python security flaws using bandit. Run bandit manually:
docker-compose run web bandit -r crt_portal/
If there is a false positive you can add # nosec
at the end of the line that is triggering the error. Please also add a comment that explains why that line is a false positive.
You can check for style issues by running flake8:
docker-compose run web flake8
If you have a a reason why a line of code shouldn't apply flake8 you can add # noqa
, but try to use that sparingly.
We aim to test against Interent Explorer 11 and Google Chrome on a regular basis, and test against Safari and Firefox on an occasional basis.
You only need to get the services stood up and configure the S3 bucket once.
For working with cloud.gov directly, you will need to install the cloud foundry cli. That will allow you to run the cf
commands in a terminal.
First, login to cloud.gov at https://login.fr.cloud.gov/login and then, get a passcode https://login.fr.cloud.gov/passcode.
Log on with cf login -a api.fr.cloud.gov --sso-passcode <put_passcode_here>
First, log into the desired space.
Create postgres DB and S3 with development settings:
cf create-service aws-rds shared-psql crt-db
cf create-service s3 basic-public crt-s3
Store environment variables
cf cups VCAP_SERVICES -p SECRET_KEY
when prompted give it the secret key
You will needed to enable CORS via awscli, for each bucket instructions are here: https://cloud.gov/docs/services/s3/#allowing-client-side-web-access-from-external-applications
Create a service account for deployment for each space you are setting up. (Replace "SPACE" with the name of the space you are setting up.)
cf create-service cloud-gov-service-account space-deployer crt-service-account-SPACE
cf create-service-key crt-service-account-SPACE crt-portal-SPACE-key
cf service-key crt-service-account-SPACE crt-portal-SPACE-key
Those credentials will need to be added to CircleCI as environment variables: CRT_USERNAME_SPACE
CRT_PASSWORD_SPACE
(replace "SPACE" with the relevant space).
Right now, the route is set for the production space, we will want to pass in different routes for different spaces but that can be handled when we add the automation.
To deploy manually, make sure you are logged in, run the push command and pass it the name of the manifest for the space you want to deploy to:
cf push -f manifest_space.yaml
That will push to cloud.gov according to the instructions in the manifest and Profile.
Need to ssh to create superuser (would like to do this automatically in another PR)
cf ssh crt-portal-django
Once in, activate local env
/tmp/lifecycle/shell
Then, you can create a superuser
python /crt_portal/manage.py createsuperuser
Deploys will happen via Circle CI. - For deploys to dev, it will deploy after tests pass, when a PR is merged into the develop branch. - For deploys to staging, it will deploy after tests pass, when we make or update a branch the starts with "release/". - Once we are cleared to deploy to prod, it will deploy after tests pass, when we merge the release into the master branch.
As a back up contingency, you can deploy just with a push using the manifest:
cf push -f manifest_space.yml
These are some technologies we are using in the build, here are some links for background.
Pipenv This is what we use to manage python packages
Postgres Here are the database docs
This is a tool for for interfacing with postgres pgcli
Docker We are using containers for local development.
USWDS We are using 2.0 as our base
Django This is the web framework
Cloud.gov This is the PaaS the app is on