From eb3cb301fc75827319ccb155c4e5002968430963 Mon Sep 17 00:00:00 2001 From: justusbunsi Date: Fri, 17 Jun 2022 13:34:06 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 14 ++++++++++++++ Dockerfile | 1 + README.md | 9 +++++++++ cmd/gitea-sonarqube-bot/main.go | 13 ++++++++++--- helm/Chart.yaml | 2 +- helm/README.md | 27 ++++++++++++++------------- helm/templates/deployment.yaml | 6 ++++-- helm/values.yaml | 3 +++ 8 files changed, 56 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab9182b..d33dfda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Dockerfile b/Dockerfile index 93bf360..c6f3eec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index be3fcb3..d030330 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/gitea-sonarqube-bot/main.go b/cmd/gitea-sonarqube-bot/main.go index 42b5de3..4cf2821 100644 --- a/cmd/gitea-sonarqube-bot/main.go +++ b/cmd/gitea-sonarqube-bot/main.go @@ -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) } diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 13162e1..6061391 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -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: diff --git a/helm/README.md b/helm/README.md index 20ba017..a7cb6cf 100644 --- a/helm/README.md +++ b/helm/README.md @@ -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 diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml index 481b9d3..b5b84c4 100644 --- a/helm/templates/deployment.yaml +++ b/helm/templates/deployment.yaml @@ -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: diff --git a/helm/values.yaml b/helm/values.yaml index 377758b..d42d99e 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -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