Skip to main content

Build From Source

In this document manual procedures are explained (without make and continuous integration).

Prerequisites

For Windows developers, make sure you're using Windows 10 or later. And if you have Git for Windows installed, you can use Git Bash to run the commands in this document. Otherwise, please use PowerShell instead of CMD.

Get Source Code

Clone the repository with --depth=1 to avoid downloading the entire history.

$ git clone --depth=1 https://github.com/anyshake/observer

If you don't have git installed, you can download the source code as a .zip or .tar.gz archive, extract it and cd into the directory. However, you will not be able to update the source code with git pull.

Build Docs

Install swag by running go install command.

$ go install github.com/swaggo/swag/cmd/swag@latest

Check if swag is installed successfully.

$ swag --version
swag version v1.16.2

In root directory, use swag init to generate Swagger docs.

$ swag init -d ./ -o ./docs -g ./cmd/main.go

Build Frontend

Go to the frontend directory.

$ cd frontend

Install dependencies and build the frontend.

$ cd frontend/src
$ npm install
$ npm run build

Build Backend

Go back to the repository root directory to build backend binary.

$ CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath -o observer cmd/*.go

If you're using Windows with PowerShell, please use the following command instead.

$ $env:CGO_ENABLED=0
$ go build -ldflags="-s -w" -trimpath -o observer.exe cmd/*.go

The output file will be observer (Windows is observer.exe), test it with -version or -help flag.