Local Development - green-ecolution/backend GitHub Wiki
The following dependencies are required to start the backend:
-
Golang as the programming language (
>=1.24
) - Make as a build helper
- Docker is not strictly required but highly recommended
The installation depends on the operating system and is not described here (see Golang documentation). The required tools can be installed using make as follows:
make setup # for linux
make setup/macos # for macOS
make setup
installs all necessary tools. Additional dependencies required by the system are described in the following sections.
On Linux, additional dependencies need to be installed.
yq
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && \
chmod +x /usr/bin/yq
[!NOTE]
There are different versions of yq. The required version is: https://github.com/mikefarah/yq
sops/age
sudo pacman -S sops age
The latest sops releases can be found at https://github.com/getsops/sops/releases. At the time of writing, the latest version is v3.9.4 and can be installed with:
# Download the binary
curl -LO https://github.com/getsops/sops/releases/download/v3.9.4/sops-v3.9.4.linux.amd64
# Move the binary in to your PATH
mv sops-v3.9.4.linux.amd64 /usr/local/bin/sops
# Make the binary executable
chmod +x /usr/local/bin/sops
A nix shell via flake is available 🤓
nix develop
make setup/macos
installs all additional dependencies using brew. Ensure that brew is installed and active: https://brew.sh/
The Windows-only development environment is not supported by us and is not described here. Use WSL and skip to the Linux setup chapter. Or go your own way and find all the necessary dependencies for Windows and run them that way (but don't blame us).
The configuration files are located under config/
and are encrypted in this repository. They can be decrypted using sops
. To decrypt the configurations, the private key must be available. The private key is stored securely (e.g., in Vaultwarden) and can be downloaded from there. It must be placed in the file $XDG_CONFIG_HOME/age/keys.txt
(see sops docs for more informationen).
make config/dec ENV=[dev,stage,prod] # default: dev
make
decrypts the configurations and places them under config/
. The application will not start if the configuration is not decrypted. If the configuration is modified, it must be re-encrypted before committing it to the repository.
make config/all # encrypts all configurations
make config/enc ENV=[dev,stage,prod] # default: dev
If you don't have access to the private sops key, you will need to create your own configuration. Create a configuration file (e.g. config/config.dev.yaml
) and fill it with the values mentioned in Configuration.
The application requires various infrastructure components to function. These components are packaged in Docker containers and can be started using docker-compose
make infra/up # starts the infrastructure
make infra/down # stop the infrastructure
The infrastructure consists of the following components:
-
postgres
(database) -
pgadmin
(database management tool) -
valhalla
(routing) -
ors
(routing) -
vroom
(routing optimizing)
A PostgreSQL database is started as part of the Docker Compose infrastructure. It uses default configurations and can be managed via pgAdmin. The database is initialized with migration files.
make migrate/reset && make migrate/up && make seed/up
The database can be managed via pgAdmin, a web interface for PostgreSQL. It is accessible at http://localhost:5050
The application can also be started using Docker. This approach has the advantage that it runs in an isolated environment without requiring dependencies to be installed on the host system. This means that system dependencies like proj
or geos
do not need to be installed manually.
To start the application via Docker, the configuration files must be correctly placed. sops/age
is required along with the organization's private key to decrypt the encrypted configuration files in the repository so that Docker can use them (or use your own configuration file).
Once the configuration files are available, the process can be started with:
make run/docker ENV=[dev,stage,prod] # default dev
Once all configurations such as database and credentials are set up, the application can be launched. The Go application can be run using go run .
or air
. air' provides a hot reload mechanism for Golang applications. These commands are also bundled in the make file
make run # execute binary
make run/live # execute air for hot reload