Skip to content

ashraf-minhaj/HushHub-Backend

Repository files navigation

Hush Hub Backend

Share thoughts wihtout letting them know who you are banner

main workflow  stage    Maintainability Rating  Reliability Rating 

         

see demo snap see HushHub Frontend

Application Features

  • Dockerize Application
  • Docker Hot reloading for local development
  • Multistage build
  • Separate credentials for local dev and production (.env)
  • Local docker image
  • Pull/push from the docker hub
  • Log formatting (Configure logging in application)
  • Seeding data for the application
  • Docker tool to wrap complex docker commands in a simpler format

CI/CD Features

  • Setup Production and Dev Environment servers using Ansible

  • On PR:

    • Linter
    • Unit Test
    • CodeQL
    • SonarQube, With results in PR annotations (integrated with SonarCloud)
  • On Push to feature branch:

    • Unit Test
    • Build Image
  • Deploy to dev env from feature branch

    • run dev deployment workflow by commit-msg. commit with deploy-dev message
    • run workflow by pr-comment. comment on pr - /deploy-dev
  • on CD deploy image to dockerHub

  • Implement CD from main branch to both the envs (dev, prod)

  • Implement a simple rollback job that we use the last successful image to do the deployment

  • Implement a rollback table with PRs and SHAs

  • Calculate disaster recovery time of the CI/CD

  • Notify on failed deployments with details in the email

Improvement scopes (future considerations)

  • application health check monitoring and notification system (more to come)

Rollback Table

In case of unwanted situations copy the hash from sha table and run rollback worlfow rollback

Demo

demo

setup local environment

  • Install latest version of docker in your system

  • Install python3 on your system (should come with your distro BTW)

  • Setup devtool. Go to 'tools' dir and run -

        $ pip3 install .
    
  • Now run the tool from your 'app' directory.

       $ devtool run --app-name devbackend
    
  • example devtool --help -

        Usage: devtool [OPTIONS] COMMAND [ARGS]...
    
        Options:
        --install-completion [bash|zsh|fish|powershell|pwsh]
                                        Install completion for the specified shell.
        --show-completion [bash|zsh|fish|powershell|pwsh]
                                        Show completion for the specified shell, to
                                        copy it or customize the installation.
        --help                          Show this message and exit.
    
        Commands:
        get-errors   get application errors.
        get-logs     get application logs.
        list-images  get list of images.
        ls           get list of things in current directory, use it to see if...
        run          run the application.
        stop         stop the running application.
    

    Do not run in detachable mode if you want to see live logs of the app.

Environment variable file

The file should be named as .env, devs will get the dev env from the lead. no env specific things should reside on the repository.

  ENV=dev
  PORT=8080
  DB_URL=mongodb://mongodb:27017 # for docker service
  # DB_URL=mongodb://localhost:27017
  # f"mongodb://{username}:{password}@host:port/"

Build and Push image to dockerhub

```
cd scripts/
bash build_n_push.sh <version-tag>
```

Refactoring

  • If gitignore is not taking changes, reason is Git's cache hasn't been refreshed to reflect the changes in Gitignore.

    git rm -r --cached
    git add . .
  • if you are a mac OSX user and facing permission issue please change setting on your docker-desktop application -

    In Preferences > General there is an option "Use gRPC FUSE for file sharing" which is by default checked. Uncheck that option Apply and restart.
    

ashraf minhaj