Skip to content

1. Introduction

ik-alex edited this page Jul 20, 2024 · 21 revisions

Welcome to the hng_boilerplate_java_web wiki!


This project entails setting up advanced CI/CD pipelines with GitHub Actions, integrating appropriate messaging queues, and managing the deployment of Java boilerplate projects.

ssh into your server

ssh username@server_ip

CI/CD Setup

  1. Choosing a CI/CD tool:
  • Pipeline Setup
  1. Database Installation and Setup: For this project we are going to use a PostgresDB. The following instructions below shows how to install and start the database;
  • first we have to make sure our linux server is upto date by running this command
    sudo apt update
  • install postgresDB
    sudo apt install postgresql -y
  • start the PostgreSQL database service on the linux system
    sudo systemctl start postgresql
  • configure the PostgreSQL service to start automatically at boot time on systems that use systemd (linux systems)
    sudo systemctl enable postgresql
  • check the status of the PostgreSQL service on a system that uses systemd (linux systems) for managing services
    sudo systemctl status postgresql

Create Database and user

  • Login with default user (Postgres)
    sudo -u postgres psql
  • Create a new user (admin)
    CREATE USER admin WITH PASSWORD '<password>';
  • Create a new database for dev, staging & prod
    CREATE DATABASE <db_name>;
  • Grant all privileges on the databases to the new admin
    GRANT ALL PRIVILEGES ON DATABASE <db_name> TO admin;
  • Assign database ownership to the admin user
    ALTER DATABASE <db_name> OWNER TO admin;

Messaging Queue Integration

  1. Setting up the messaging queuing system
    • Update the package list:

      sudo apt update
    • Create a bash script to run RabbitMQ server installation

      touch rabbitMQ.sh
      sudo chmod +x rabbitMQ.sh
      vim rabbitMQ.sh
    • The rabbitMQ.sh

      #!/bin/sh
      
      sudo apt-get install curl gnupg apt-transport-https -y
      
      ## Team RabbitMQ's main signing key
      curl -1sLf "https://keys.openpgp.org/vks/v1/by-fingerprint/0A9AF2115F4687BD29803A206B73A36E6026DFCA" | sudo gpg --dearmor | sudo tee /usr/share/          keyrings/com.rabbitmq.team.gpg > /dev/null
      ## Community mirror of Cloudsmith: modern Erlang repository
      curl -1sLf https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key | sudo gpg --dearmor |      sudo tee /usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg > /dev/null
      ## Community mirror of Cloudsmith: RabbitMQ repository
      curl -1sLf https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key | sudo gpg --dearmor |  sudo tee /usr/share/keyrings/rabbitmq.9F4587F226208342.gpg > /dev/null
      
      ## Add apt repositories maintained by Team RabbitMQ
      sudo tee /etc/apt/sources.list.d/rabbitmq.list <<EOF
      ## Provides modern Erlang/OTP releases
      ##
      deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu  jammy main
      deb-src [signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa1.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu jammy  main
      
      # another mirror for redundancy
      deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa2.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu  jammy main
      deb-src [signed-by=/usr/share/keyrings/rabbitmq.E495BB49CC4BBE5B.gpg] https://ppa2.novemberain.com/rabbitmq/rabbitmq-erlang/deb/ubuntu jammy main
      
      ## Provides RabbitMQ
      ##
      deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu  jammy main
      deb-src [signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa1.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu jammy main
      
      # another mirror for redundancy
      deb [arch=amd64 signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa2.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu    jammy main
      deb-src [signed-by=/usr/share/keyrings/rabbitmq.9F4587F226208342.gpg] https://ppa2.novemberain.com/rabbitmq/rabbitmq-server/deb/ubuntu jammy  main
      EOF
      
      ## Update package indices
      sudo apt-get update -y
      
      ## Install Erlang packages
      sudo apt-get install -y erlang-base \
                         erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
                         erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
                         erlang-runtime-tools erlang-snmp erlang-ssl \
                         erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl
      
      ## Install rabbitmq-server and its dependencies
      sudo apt-get install rabbitmq-server -y --fix-missing
      • Execute the RabbitMQ server script
        ./rabbitMQ.sh
      • Enable the RabbitMQ Sevrer Management Plugin
        sudo rabbitmq-plugins enable rabbitmq_management
      • Create RabbitMQ User and set Permmisions
        sudo rabbitmqctl set_permissions -p / guest ".*" ".*" ".*"
      • Update the configuration files
        sudo nano /etc/rabbitmq/rabbitmq.conf
      • Exit and restart the server.
        sudo systemctl restart rabbitmq-server