GithubHelp home page GithubHelp logo

miltonarango / fastapi-crud-async Goto Github PK

View Code? Open in Web Editor NEW

This project forked from testdrivenio/fastapi-crud-async

0.0 0.0 0.0 699 KB

FastAPI CRUD

License: MIT License

Python 78.05% Dockerfile 5.89% Go 16.07%

fastapi-crud-async's Introduction

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)

fastapi-crud-async's People

Contributors

amirtds avatar miltonarango avatar mjhea0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.