# Development ## Setup If you haven't installed Go on your system yet, follow the [golang installation guide](https://golang.org/doc/install). To get your local setup going, run `make bootstrap`. It will install all required dependencies as well as setting up our git hooks. Run `make help` to get an overview of available make targets. The project can be compiled using `make build`. This should create a binary which can then be executed. Alternatively, the `go run ./cmd/poseidon` command can be used to automatically compile and run the project. ## Tests As testing framework we use the [testify](https://github.com/stretchr/testify) toolkit. Run `make test` to run the unit tests. ### Mocks For mocks we use [mockery](https://github.com/vektra/mockery). You can create a mock for the interface of your choice by running ```bash make mock name=INTERFACE_NAME pkg=./PATH/TO/PKG ``` on a specific interface. For example, for an interface called `ExecutorApi` in the package `nomad`, you might run ```bash make mock name=ExecutorApi pkg=./nomad ``` If the interface changes, you can rerun this command (deleting the mock file first to avoid errors may be necessary). Mocks can also be generated by using mockery directly on a specific interface. To do this, first navigate to the package the interface is defined in. Then run ```bash mockery \ --name=<> \ --structname=<>Mock \ --filename=<>Mock.go \ --inpackage ``` For example, for an interface called `ExecutorApi` in the package `nomad`, you might run ```bash mockery \ --name=ExecutorApi \ --structname=ExecutorAPIMock \ --filename=ExecutorAPIMock.go \ --inpackage ``` Note that per default, the mocks are created in a `mocks` sub-folder. However, in some cases (if the mock implements private interface methods), it needs to be in the same package as the interface it is mocking. The `--inpackage` flag can be used to avoid creating it in a subdirectory. ### End-to-end tests For e2e tests we provide a separate package. e2e tests require the connection to a Nomad cluster. Run `make e2e-tests` to run the e2e tests. This requires Poseidon to be already running. Instead, you can run `make e2e-docker` to run the API in a Docker container, and the e2e tests afterwards. You can use the `DOCKER_OPTS` variable to add additional arguments to the Docker run command that runs the API. By default, it is set to `-v $(shell pwd)/configuraton.yaml:/configuration.yaml`, which means, your local configuration file is mapped to the container. If you don't want this, use the following command. ```shell $ make e2e-docker DOCKER_OPTS="" ``` ## Coding Style ### Git hooks The repository contains a git pre-commit hook which runs the go formatting tool `gofmt` to ensure the code is formatted properly before committing. To enable them, run `make git-hooks`. ### Linter To lint our source code and ensure a common code style in the codebase we use [Golang CI Lint](https://golangci-lint.run/usage/install/#local-installation) as a linter. Use `make lint` to execute it. ## Continuous Integration We use the Gitlab CI to automatically build the project, run unit and e2e-tests, perform an automated dependency check and deploy instances of the API. ### Docker The CI builds a Docker image and pushes it to our Docker registry at `drp.codemoon.xopic.de`. In order to pull an image from the registry you have to login with `sudo docker login drp.codemoon.xopic.de`. Execute `sudo docker run -p 7200:7200 drp.codemoon.xopic.de/` to run the image locally. You can find the image name in the `dockerimage` CI job. You can then interact with the webserver on your local port 7200. You can also build the Docker image locally by executing `make docker` in the root directory of this project. It builds the binary first and a container with the tag `poseidon:latest` afterwards. You can then start a Docker container with `sudo docker run --rm -p 7200:7200 poseidon:latest`.