Coolify supports sending notifications to Slack. However, it sends all notifications to a single Slack channel. This means that all app's deployment notifications end up in one noisy channel rather than each project's respective Slack channel.
Coolify's Notifications include... (expand me)
- Deployment success
- Deployment failure
- Container status changes
- Backup Success
- Backup Failure
- Scheduled task success
- Scheduled task failure
- Docker cleanup success
- Docker cleanup failure
- Server disk usage
- Server reachable
- Server unreachable
This simple Go app solves this problem by serving as a reverse proxy. It mirrors 🪞 notifications to their respective project channels.
In order to route notification to the right Slack channel, The Conductor requires a list of Destinations. Each Destination consists of:
- A Slack channel webhook URL
- A (or multiple) regular expression(s)
When a new notification webhook is sent to The Conductor, it builds a list of relevant Destinations and mirrors the notification to them. Pretty simple!
So, how does The Conductor determine whether a Destination is relevant for a given notification?
It uses the Destination's regex(es). If any of the Destination's regexes matches any part of the notification webhook's payload (body), then the notification will be sent to the Destination's Slack channel.
A typical Slack notification looks like this
However, it's webhook payload is JSON (built using Slack's Block Kit).
This means that when writing regular expressions for Destinations, you must consider the JSON payload itself. Here's an example of one of those payloads:
{
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Coolify Notification"
}
}
],
"attachments": [
{
"color": "#00ff00",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "New version successfully deployed"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "New version successfully deployed for hackclub\/mfa:main\nApplication URL: https:\/\/mfa.hackclub.com\n\n**Project:** gary@mfa\n**Environment:** production\n**Deployment Logs:** https:\/\/app.coolify.io\/project\/ik0w8s404gg88ww0o4wgg048\/production\/application\/vogokcg8s4c4ok40880ssko8\/deployment\/oowo484co8go84ss0kso0gwc"
}
}
]
}
]
}but without the nice formatting (no new lines or indentation).
To begin, configurations are located in the config.yml file.
As mentioned above, each Destination requires a Slack webhook URL and one (or multiple) regexes.
- Visit the Coolify Slack app's Incoming Webhooks settings: https://api.slack.com/apps/A08AQL7JLT1/incoming-webhooks
- Click "Add New Webhook to Workspace"
- Choose your project's Slack channel
- Click "Allow"
- Copy the Webhook URL for your channel
Hang on to that URL.
Keep in mind you may need to escape certain special characters.
For examples, I'd recommend reading the config.yml file. However, here are a few things to know:
-
Project-related notifications (e.g. Deployment success) include its project name.
**Project:** gary@coolify-slack-conductorSo, you can use that to match all notification related to your project.
-
It may be helpful to look at existing notification messages to see what to match for. You can find them in the
#coolify-notifschannel. Since coolify is open source, you can also find their notification templates here.
Inside config.yml, add a new array item under the destinations key. That item should have the
following keys:
name: Must be all caps. Should be similar to your Slack channel's name.regex: Any array of regular expressions
Here's an example:
- name: HCB_ENGR_NOTIFS
regex:
- \*\*Project:\*\* gary@mfa\\n
- \*\*Project:\*\* gary@g-verify\\n
- \*\*Project:\*\* ian@bank-shields\\nThis Destination is named HCB_ENGR_NOTIFS. The regex will match notifications for the
projects gary@mfa, gary@g-verify, and ian@bank-shields.
You might notice that you're still hanging onto that Slack channel webhook URL. So, where does that go?
Since Slack webhook URLs should be treated like secrets, they're not stored in this codebase. Instead, the app will look
for them in its environment variables. In the example above, since the Destination's name is HCB_ENGR_NOTIFS, the app
expects an environment variable called WEBHOOK_HCB_ENGR_NOTIFS_URL to be set. It MUST be set, otherwise, the app
refuses the boot.
- PR your changes
- If you added a new Destination, add its respective environment variable to the Coolify deployment
- Go to Coolify
- Find the
gary@coolify-slack-conductorapp - Find the environment variable section
- Add the new variable. If you destination is named
MY_CHANNEL, then you should be addingWEBHOOK_MY_CHANNEL_URL. The URL should look something likehttps://hooks.slack.com/services/T0230FmGR/B083YH3Sn8W/gTZwlvOe4gsrO6JeO3N3ghjk.
- Merge the PR.
The environment variable MUST be added before merging your changes!
The Conductor will always send all notification to the main channel. This is currently set
as #coolify-notifs and is configured via the WEBHOOK_MAIN_URL.
via Docker on Coolify.
Set the following environment variables:
AUTH_KEY: any string. This "secures" this reverse proxy and prevents people from spamming our channelsWEBHOOK_MAIN_URL: the Slack webhook url of the main channel. See the Main channel section above.
- Go to Coolify dashboard
- On the left side, click "Notifications"
- Click the "Slack" tab
- Set the Webhook field https://coolify-conductor.hackclub.com?key=WHAT_EVER_YOU_SET_AS_AUTH_KEY
- Enable it
