/buzz-me-in

automated sms buzzer for our switchbot

Primary LanguagePython

buzz-me-in

twilio -> switchbot service to let you manage access

notes

you need a config.json in the root directory for switchbot auth. example config.json looks like this:

{
  "SWITCHBOT_AUTH": "[auth key here]",
  "TWILIO_ACCOUNT_SID": "[sid here]",
  "TWILIO_AUTH_TOKEN": "[auth token here]"
}

dev quickstart

TODO: independent backend and frontend dev

database - postgresql

TODO: add environment variables shell script for local vs prod environments

prereqs:

  • postgres

connect to local db

start postgres server - depends on how you installed postgres

brew services restart postgresql     # if postgres was installed with brew
postgres -D /usr/local/var/postgres  # to run postgres without brew

create local postgres db

createdb buzz-me-in

run postgres interactive terminal

psql buzz-me-in

connect to prod db

on GCP, the instance is called buzzer-166. In the cloud console, enter:

gcloud sql connect myinstance --user=postgres

backend - python + flask

prereqs:

  • python3.7+

install venv package globally:

python3 -m pip install venv

set up virtual environment (in root dir):

python3 -m venv .venv      # create virtual env
source .venv/bin/activate  # activate virtual env
# install dependencies and test dependencies
pip install -r requirements.txt -r requirements-test.txt -r requirements-dev.txt
deactivate                # deactivate virtual env

to run server locally (with virtual environment activated):

yarn start-server

to run server in Google's dev server locally to mimic the prod environment:

dev_appserver.py --env_var GOOGLE_APPLICATION_CREDENTIALS=[path to your credentials] .

to run tests:

yarn test-server

NOTE: to run the server, currently you need an authorized google cloud service account key file on your machine, as well as the GOOGLE_APPLICATION_CREDENTIALS env var set to the location of that file. This is just for logs. TODO: remove google logs dependency or set logs to only use google when on the server

frontend - typescript + react

install dependencies

yarn

start react dev server

yarn start

deployment stuff

Currently, this app is deployed and hosted with Google Cloud Platform. app.yaml and .gcloudignore are config files for the gcloud which is used to deploy this app to GCP.

prereqs for deployment:

  • your google account must be given privileges
  • download their gcloud (docs) CLI tool here.

to deploy a new version (from root dir):

yarn build          # build the react app
gcloud app deploy   # push to prod server

Create React App readme

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.

The page will reload when you make changes.
You may also see any lint errors in the console.

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

npm run eject

Note: this is a one-way operation. Once you eject, you can't go back!

If you aren't satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

npm run build fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify