Skip to content

An open-source HTML to PDF document converter. (Python, PostgreSQL, Celery, RabbitMQ, Redis, Terraform, AWS (RDS, S3, ECR), Docker, Kubernetes)

Notifications You must be signed in to change notification settings

mustafaelghrib/docorvter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docorvter

A platform for converting HTML and Docx documents to PDF files.

Features

  • Convert HTML and Docx files to PDF files
  • Convert PDF files to HTML and Docx files
  • Convert multiple documents at the same time as the converting process work in the background
  • Manage all converted documents, you could see a list of all files and delete or get more details about each one
  • You could download converted documents, and bulk download list of documents at the same time

Architecture

The backend API is built based on the monolithic architecture and has those modules:

  • Users Module: A module for registering and logining users
  • Files Module: A module for manging files
  • Document Converter Module: A module for converting documents
  • Converter Module: A module for request to convert files and contain the document converter module

Tech Stacks

  • Backend: Python, Django, PostgreSQL, Celery, RabbitMQ, Redis
  • Infrastructure: Terraform, Amazon Web Services (AWS)
  • Deployment: Docker, Kubernetes

The Development Environment:

Run The Backend Locally:

  • Copy backend/.env.sample/.env.development to backend/.env/.env.development and update it.
  • Run The Backend API:
    docker compose -f backend/.docker-compose/development.yml up -d --build

Run The Tests:

  • Run Pytest:
    docker exec -it backend_development_django /bin/bash -c "/opt/venv/bin/pytest -rP"
  • Run Pytest Coverage:
    docker exec -it backend_development_django /bin/bash -c "/opt/venv/bin/pytest --cov=."

Docs:

  • Check Docs Coverage:
    docker exec -it backend_development_django /bin/bash -c "/opt/venv/bin/interrogate -v ."
  • Check Docs Style:
    docker exec -it backend_development_django /bin/bash -c "/opt/venv/bin/pydocstyle ."
  • Copy docs and mkdocs.yml to The Container:
    docker cp mkdocs.yml backend_development_django:/mkdocs.yml
    docker cp docs backend_development_django:/docs
  • Show Docs Locally:
    docker exec -it backend_development_django /bin/bash -c "cd .. && /opt/venv/bin/mkdocs serve --dev-addr 127.0.0.1:9000"
  • Deploy Docs to GitHub Pages:
    docker exec -it backend_development_django /bin/bash -c "cd .. && /opt/venv/bin/mkdocs gh-deploy"

The Production Environment:

Run The Backend Locally:

  • Setup and run the infrastructure
  • Get the environment variables from the infrastructure:
    python scripts/get_infra_output.py --c=infrastructure/.docker-compose.yml --m=aws --f=env
  • Copy backend/.env.sample/.env.production to backend/.env/.env.production and update it.
  • Run The Backend API:
    docker compose -f backend/.docker-compose/production.yml up -d --build

Deploy Manually on Minikube with Docker and Kubernetes:

  • Export Values:

    export ENVIRONMENT=production;
    export PROJECT_NAME=docorvter;
    export DOCKER_HUB=mustafaabdallah;
    export FINAL_IMAGE=$DOCKER_HUB/$PROJECT_NAME
    export NAMESPACE="$PROJECT_NAME-namespace"
  • Build a Docker Image:

    docker build -t $FINAL_IMAGE -f backend/Dockerfile backend --build-arg ENVIRONMENT=$ENVIRONMENT
  • Push to Docker Hub:

    docker push $FINAL_IMAGE
  • Run The Image Locally:

    python3 scripts/run_backend.py --env=backend/.env/.env.production --image=$FINAL_IMAGE
  • Create a Namespace

    kubectl create namespace $NAMESPACE
  • Create Kubernetes secret from the env file

    kubectl create secret generic "$PROJECT_NAME-env-secrets" \
    --from-env-file=.env/.env.production \
    --namespace=$NAMESPACE
  • Apply Kubernetes deployment and service

    kubectl apply -f kubernetes/deployment.yml
    kubectl apply -f kubernetes/service.yml
  • Change namespace

    kubectl config set-context --current --namespace=$NAMESPACE
  • Launch the app

    minikube service -n $NAMESPACE --url $PROJECT_NAME
  • Delete a Namespace

    kubectl delete namespace $NAMESPACE

Infrastructure

Setup Terraform Backend:

  • Set Bucket Name:
    export BUCKET_NAME=docorvter-terraform-backend;
  • Create a Bucket on AWS S3.
    aws s3api create-bucket --bucket $BUCKET_NAME --region us-east-1
  • Empty The Bucket
    aws s3 rm s3://$BUCKET_NAME --recursive
  • Delete The Bucket
    aws s3api delete-bucket --bucket $BUCKET_NAME
  • Create a file and name it to .backend.hcl under infrastructure folder.
  • Copy the content of file .backend.hcl.sample inside it and fill the values.

Setup Secrets:

  • Create a file with the name .secrets.auto.tfvars under infrastructure folder.
  • Copy the contents of file .secrets.auto.tfvars.sample inside it and fill the values.

Run Terraform Commands:

  • terraform init
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform init -backend-config=.backend.hcl

  • terraform plan all
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform plan
  • terraform plan aws
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform plan -target="module.aws"

  • terraform apply all
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform apply --auto-approve
  • terraform apply aws
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform apply -target="module.aws" --auto-approve

  • terraform destroy all
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform destroy --auto-approve
  • terraform destroy aws
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform destroy -target="module.aws" --auto-approve

  • terraform output aws
    docker compose -f infrastructure/.docker-compose.yml run --rm terraform output aws

About

An open-source HTML to PDF document converter. (Python, PostgreSQL, Celery, RabbitMQ, Redis, Terraform, AWS (RDS, S3, ECR), Docker, Kubernetes)

Topics

Resources

Stars

Watchers

Forks