GithubHelp home page GithubHelp logo

peroxy / starsky-backend Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 717 KB

Starsky is a management application for employee scheduling.

License: MIT License

Dockerfile 0.09% Java 99.91%
scheduling schedule employee employee-management starsky starsky-backend employee-scheduling

starsky-backend's Introduction

Starsky backend โญ

Starsky backend represents the API and database portion of starsky application for employee scheduling. It uses Java (Spring Boot) for REST API, PostgreSQL for data storage and Nginx for reverse proxy in production.

Front-end React application is located in a repository called starsky-frontend.

It also uses the transactional email API that is located in a repository called starsky-mail.

Requirements ๐Ÿ“‹

Development ๐Ÿ’ป

Running with docker

Please note that this has only been tested with docker on Ubuntu 20.04.

  1. Download source files and go to docker directory:
git clone https://github.com/peroxy/starsky-backend.git
cd starsky-backend/docker
  1. Build and run the entire stack:
docker-compose up
  1. You will now be able to access:

You can access the starsky database by using credentials (this can be changed in the docker-compose.override.yml file):

  • username: starsky
  • password: starsky

Debugging

You can run the API locally using your favorite Java IDE:

  1. Run the database:
cd starsky-backend/docker
docker-compose up database
  1. Set Spring active profiles: dev and local
  2. Run and debug the application

Testing

We are using JUnit5 for tests with Spring Boot. An in-memory H2 database is used.

No extra configuration is needed, just run: gradle test

OpenAPI client

You can generate an OpenAPI client by running backend API locally, then running (for example TypeScript client):

docker run --rm --network host -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i http://localhost:8080/api/v3/api-docs -g typescript -o /local/out/ts

Deployment ๐Ÿš€

We host entire infrastructure on Azure, specifically using Azure Virtual Machine.

Server requirements

The server (in our case Azure VM) must have these installed:

Setup on Azure Virtual Machine:

  1. Create Azure Virtual Machine with Ubuntu installed and setup your public SSH key. Ubuntu 18.04 was used at the time of writing this.

  2. Enable SSH (port 22) and whitelist your IP.

  3. Connect to your machine:

    ssh username@ipAddress
  4. Install docker:

    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo usermod -aG docker <your-user>

    Log out and log back in to be able to use docker without sudo.

  5. Install docker-compose:

     sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
     sudo chmod +x /usr/local/bin/docker-compose
  6. Generate a SSH key:bb

    ssh-keygen -t rsa -b 4096 -c "starsky_deploy"

SSL Setup

Currently, SSL is done manually by using ZeroSSL and copying certificates to Azure VM.

  1. Generate a certificate, you will get 3 files: certificate.crt, private.key, ca_bundle.crt.
  2. Copy them to Azure VM with rsync:
cd ~/certs
rsync ./* user@host:~/certs
  1. Restart Nginx on Azure VM.

Repository secrets

These are the required secrets that should be stored inside Github repository secrets:

  • Dockerhub:
  • PostgreSQL:
    • POSTGRES_USER
    • POSTGRES_PASSWORD - don't make it too long, there were some issues with authentication with a 128 character password, even though it should be supported in theory...
  • Server host (Azure VM):
    • REMOTE_HOST - remote host IP address / domain to SSH into
    • REMOTE_USER - username to SSH with
    • SERVER_SSH_KEY - private SSH key (OpenSSH, for example the contents of your ~/.ssh/id_rsa key) to connect to your server
  • API:
    • STARSKY_JWT_SECRET - needed for generating JWT tokens, use a random 32 character secret
    • STARSKY_FRONTEND_REGISTER_URL - needed to send invite links with proper URL

How to deploy

Push a tag *.*.* (e.g. 1.0.3) to master branch and it will automatically deploy everything via Github workflow. See .github/main.yml workflow for more info.

In short, it does this if it gets triggered by a new tag:

  • Takes source code from master branch and extracts the newest version from tag.
  • Configures environment variables used by docker containers from Github repository's secrets.
  • Builds and pushes all apps as Docker images to DockerHub.
  • Copies environment variables and docker-compose files to Azure VM.
  • Stops starsky-backend containers on Azure VM, pulls the newest images and starts the containers again.

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.