Sign inSign up

wildflowerschools/sunbeam

By wildflowerschools

Updated about 6 years ago

Flask + Blueprint app for running small WF utilities, apps have largely been retired since 2018

Image
0

654

wildflowerschools/sunbeam repository overview

Sunbeam

Docker Setup

Development

App is exposed over port 5000

docker-compose up
Prod
1) Docker run postgres
docker run -d -e "POSTGRES_PASSWORD=iamaninsecurepassword" -e "POSTGRES_USER=sunbeam" -e "POSTGRES_DB=sunbeam" --name="sunbeam_postgres_prod" postgres:11.3
2) Docker run memcached
docker run -d --name "sunbeam_memcached_prod" memcached:1.5.16-alpine
3) Docker run sunbeam

The following exposes port 5005 and loads a local .env file

docker build -t sunbeam_prod .
docker run --env-file ./.env -e "DATABASE_URL=postgresql://sunbeam:iamaninsecurepassword@sunbeam_postgres_prod:5432/sunbeam" -e "MEMCACHEDCLOUD_SERVERS=sunbeam_memcached_prod" --link="sunbeam_postgres_prod" --link="sunbeam_memcached_prod" --name="sunbeam_prod" -p 5005:80 sunbeam_prod

Setup w/o Docker

Install Python >=3.7

Clone repo
  git clone https://github.com/WildflowerSchools/sunbeam/

Change to directory
  cd sunbeam

Set up virtual env
  python3.7 -m venv ./venv

Activate virtual env
  . venv/bin/activate

Install python packages (--upgrade is used to force updates to github sourced pip packages)
  find . -path "*requirements*" -name "development.txt"  -maxdepth 4 -exec pip install --upgrade -r {} \;

Database
  Create databases
    psql -c "create database sunbeam_development"
    psql -c "create database sunbeam_test"
  Add a user
    psql -c "create role sunbeam login"


Set environment variables, either in the shell, or in a .env file (see https://github.com/theskumar/python-dotenv)
      TEST_DATABASE_URL="postgresql://sunbeam@localhost:5432/sunbeam_test"
      DEVELOPMENT_DATABASE_URL="postgresql://sunbeam@localhost:5432/sunbeam_development"
      SECRET_KEY="SOMETHINGSECRET"

Set up global application variables
  See "Global environment variables" section below

Run database migrations
  ./flask.sh db upgrade
  ./flask.sh test db upgrade

Troubleshooting

psycopg2 fails to install due to openssl issue

ERROR:

...
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1
...

FIX:

export LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib"

# rerun pip install command as documented above

Run

./flask.sh run
Tests
./test.sh
Test Setup:
  • Download nltk data if running apply_blueprint tests

    import nltk
    nltk.download('wordnet')

Heroku environment variables

heroku config:set APP_CONFIG_MODE=production

Commit tagged release

git tag -a v`date -u "+%Y-%m-%d-%H-%M-%S"` -m ""
git push origin `git describe --abbrev=0`

Leaky abstractions / TODO

Add flask cli command for copy generators/blueprint to app/whatever

blueprint_name in tests feels leaky

nltk_data dir in root is leaky; should be beneath apply_blueprint (since used there)

config is still a global namspace; isolate each blueprint's config?

Tag summary

Content type

Image

Digest

Size

300.1 MB

Last updated

about 6 years ago

docker pull wildflowerschools/sunbeam:v2020-07-31-23-57-21