Simple, Extensible, Reliable, Modular Angular-Flask-PostgreSQL seed project with Docker.
This is a simple Angular-Flask web application skeleton project with following key features:
.env
variable and docker.compose.yml
files.Blueprints
,
application factory
and different configs, you can easily extend this seed project to any
Production ready application.Service
Class that encapsulates common SQLAlchemy operations to interact with data model by
exposing APIs.PostgreSQL
database support with sample db, model and dummy data examples included in
the project.nginx
.It is built with following components:
NOTE: I have tagged this project at each release. So please refer to previous tags if you are looking for a simpler version of this seed project. For e.g., If you want to use the seed project without database support please refer to v1.0.0 of the project under tags. Also refer Changelog file for latest changes.
This directory holds the Angular code.
This directory holds the nginx config file and Dockerfile for running the nginx container. This container serves the Angular code and also passes request to backend.
This directory holds the Dockerfile for running PostgreSQL database. It also contains init.sql
script to create a sample database when postres docker container initializes.
This directory contains the server side code. It hosts the Flask app, tests setup and other configs and settings files required by the backend. It also has Dockerfile for running the flask container. This container hosts the backend code.
A simple .env
file to set the environment variables for Flask and Postgres. We can have multiple
versions of this file for different environments.
This file is used by the Docker to create the containers and run your app. We can have multiple versions of this file for different environments.
For this seed project, I am using 3 Docker containers:
The three components are all created from Docker images that expand on the respective official images from Docker Hub. Each of these images are built using separate Dockerfiles. Docker Compose is then used to create all three containers and connect them correctly into a unified application.
The request from an external user hits the nginx web server on port 80. Depending on the URL,the request is served using Angular code or it is sent to Flask web application. In this app, all request URL starting with /api is sent to Flask web service. The Flask docker container is also running and it exposes port 5000. These setting are defined in nginx.conf file. In this way, nginx is aware of both Frontend and Backend services. The Flask container talks to the PostgreSQL database on port 5432 for any request that require database operations.
NOTE: Make sure you have Docker, node, npm and angular-cli installed. Check Angular Prerequisites here.
ng build --prod
to create production build for Angular.docker-compose build
docker-compose up
docker-compose -f docker-compose.yml up --build
localhost
- It should display the Welcome message from Angular and a default message from
backend.localhost/api
- It should display welcome message from Flask.localhost/api/ping
- To get a json
from Flask.http://localhost/api/users
- Fetches all users from users
table.This seed project is good for starting up with any Angular-Flask-Docker project, so check it out and feel free to fork, update, plug in your project etc. Let me know if you find any issues.
postgres
is running on port 5432
:
nc -zv localhost 5432
Connection to localhost port 5432 [tcp/postgresql] succeeded!
docker ps -a
docker exec -it <container_id> bash
psql -U <database_username>
.
psql -U postgres
root@0dffa1473a46:/# psql -U postgres
psql (9.6.9)
Type "help" for help.
postgres=#
\l
- show all databases\c users_dev
- connect to users_dev
database.\dt
- shows list of tables in the selected databaseSELECT * FROM users;
server/tests
directory and managed by manage .py
Python file.docker-compose -f docker-compose.yml run --rm flask_demo python manage.py test
I refered a lot of online blogs, github repos and stackoverflow questions, while I was working on to create this project. A big Thank You to all these people who take time from their regular work and write Blog, answers questions and post their code online, so that someone like me could learn from those posts and come up with something of their own. Special mention for these blog posts.