Allow changing the port

This introduces a new application option `--port`/`-p` to switch the
listening port from 3000 (default) to another port.

Docker image can be configured using the corresponding environment
variable `GITEA_SQ_BOT_PORT`.

Helm Chart allows setting `.Values.app.listeningPort`

Resolves: #25

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
This commit is contained in:
justusbunsi 2022-06-17 13:34:06 +02:00
parent 471b25e682
commit eb3cb301fc
No known key found for this signature in database
GPG key ID: 82B29BF2507F9F8B
8 changed files with 56 additions and 19 deletions

View file

@ -1,5 +1,19 @@
# Changelog
## v0.2.1
### 🤖 Application
- Allow configuring listening port
### 🐳 Docker image
- Add `GITEA_SQ_BOT_PORT` environment variable
### ☸️ Helm Chart
- Add `.Values.app.listeningPort` parameter
## v0.2.0
### 🤖 Application

View file

@ -41,6 +41,7 @@ ENV HOME=/home/bot
EXPOSE 3000
ENV GIN_MODE "release"
ENV GITEA_SQ_BOT_CONFIG_PATH "/home/bot/config/config.yaml"
ENV GITEA_SQ_BOT_PORT "3000"
VOLUME ["/home/bot/config/"]
RUN ["chmod", "+x", "/usr/local/bin/docker-entrypoint.sh"]

View file

@ -53,6 +53,15 @@ See [config.example.yaml](config/config.example.yaml) for a full configuration s
## Installation
Supported environment variables for application runtime configuration:
| Environment Variable | Purpose |
|-----------------------------|---------------------------------|
| `GITEA_SQ_BOT_PORT` | Port the bot will listen on |
| `GITEA_SQ_BOT_CONFIG_PATH` | Full path to configuration file |
For detailed information, use the `--help` flag.
### Docker
Create a directory `config` and place your [config.yaml](config/config.example.yaml) inside it. Open a terminal next to this directory

View file

