A starter project for building Flask applications, utilizing PostgreSQL for the database and NGINX for reverse-proxy and static file serving
Endpoints are defined in services/web/project/__init__.py
/returns json{"hello": "world"}/static/hi.txtreturns a text file containinghi!- Any file placed in
staticfolder is accessible through/static/[filename.extension]
- Any file placed in
/uploadreturns a web form through which a user can upload files- Any file uploaded through form is accessible through
/media/[filename.extension]
- Any file uploaded through form is accessible through
To execute commands against the web container, run: docker-compose exec web python manage.py [command]
For production, be sure to include -f flag: -f docker-compose.prod.yml
Commands are defined in serrvices/web/manage.py
create_dbdrops the database and recreates it- This command is run by default when you start up the development server
- You will need to run this manually at least once in production to set up database
seed_dbseeds the database with whatever is defined within
Run docker-compose up -d --build
This will:
- Create the
webanddbcontainers - Rebuild the database based on what is defined in the project
- By default, this will create a basic
userstable (defined inservices/web/project/__init__.py)
- By default, this will create a basic
- Seed the database with what is defined in the
seed_dbcommand (defined inservices/web/manage.py)- By default, this create a user with the email
test@email.com
- By default, this create a user with the email
Go to localhost:5000 to see application run
Using .env.dev as a template, create an .env.prod. The only required changes for this setup is:
- Set
FLASK_ENVto 'production' - SET
APP_FOLDERto '/home/app/web'
You should also set the DATABASE_URL to what fits for your application
This is the environment for the db container
You should define:
* POSTGRES_USER
* POSTGRES_PASSWORD
* POSTGRES_DB
Of course, if you are deploying to an environment that manages your environment variables, you can define the required environment variables there instead of in files
Run docker-compose -f docker-compose.prod.yml up -d --build
This will:
- Create the
web,db, andnginxcontainers
Go to localhost:1337 to see application run
To change the nginx config, you can edit services/nginx/nginx.conf. This file is copied over to the nginx container during the build step
By default, static files are served out of web/project/static/. They are There is a sample hello.txt that can be deleted