Thanks to visit codestin.com
Credit goes to github.com

Skip to content

miltonArango/fastapi-crud-async

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkedIn


Logo

Test Assignment DevOps Milton

Table of Contents
  1. About The Project
  2. Architecture
  3. Assignment
  4. Stretch Goals
  5. Getting Started
  6. Endpoints
  7. SSL Certificate Generation
  8. Database Management
  9. Database Migrations
  10. License
  11. Contact

About The Project

Product Name Screen Shot

Architecture

System Architecture

Assignment

For this assignment, I've completed the following tasks:

  1. Set up a local Gitlab instance on your device using Docker and Docker Compose.
  2. Within this Gitlab instance, create a web project that builds a Docker container serving static content.
  3. Register a Gitlab runner instance on your device with your local Gitlab instance.
  4. Write a gitlab-ci.yml file to automate the build and deployment of your service using the Gitlab runner connected in the previous step.

Stretch Goals

All the following goals have been completed as well:

  • Test your service after each build and deploy only if the tests are successful.
  • Serve the web content not directly through a port but using a reverse proxy, making it accessible through the URL http://mywebapp.localtest.me/.
    • Add a second static content service behind the proxy.
    • Enable secure HTTPS communication.
    • Provide detailed steps on how to automatically generate SSL certificates, as local generation is not possible.
  • Connect your application to a Dockerized database and serve some content from it.
    • Explain how you manage the state of the database.
    • Describe your approach to running migrations.
  • Implement a login mechanism for all your web services.
    • You can use Basic Auth.
    • Consider using a separate service.
    • Implement both of the above options on individual services.

(back to top)

Built With

  • Gitlab
  • postgres
  • fastapi
  • aws
  • vscode
  • go
  • python
  • docker

(back to top)

Getting Started

The project works with docker compose to spin up all the containers necessary to execute the services.

Prerequisites

  • Generating locally signed certificates for HTTPS using mkcert
    cd nginx/certs
    mkcert "mywebapp.localtest.me"
    mkcert "auth.localtest.me"
    mkcert "go.localtest.me"
  • Install Docker

Installation

  1. Configure an OAuth application on a suitable provider (GitHub, Google, Facebook, ...).
  2. Fill in the necessary environment variables in a .env file.
  3. Run the Docker compose stack.
    export DATABASE_URL=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
    docker compose up -d --build

(back to top)

Endpoints

(back to top)

SSL Certificate Generation

  1. For the SSL certificate generation we can add a certbot container to automatically create the SSL certificates using Let's Encrypt
  2. Create a Cron job in the container to trigger a re-creation of the certificates when they are close to expire.
  3. Reset the Nginx service once a certificate renewal is triggered by the Cron job.

(back to top)

Database Management

  1. The provisioning of the Database is handled by the docker compose file configuration, using environment variables to set the necessary configuration options for the database.
  2. The connection and transactions to the database are handled by an ORM (SQLAlchemy) which acts as a repository interface to perform CRUD operations on the database.
  3. Docker also provisions a volume to store the data of the database service, the volume is transitory and will be deleted when the compose stack is taken down. For a persistent volume there's an option for named volumes in docker.

(back to top)

Database Migrations

  1. When a change in the database schema is necessary we can use migrations to adapt to new schema requirements while also enabling rollbacks to a previous state.
  2. In Python the migrations can be done by modifying the ORM model objects and initializing a migration tool like Alembic for the SQLAlchemy case.
  3. Additional SQL code can be specified to deal with null values or data consistency issues.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

Milton Arango - @miltonarango - [email protected]

(back to top)

About

FastAPI CRUD

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 78.0%
  • Go 16.1%
  • Dockerfile 5.9%