Skip to content

Instantly share code, notes, and snippets.

@gsf
Last active August 29, 2015 14:07
Show Gist options
  • Save gsf/9515a50187fcbca16981 to your computer and use it in GitHub Desktop.
Save gsf/9515a50187fcbca16981 to your computer and use it in GitHub Desktop.
RecordTrac example data on Heroku
$ heroku run python db_users.py
Running `python db_users.py` attached to terminal... up, run.9338
Traceback (most recent call last):
  File "db_users.py", line 4, in <module>
    set_directory_fields()
  File "/app/public_records_portal/prr.py", line 284, in set_directory_fields
    csvfile = urllib.urlopen(app.config['STAFF_URL'])
  File "/app/.heroku/python/lib/python2.7/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/app/.heroku/python/lib/python2.7/urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "/app/.heroku/python/lib/python2.7/urllib.py", line 463, in open_file
    return self.open_local_file(url)
  File "/app/.heroku/python/lib/python2.7/urllib.py", line 477, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] No such file or directory: 'not supplied'
$ heroku run python db_seed.py
Running `python db_seed.py` attached to terminal... up, run.4419
Traceback (most recent call last):
  File "db_seed.py", line 1, in <module>
    from public_records_portal import prr, db_helpers, departments, db, models
ImportError: cannot import name departments
$

The error in db_seed.py is due to an issue I already submitted a pull request for: codeforamerica/recordtrac#154.

#!/bin/sh
file=$1
bucket=$2
contentType=$3
resource="/${bucket}/${file}"
dateValue=`date -R`
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
s3Key=xxxxxxxxxxx
s3Secret=xxxxxxxxxxxxxxxxxxxxxxxxx
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${file}
@gsf
Copy link
Author

gsf commented Sep 29, 2014

With that fix committed we hit this error, which I assume is caused by the lack of db_users:

$ heroku run python db_seed.py
Running `python db_seed.py` attached to terminal... up, run.1101
Seeding database...
Traceback (most recent call last):
  File "db_seed.py", line 20, in <module>
    request_department = random.choice(departments)
  File "/app/.heroku/python/lib/python2.7/random.py", line 275, in choice
    return seq[int(self.random() * len(seq))]  # raises IndexError if seq is empty
IndexError: list index out of range
$

@gsf
Copy link
Author

gsf commented Sep 29, 2014

Once I removed the STAFF_URL environment variable I was able to run db_users, then db_seed. Only the DEFAULT_OWNER_EMAIL can log in right now -- I'll point it at a CSV so we can add more admin users.

@gsf
Copy link
Author

gsf commented Sep 30, 2014

I uploaded the staff.csv (example) to S3 with the above script. Now I get the following error:

$ heroku run python db_users.py
Running `python db_users.py` attached to terminal... up, run.4561
Traceback (most recent call last):
  File "db_users.py", line 4, in <module>
    set_directory_fields()
  File "/app/public_records_portal/prr.py", line 283, in set_directory_fields
    update_user(user = user, is_staff = False)
NameError: global name 'update_user' is not defined
$ 

Looks like update_user isn't being included in the import from db_helpers.

@gsf
Copy link
Author

gsf commented Oct 7, 2014

Now that things are up and running the workflow for adding people to the system is as follows:

  1. Add lines to staff.csv
  2. Run ./s3up.sh staff.csv recordtrac text/csv to upload the CSV.
  3. Turn off the web dyno at heroku with heroku ps:scale web=0
  4. Update the users with heroku run python db_users.py
  5. Turn the web dyno back on with heroku ps:scale web=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment