diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 03d9663..9fdbfe1 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,4 +1,4 @@ -name: Publish Docker image +name: Publish new release on: push: tags: @@ -10,22 +10,30 @@ jobs: steps: - name: Check out the repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Push to Docker Hub - uses: docker/build-push-action@v1 + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: maibornwolff/opsbot - tag_with_ref: true + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push image to GitHub Container Registry + env: + GITHUB_REF: ${{ github.ref }} + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/opsbot + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + TAG=${GITHUB_REF//refs\/tags\/v} + docker build . -t $IMAGE_ID:$TAG --push - name: Prepare helm chart env: GITHUB_REF: ${{ github.ref }} run: | sed -i 's/0.0.1/'"${GITHUB_REF//refs\/tags\/v}"'/' deploy/helm/opsbot/Chart.yaml - sed -i 's/v0.0.1/'"${GITHUB_REF//refs\/tags\/}"'/' deploy/helm/opsbot/values.yaml + sed -i 's/0.0.1/'"${GITHUB_REF//refs\/tags\/v}"'/' deploy/helm/opsbot/values.yaml - name: Publish helm chart uses: stefanprodan/helm-gh-pages@master @@ -34,7 +42,6 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - name: Create Release - id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -43,4 +50,3 @@ jobs: release_name: Release ${{ github.ref }} draft: false prerelease: false - diff --git a/Dockerfile b/Dockerfile index 3b9209a..bc1d741 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-slim +FROM python:3.11-slim COPY requirements.txt /requirements.txt RUN pip install -r /requirements.txt diff --git a/README.md b/README.md index 0dc760e..60fed8e 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,15 @@ The Bot in Teams has to be configured with the public URL of the backend service After you have installed both the Bot in MS Teams, and the backend Service you need to initialize the Opsbot. This will set the Channel you issued the init command in as the default channel for the Opsbot: - @Opsbot init - +```plain +@Opsbot init +``` + You can then ask the Opsbot for a complete list of all possible commands: - @Opsbot help +```plain +@Opsbot help +``` ### Teams Bot @@ -31,10 +35,10 @@ To configure a bot in Microsoft Teams you use the Teams app "App Studio". There you can create the configuration (A json manifest file) for the Bot and install it into your teams channel. In `deploy/ms_teams` you find an example of such a manifest file. You can import and modify the provided one or create your own. In both cases you will need to create a new Bot id and password in App Studio and set those in your Backend configuration. - + ### Backend -The backend service is provided as a dockerfile which is available at [Dockerhub](https://hub.docker.com/r/maibornwolff/opsbot). +The backend service is provided as a docker image which is available in the Github Container Registry for this repo. You can use this one or build your own from this repository. In any case you have to deploy the service somewhere publicly available. #### Kubernetes @@ -44,8 +48,10 @@ For kubernetes deployment a helm template is included in the project under `depl You can install this chart with - $ helm repo add maibornwolff-opsbot https://MaibornWolff.github.io/opsbot - $ helm install my-release maibornwolff-opsbot/opsbot --values my-values.yaml +```bash +helm repo add maibornwolff-opsbot https://MaibornWolff.github.io/opsbot +helm install my-release maibornwolff-opsbot/opsbot --values my-values.yaml +``` To further simplify the deployment even more there is also a predefined helmfile (deploy/helmfile/helmfile.yaml) available. You can configure the deployment of the backend service and also provide the Opsbot configuration in one file. @@ -65,9 +71,9 @@ These plugins are currently included in OpsBot: | Plugin | Description | |---|---| | Operations | Team member can be registered with this plugin. Every day the plugin chooses an operations responsible for the day and announces him or her in the Chat. | -| Sayings | A plugin that reacts to unknown commands with an insult. | -| Jira | This plugin can check Jira for Defect tickets and it can create subtasks for an existing ticket. | -| Alerts | Checks an alertmanager for active alerts. | +| Sayings | A plugin that reacts to unknown commands with an insult. | +| Jira | This plugin can check Jira for Defect tickets and it can create subtasks for an existing ticket. | +| Alerts | Checks an alertmanager for active alerts. | This is an overview of all possible configuration parameters: @@ -152,7 +158,7 @@ actions: # Configuration for the different plugins Below you find a list of all commands, the Opsbot understands. All commands are issued by mentioning the Opsbot either in a channel or via direct message. (@Opsbot \) -##### Global commands: +#### Global commands | Command | Description | |---------|-------------| @@ -161,7 +167,7 @@ All commands are issued by mentioning the Opsbot either in a channel or via dire | unregister channel XX | Remove the channel assignment for type XX | | help | Print out the help | -##### Operations plugin: +#### Operations plugin | Command | Description | |---------|-------------| @@ -172,7 +178,7 @@ All commands are issued by mentioning the Opsbot either in a channel or via dire | morgen
tomorrow | Prints out who is the responsible tomorrow | | 'Urlaub am dd.mm.yyyy' [@user]
'Urlaub von dd.mm.yyyy bis dd.mm.yyyy' [@user]
'Urlaub dd.mm.yyyy - dd.mm.yyyy' [@user] | Add your vacation or those of another mentioned person | -##### Jira plugin: +#### Jira plugin | Command | Description | |---------|-------------| @@ -181,25 +187,28 @@ All commands are issued by mentioning the Opsbot either in a channel or via dire | fix XXX-XXXX | Solves the issue XXX-XXXX | | defects | Lists current defects | - ### Channels Opsbot supports multiple Channels. The default is always the one the `init` command was issued in. You can then tell Opsbot to send certain types of messages to another channel by sending this command: - - @Opsbot channel register defects + +```plain + @Opsbot channel register defects +``` The channel type 'defects' that is used for this example is configured in the [Jira plugin](opsbot/plugins/actions/jira.py) when it sends out scheduled messages. If there is no channel set for a type, the default one is used. There is also a deregister command to remove the association: - @Opsbot defects deregister channel +```plain + @Opsbot defects deregister channel +``` #### Available channels + | Plugin | Channel type | |---|---| | Jira | defects | -| Alerts | alerts | - +| Alerts | alerts | ## Local development @@ -212,17 +221,17 @@ Then you only need to create the `opsbot_config.yaml` file, and you can run Opsb To simplify the local development of the bot there is also a small CLI tool with which you can talk to the bot while it is running on your local machine. -The CLI sends messages to the Opsbot at `localhost:5000`. In these messages the URL the Bot is going to reply to is set to `localhost:1234`. +The CLI sends messages to the Opsbot at `localhost:5000`. In these messages the URL the Bot is going to reply to is set to `localhost:1234`. To receive those the CLI tool spins up a simple Flask server that listens on that port and echoes the responses of Opsbot. The CLI can be started with `./run_cli.sh` and understands the following commands: -* start: Start of restart the flask server -* stop: Stop the flask server -* send "": Send a message to opsbot -* quit/exit: Exit the CLI +* `start`: Start of restart the flask server +* `stop`: Stop the flask server +* `send ""`: Send a message to opsbot +* `quit`/`exit`: Exit the CLI -## Custom plugins +## Custom plugins Opsbot can be extended with new features by adding custom plugins. A custom plugin must extend the abstract `ActionPlugin` or `PersistencePlugin` class and implement their required methods. In the configuration `additional_plugin_dir` then needs to be set to the directory containing the custom plugin. diff --git a/deploy/helm/opsbot/Chart.yaml b/deploy/helm/opsbot/Chart.yaml index 3d75756..6726a38 100644 --- a/deploy/helm/opsbot/Chart.yaml +++ b/deploy/helm/opsbot/Chart.yaml @@ -1,5 +1,8 @@ -apiVersion: v1 -appVersion: "1.0" -description: A Microsoft Team bot that helps organize operational tasks +apiVersion: v2 name: opsbot +description: A Microsoft Teams bot that helps organize operational tasks +type: application version: 0.0.1 +appVersion: "0.0.1" +sources: + - https://github.com/MaibornWolff/opsbot diff --git a/deploy/helm/opsbot/templates/pvc.yaml b/deploy/helm/opsbot/templates/pvc.yaml index 0b8477a..134c681 100644 --- a/deploy/helm/opsbot/templates/pvc.yaml +++ b/deploy/helm/opsbot/templates/pvc.yaml @@ -17,4 +17,4 @@ spec: {{- if .Values.pvc.volumeName }} volumeName: {{ .Values.pvc.volumeName }} {{- end }} -{{ end }} \ No newline at end of file +{{ end }} diff --git a/deploy/helm/opsbot/templates/role.yaml b/deploy/helm/opsbot/templates/role.yaml index a8f1449..781fb0f 100644 --- a/deploy/helm/opsbot/templates/role.yaml +++ b/deploy/helm/opsbot/templates/role.yaml @@ -8,4 +8,4 @@ rules: - apiGroups: [""] resources: ["configmaps"] verbs: ["get", "create", "patch", "update", "watch"] -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/deploy/helm/opsbot/templates/rolebinding.yaml b/deploy/helm/opsbot/templates/rolebinding.yaml index 8dff26a..3d6679e 100644 --- a/deploy/helm/opsbot/templates/rolebinding.yaml +++ b/deploy/helm/opsbot/templates/rolebinding.yaml @@ -12,4 +12,4 @@ roleRef: kind: Role name: {{ include "opsbot.fullname" . }} apiGroup: rbac.authorization.k8s.io -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/deploy/helm/opsbot/templates/service.yaml b/deploy/helm/opsbot/templates/service.yaml index 72f0edd..5148fba 100644 --- a/deploy/helm/opsbot/templates/service.yaml +++ b/deploy/helm/opsbot/templates/service.yaml @@ -19,5 +19,5 @@ spec: app.kubernetes.io/name: {{ include "opsbot.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- if .Values.podLabels }} -{{- toYaml .Values.podLabels | nindent 4 }} + {{- toYaml .Values.podLabels | nindent 4 }} {{- end }} diff --git a/deploy/helm/opsbot/values.yaml b/deploy/helm/opsbot/values.yaml index 93b9f22..a28d3d5 100644 --- a/deploy/helm/opsbot/values.yaml +++ b/deploy/helm/opsbot/values.yaml @@ -2,8 +2,8 @@ replicaCount: 1 image: - repository: maibornwolff/opsbot - tag: v0.0.1 + repository: ghcr.io/maibornwolff/opsbot + tag: 0.0.1 pullPolicy: IfNotPresent nameOverride: "" diff --git a/requirements.txt b/requirements.txt index 6c62249..c981a1a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,13 @@ -Flask==2.1.0 -requests==2.25.1 -botbuilder-core==4.14.0 -botbuilder-schema==4.14.0 -botframework-connector==4.14.0 -APScheduler==3.6.3 -kubernetes==18.20.0 -holidays==0.10.3 -beautifulsoup4==4.9.3 +Flask==3.0.1 +requests==2.31.0 +botbuilder-core==4.14.7 +botbuilder-schema==4.14.7 +botframework-connector==4.14.7 +APScheduler==3.10.4 +kubernetes==29.0.0 +holidays==0.41 +beautifulsoup4==4.12.3 oyaml==1.0 click-shell[readline]==2.1 -pytz==2020.1 -aiohttp==3.7.4.post0 \ No newline at end of file +pytz==2023.3.post1 +aiohttp==3.9.1