Platform-as-a-service in your own Cloud
withcoherence.com
This is the code to accompany the tutorial available at our Framework Guide (Flask) page.
You can use it as a starting point for any full stack Flask application. Read the guide to see how to deploy it to a production environment in your own cloud, or see the instructions below to run a development version of it locally.
- Docker
- Postgres
-
Clone the repository:
git clone https://github.com/<your_github_username>/flask-postgres-employees-demo.git cd flask-postgres-employees-demo
-
Add your database credentials to the
docker-compose.yml
file:services: db: image: postgres:13 environment: POSTGRES_DB: <database_name> POSTGRES_USER: <database_user> POSTGRES_PASSWORD: <database_password>
-
Add your database credentials to the
app.py
file:app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://<database_user>:<database_password>@db:5432/<database_name>'
-
Build and run the Docker container:
docker-compose up --build
-
Run database migrations:
docker-compose exec web flask db upgrade
-
Access the application: Open your browser and navigate to
http://localhost:5000/
.
-
Add Employee:
- Fill out the form with the employee's name, email, and phone number.
- Click "Add Employee".
-
Edit Employee:
- Click the "Edit" link next to the employee you want to edit.
- Update the employee's information in the form.
- Click "Update".
-
Delete Employee:
- Click the "Delete" link next to the employee you want to delete.
To run migrations, use the following command:
docker-compose exec web python migrations.py
or on Coherence add to your cnc.yaml file:
migrate: python migrations.py
Take a look at the following for more information:
Cloud Infrastructure On Autopilot
Deploy containerized and serverless apps to your own cloud in minutes, not weeks.