This covers Cloud Foundry specific instructions, and TODOs.
- moving config to environment variables
- running via foreman
- Deployed to Heroku
- Deployed to Cloudfront
waitress
added torequirements.txt
.
pip install -r requirements.txt
- Run with waitress directly:
waitress-serve --port=8000 foia_hub.wsgi:application
- Make a
Procfile
that will work with CloudFoundry's port:
web: waitress-serve --port=$VCAP_APP_PORT foia_hub.wsgi:application
-
Add
VCAP_APP_PORT
to.env
andenv.example
. -
Run with foreman:
foreman start
- Install
dj-database-url
. - Rework
local_settings.py
to use a database string instead of a whole dict.
- Add a
runtime.txt
withpython-3.4.2
.
- Create a Heroku app.
heroku apps:create foia-testing-18f
- Install the Postgres addon.
heroku addons:add heroku-postgresql:hobby-dev
- Grab the Postgres connection string from the Heroku config.
heroku config
-
Add the Postgres connection string to
.env
. -
Send environment variables to the app, overwriting any that are there.
heroku config:push -o
- Deploy the app.
git push heroku master
If using a non-master
branch, like cloudfoundry
:
git push heroku cloudfoundry:master
- Migrate the database.
heroku run python manage.py migrate
- Moved some old settings file into
shared/old
. - Made a new
shared/log
dir and restarted nginx to kick off nginx log files again. - Updated fabfile with a first pass at new approach.
- Renamed
env
tofoia-env
, sinceenv
is a system command. - Removed
links
method infabfile.py
, since we don't need unversioned files anymore. - Important: the
$PYTHONPATH
variable should not be set. If it is set, it interferes in non-obvious ways to make the server not see env variables and not start. - Sourced environment variables for the
migrate
step in the fabfile. - Temporarily add
$PORT
to the env file as well, since theProcfile
uses$PORT
. - Change the
start
command to usenohup foreman start &
. - Change the
stop
command to justkillall waitress-server
Status:
fab deploy
will stay hanging, but successfully daemonize the app.- The webhook is down.
Right now, load it locally from your laptop, with a connection string pointed at the production DB:
./manage.py load_agency_contacts /path/to/foia/contacts/data
Better instructions TBD!
- Create an S3 bucket for the public assets.
cf cs s3 basic-public foia-public-bucket
-
Configure CORS policy on the s3 bucket
-
Create an RDS database for the database.
cf cs aws-rds medium-psql foia-db
-
Change
Procfile
to use$VCAP_APP_PORT
instead of$PORT
. -
Set the necessary environment variables:
cf set-env foia FOIA_ANALYTICS_ID [value]
cf set-env foia FOIA_SECRET_SESSION_KEY [value]
cf set-env foia DJANGO_SETTINGS_MODULE foia_hub.settings.dev
cf set-env foia NEW_RELIC_LICENSE_KEY=[value]
cf set-env foia NEW_RELIC_APP_NAME=[value]
-
Moved the runtime to
3.4.6
-
Renamed app from
foia-testing
tofoia
. -
Ignored the
staticfiles/
directory. -
Re-synced the
.cfignore
and.gitignore
.
- Map a route from our app to a custom domain.
cf map-route foia open.foia.gov
- Setting the host value in
/etc/hosts
locally foropen.foia.gov
to the IP address used bycf.18f.us
should then causehttp://open.foia.gov
to show the deployed app in your browser.
To deploy the app while also running migrations and loading in the latest data:
cf push foia -c "bash cf.sh"
To deploy a staging version of the application, deploy using the staging-manifest.yml (as follows):
cf push -f ./staging-manifest.yml -c "bash cf.sh"
Using the staging-manifest.yml ensures that the application name is set correctly (and as expected).
There's also a staging.py settings file that sets up a production environment (Debug=False in Django) but does not include any of the HTTPS related configuration.
At 18F:
-
In Cloud Foundry at 18F, the staging server is in a separate space called 'staging' than the production instance.
-
There's a separate S3 bucket for staging files.
-
There's a separate RDS instance.
-
There is no ELB instance used by the staging instance, since we don't
-
configure that with HTTPS.