Add googlemaps api to env update my local tables
Note: App is the flask backend. react-app is frontend
pipenv install --dev -r dev-requirements.txt && pipenv install -r requirements.txt
psql create user travel_bucket_dev with password 'arst1234'; create database travel_bucket_app with owner travel_bucket_dev;
Back End -------------- other readme commands pipenv run flask run
Front End ------------- cd react-app npm i npm start
Seeds are not automatically done heroku run -a travel-bucket-app flask seed all heroku run -a travel-bucket-app flask seed undo
Local Seeds pipenv run flask seed all
github cheats git fetch origin branchName -- should pull changes into the branch your on from branchName
Add a model pipenv run flask db migrate to autogenerate a migration pipenv run flask db upgrade to apply table and model changes to the database
pipenv run flask db migrate -m "create a table message"
Dont run alembic directly:
This is the starter for the Flask React project.
-
Clone this repository (only this branch)
git clone https://github.com/appacademy-starters/python-project-starter.git
-
Install dependencies
pipenv install --dev -r dev-requirements.txt && pipenv install -r requirements.txt
-
Create a .env file based on the example with proper settings for your development environment
-
Setup your PostgreSQL user, password and database and make sure it matches your .env file
-
Get into your pipenv, migrate your database, seed your database, and run your flask app
pipenv shell
flask db upgrade
flask seed all
flask run
-
To run the React App in development, checkout the README inside the
react-app
directory.
IMPORTANT! psycopg2-binary MUST remain a dev dependency because you can't install it on apline-linux. There is a layer in the Dockerfile that will install psycopg2 (not binary) for us.
-
Make sure you have the Microsoft Remote - Containers extension installed.
-
Make sure you have Docker installed on your computer.
-
Clone the repository (only this branch)
git clone https://github.com/appacademy-starters/python-project-starter.git
-
Open the repo in VS Code.
-
Click "Open in Container" when VS Code prompts to open container in the bottom right hand corner.
-
Be Patient! The initial install will take a LONG time, it's building a container that has postgres preconfigured and even installing all your project dependencies. (For both flask and react!)
Note: This will take much less time on future starts because everything will be cached.
-
Once everything is up, be sure to make a
.env
file based on.env.example
in both the root directory and the react-app directory before running your app. -
Get into your pipenv, migrate your database, seed your database, and run your flask app
pipenv shell
flask db upgrade
flask seed all
flask run
-
To run the React App in development, checkout the README inside the
react-app
directory.
This repo comes configured with Github Actions. When you push to your main branch, Github will automatically pull your code, package and push it to Heroku, and then release the new image and run db migrations.
-
Before you deploy, don't forget to run the following command in order to ensure that your production environment has all of your up-to-date dependencies. You only have to run this command when you have installed new Python packages since your last deployment, but if you aren't sure, it won't hurt to run it again.
pipenv lock -r > requirements.txt
-
Write your Dockerfile. In order for the Github action to work effectively, it must have a configured Dockerfile. Follow the comments found in this Dockerfile to write your own!
-
Create a new project on Heroku.
-
Under Resources click "Find more add-ons" and add the add on called "Heroku Postgres".
-
Configure production environment variables. In your Heroku app settings -> config variables you should have two environment variables set:
Key Value DATABASE_URL
Autogenerated when adding postgres to Heroku app SECRET_KEY
Random string full of entropy -
Generate a Heroku OAuth token for your Github Action. To do so, log in to Heroku via your command line with
heroku login
. Once you are logged in, runheroku authorizations:create
. Copy the GUID value for the Token key. -
In your Github Actions Secrets you should have two environment variables set. You can set these variables via your Github repository settings -> secrets -> actions. Click "New respository secret" to create each of the following variables:
Key Value HEROKU_API_KEY
Heroku Oauth Token (from step 6) HEROKU_APP_NAME
Heroku app name -
Push to your
main
branch!
Command | Purpose |
---|---|
pipenv shell |
Open your terminal in the virtual environment and be able to run flask commands without a prefix |
pipenv run |
Run a command from the context of the virtual environment without actually entering into it. You can use this as a prefix for flask commands |
flask db upgrade |
Check in with the database and run any needed migrations |
flask db downgrade |
Check in with the database and revert any needed migrations |
flask seed all |
Just a helpful syntax to run queries against the db to seed data. See the app/seeds folder for reference and more details |
heroku login -i |
Authenticate your heroku-cli using the command line. Drop the -i to authenticate via the browser |
heroku authorizations:create |
Once authenticated, use this to generate an Oauth token |
heroku run -a travel-bucket-app |
Run a command from within the deployed container on Heroku |