@ -16,9 +16,9 @@ import (
func main() {
app := &cli.App{
Name: "gitea-sonarqube-pr-bot",
Name: "gitea-sonarqube-bot",
Usage: "Improve your experience with SonarQube and Gitea",
Description: `By default, gitea-sonarqube-pr-bot will start running the webserver if no arguments are passed.`,
Description: `Start an instance of gitea-sonarqube-bot to integrate SonarQube analysis into Gitea Pull Requests.`,
Action: serveApi,
Flags: []cli.Flag{
&cli.PathFlag{
@ -29,6 +29,13 @@ func main() {
EnvVars: []string{"GITEA_SQ_BOT_CONFIG_PATH"},
TakesFile: true,
},
&cli.IntFlag{
Name: "port",
Aliases: []string{"p"},
Value: 3000,
Usage: "Port the bot will listen on.",
EnvVars: []string{"GITEA_SQ_BOT_PORT"},
},
},
}
@ -49,5 +56,5 @@ func serveApi(c *cli.Context) error {
sqHandler := api.NewSonarQubeWebhookHandler(giteaSdk.New(), sonarQubeSdk.New())
server := api.New(giteaHandler, sqHandler)
return endless.ListenAndServe(":3000", server.Engine)
return endless.ListenAndServe(fmt.Sprintf(":%d", c.Int("port")), server.Engine)
}

View file

@ -2,7 +2,7 @@ apiVersion: v2
name: gitea-sonarqube-bot
description: A Helm Chart for running a bot to communicate between both Gitea and SonarQube
type: application
version: 0.2.0
version: 0.2.1
appVersion: "v0.2.0"
home: https://codeberg.org/justusbunsi/gitea-sonarqube-bot/
maintainers:

View file

@ -53,19 +53,20 @@ You can find a full changelog in the [main repository](https://codeberg.org/just
### App parameters
| Name | Description | Value |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| `app.configLocationOverride` | Override the default location of the configuration file (`/home/bot/config/config.yaml`). **Available since Chart version `0.2.0`. Requires at least image tag `v0.2.0`**. (See values file for details) | `""` |
| `app.configuration.gitea.url` | Endpoint of your Gitea instance. Must be expandable by '/api/v1' to form the API base path as shown in Swagger UI. | `""` |
| `app.configuration.gitea.token.value` | Gitea token as plain text. Can be replaced with `file` key containing path to file. | `""` |
| `app.configuration.sonarqube.url` | Endpoint of your SonarQube instance. Must be expandable by '/api' to form the API base path. | `""` |
| `app.configuration.sonarqube.token.value` | SonarQube token as plain text. Can be replaced with `file` key containing path to file. | `""` |
| `app.configuration.sonarqube.additionalMetrics` | Setting this option you can extend that default list by your own metrics. | `[]` |
| `app.configuration.projects[0].sonarqube.key` | Project key inside SonarQube | `""` |
| `app.configuration.projects[0].gitea.owner` | Repository owner inside Gitea | `""` |
| `app.configuration.projects[0].gitea.name` | Repository name inside Gitea | `""` |
| `volumes` | If token and webhook secrets shall be provided via file, volumes and volume mounts can be configured to setup the environment accordingly | `[]` |
| `volumeMounts` | If token and webhook secrets shall be provided via file, volumes and volume mounts can be configured to setup the environment accordingly | `[]` |
| Name | Description | Value |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
| `app.configLocationOverride` | Override the default location of the configuration file (`/home/bot/config/config.yaml`). **Available since Chart version `0.2.0`. Requires at least image tag `v0.2.0`**. (See values file for details) | `""` |
| `app.listeningPort` | Port the application will listening on inside the pod container. **Available since Chart version `0.2.1`. Requires at least image tag `v0.2.1`**. | `3000` |
| `app.configuration.gitea.url` | Endpoint of your Gitea instance. Must be expandable by '/api/v1' to form the API base path as shown in Swagger UI. | `""` |
| `app.configuration.gitea.token.value` | Gitea token as plain text. Can be replaced with `file` key containing path to file. | `""` |
| `app.configuration.sonarqube.url` | Endpoint of your SonarQube instance. Must be expandable by '/api' to form the API base path. | `""` |
| `app.configuration.sonarqube.token.value` | SonarQube token as plain text. Can be replaced with `file` key containing path to file. | `""` |
| `app.configuration.sonarqube.additionalMetrics` | Setting this option you can extend that default list by your own metrics. | `[]` |
| `app.configuration.projects[0].sonarqube.key` | Project key inside SonarQube | `""` |
| `app.configuration.projects[0].gitea.owner` | Repository owner inside Gitea | `""` |
| `app.configuration.projects[0].gitea.name` | Repository name inside Gitea | `""` |
| `volumes` | If token and webhook secrets shall be provided via file, volumes and volume mounts can be configured to setup the environment accordingly | `[]` |
| `volumeMounts` | If token and webhook secrets shall be provided via file, volumes and volume mounts can be configured to setup the environment accordingly | `[]` |
### Security parameters

View file

@ -31,14 +31,16 @@ spec:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.app.configLocationOverride }}
env:
{{- if .Values.app.configLocationOverride }}
- name: GITEA_SQ_BOT_CONFIG_PATH
value: "{{ .Values.app.configLocationOverride }}"
{{- end}}
- name: GITEA_SQ_BOT_PORT
value: "{{ .Values.app.listeningPort }}"
ports:
- name: http
containerPort: 3000
containerPort: {{ .Values.app.listeningPort }}
protocol: TCP
livenessProbe:
httpGet:

View file

@ -57,6 +57,9 @@ app:
# Setting this will also change the mount point for `.Values.app.configuration` to the directory part of the override value.
configLocationOverride: ""
# @param app.listeningPort Port the application will listening on inside the pod container. **Available since Chart version `0.2.1`. Requires at least image tag `v0.2.1`**.
listeningPort: 3000
# This object represents the [config.yaml](https://codeberg.org/justusbunsi/gitea-sonarqube-bot/src/branch/main/config/config.example.yaml) provided to the application.
configuration:
# Gitea related configuration. Necessary for adding/updating comments on repository pull requests