Skip to content

Commit

Permalink
feat(Main): publish slack notifications if slack configuration is ava…
Browse files Browse the repository at this point in the history
…ilable
  • Loading branch information
maciejsmolinski committed Aug 15, 2019
1 parent e251cd1 commit 5b11802
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ $ curl "http:https://localhost:8181/run?definition=main&secret=secret-token"

while the browser will show only a `success` message, the server will give you more feedback

## Slack integration

To receive slack notifications, create a new [Incoming Webhook](https://slack.com/apps/A0F7XDUAZ-incoming-webhooks) in your Slack account. Then, run orchy with the following environment variables:

* `SLACK_HOOK_URL` - webhook url, e.g. `https://hooks.slack.com/services/ABC/DEF/GHI`
* `SLACK_CHANNEL` - channel to post notifications to, e.g. `deployment-logs`

```shell
$ SLACK_HOOK_URL=<url> SLACK_CHANNEL=<channel> orchy

Orchy server is running at http:https://localhost:8181
```


## Feedback from the server

When `configuration.json` file is missing:
Expand Down
16 changes: 3 additions & 13 deletions src/Main.purs
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
module Main where

import Prelude

import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Effect (Effect)
import HTTP.Server as HTTPServer
import HTTP.Utils as HTTPUtils
import Logger as Logger
import Node.Process (lookupEnv)
import Orchestrator.FS (readFile)
import Orchestrator.JSON (fromJSON)
import Orchestrator.Main (makeId, makeSecret, runDefinitionWithIdAndSecret)
import Simple.JSON (readJSON_)

getPort :: Effect Int
getPort = do
maybePort <- lookupEnv "PORT"
case (maybePort >>= readJSON_) of
Nothing -> pure 8181
(Just port) -> pure port
import Prelude
import System.Environment (readEnvInt)

main :: Effect Unit
main = do
port <- getPort
port <- readEnvInt "PORT" 8181
configuration <- readFile "configuration.json"
case configuration of
(Left _) -> Logger.error "Failure reading configuration.json"
Expand Down
15 changes: 12 additions & 3 deletions src/Orchestrator/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Effect (Effect)
import Effect.Aff (Aff, Error, launchAff_, message)
import Effect.Class (liftEffect)
import Logger as Logger
import Notifications.Slack as Slack
import Prelude ((&&), (*>))
import System.Commands (asyncExec)

Expand Down Expand Up @@ -124,16 +125,24 @@ runDefinition (Definition { dir, commands }) = launchAff_ do
(Right _) -> logSuccess
where
logFailure :: Aff Unit
logFailure = liftEffect $ Logger.error "Execution FAILED"
logFailure = do
liftEffect $ Logger.error "Execution FAILED"
Slack.notify "Execution FAILED"

logSuccess :: Aff Unit
logSuccess = liftEffect $ Logger.info "Execution SUCCEEDED"
logSuccess = do
liftEffect $ Logger.info "Execution SUCCEEDED"
Slack.notify "Execution SUCCEEDED"

logOutput :: Error -> Aff Unit
logOutput = liftEffect <<< Logger.quote <<< message
logOutput error = do
liftEffect <<< Logger.quote $ message error
Slack.notify $ message error

executeCommand :: Dir -> Command -> Aff Unit
executeCommand (Dir cwd) (Command program args) = do
liftEffect $ Logger.info $ "Executing " <> (joinWith " " (program : args))
Slack.notify $ "Executing " <> (joinWith " " (program : args))
output <- asyncExec program args { cwd }
liftEffect $ Logger.quote output
Slack.notify output

0 comments on commit 5b11802

Please sign in to comment.