3.0 KiB
Tekton Pipeline - Approval Slack Bot
This project is a slack bot that waits for approval on a specified channel and exits upon approval. It is used to let Product Managers approve a release into production using Tekton Pipeline.
It uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
Pre-requisites
- Create a Slack application on api.slack.com/apps.
- Create an App-Level Token with the
connections:writescope. - Enable Socket Mode.
- In OAuth & Permissions, enable the
app_mentions:read,channels:read,chat:writeandcommandsscopes. - In the Slash Commands, add the
/lgtmcommand. - Install App to your Workspace
Usage
- Invite the bot to your channel
- Start the bot with the SLACK_CHANNEL and TEKTON_PIPELINE_ID environment variables
- Wait for the bot to post the message on the channel
- Send the "/lgtm 1234" command (where 1234 is the id of the tekton pipeline to approve)
- The application exits with code 0
Running the application in dev mode
Install Java 11:
sudo dnf install java-11-openjdk-devel
sudo alternatives --config java
sudo alternatives --config javac
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.19.0.7-1.fc37.x86_64
You can run your application in dev mode that enables live coding using:
export SLACK_CHANNEL="#mad-roadshow-france-2023"
export TEKTON_PIPELINE_ID="1234"
export SLACK_BOT_TOKEN="xoxb-...."
export SLACK_APP_TOKEN="xapp-...."
./mvnw compile quarkus:dev
Packaging and running the application
The application can be packaged using:
./mvnw package
It produces the quarkus-run.jar file in the target/quarkus-app/ directory.
Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/ directory.
The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar.
If you want to build an über-jar, execute the following command:
./mvnw package -Dquarkus.package.type=uber-jar
The application, packaged as an über-jar, is now runnable using java -jar target/*-runner.jar.
Creating a native executable
You can create a native executable using:
./mvnw package -Pnative
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
./mvnw package -Pnative -Dquarkus.native.container-build=true
You can then execute your native executable with: ./target/slack-bot-1.0.0-SNAPSHOT-runner
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.