Categorygithub.com/wwi21seb-projekt/server-beta
module
0.0.0-20240728120420-5df9c1d22f7a
Repository: https://github.com/wwi21seb-projekt/server-beta.git
Documentation: pkg.go.dev

# README

Server Beta

Second backend for group project

Pipelines

Tests
Deployment

Prerequisites

Make sure you have the following tools and services installed, configured and running on your system:

    apt-get install git
    apt-get install make
    wget https://golang.org/dl/go1.21.4.linux-amd64.tar.gz
    rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.4.linux-amd64.tar.gz
    export PATH=$PATH:/usr/local/go/bin
    apt-get install postgresql
    sudo -u postgres psql
    CREATE DATABASE serverbetadb;
    CREATE USER goserveruser WITH PASSWORD 'password';
    GRANT ALL PRIVILEGES ON DATABASE serverbetadb TO goserveruser;

The necessary tables are created automatically by the server when it is started for the first time.

    apt-get install nginx

To use nginx as a reverse proxy, change the configuration file in /etc/nginx/sites-available/default to the configuration specified in the nginx.conf file in the root directory of the project. Restart the nginx service with sudo systemctl restart nginx after changing the configuration.

With a nginx reverse proxy, the server can be accessed via the domain name or IP address of the server. Additionally, with e.g. Let's Encrypt, a free SSL certificate can be obtained to secure the connection to the server.

    apt install certbot
    apt install python3-certbot-nginx
    certbot --nginx

Usage

Clone the repository, build the project and run the server with the following commands:

git clone https://github.com/wwi21seb-projekt/server-beta.git
cd server-beta
make all
./bin/server-beta -port 8080

If no port is specified, the server will run on the default port :8080.

Additionally, the user needs to create an .env file with the following information. An example .env file (.env.example) can be found in the root directory of the project.

VariableDescription
JWT_SECRETSecret key for JSON Web Token (JWT) authentication
DB_HOSTHostname or IP address of the PostgreSQL database server
DB_PORTPort number of the PostgreSQL database server
DB_SSL_MODESSL mode for the database connection (e.g., disable, require, etc.)
DB_NAMEName of the PostgreSQL database
DB_USERUsername for the PostgreSQL database
DB_PASSWORDPassword for the PostgreSQL database
PROXY_HOSTHostname or IP address of the proxy server
SERVER_URLURL of the server
EMAIL_HOSTHostname or IP address of the email server
EMAIL_PORTPort number of the email server
EMAIL_ADDRESSEmail address used for sending emails
EMAIL_PASSWORDPassword for the email address
VAPID_PRIVATE_KEYVAPID private key for web push notifications
VAPID_PUBLIC_KEYVAPID public key for web push notifications
GIN_MODEMode of the application (e.g., debug, release)

In deployment, a systemctl service can be created to run the server as a service. The following steps are necessary to create a service:

  1. Create a new service file in /etc/systemd/system/server-beta.service with the content specified in the server-beta.service file in the root directory of the project.
  2. Reload the systemctl daemon.
    systemctl daemon-reload
  1. To automatically start the server on boot, enable the service.
    systemctl enable server-beta
  1. Start the server.
    systemctl start server-beta
  1. Check the status of the server.
    systemctl status server-beta

The logs of the server can be viewed using the journalctl commands.

    journalctl -u server-beta

CI/CD-Pipeline

The project uses GitHub Actions for continuous integration and continuous deployment. The workflows are specified in the .yaml-files in the .github/workflows-directory.

To use the CD-Pipeline in GitHub Actions, SSH access to the server, where the project shall be deployed, must be configured. In order for the pipeline to work, several secrets in the GitHub Repository settings. The following secrets are needed:

VariableDescription
SERVER_APP_PATHFile path where the built executable file is placed on the server
SERVER_HOSTIP address of the server
SERVER_SSH_PORTOpen SSH Port of the server
SERVER_SSH_PRIVATEPrivate SSH key to access the server
SERVER_SSH_PublicPublic SSH key to access the server
SERVER_USERUsername of the user that accesses the server using SSH

# Packages

No description provided by the author