diff --git a/workflows/util/README.md b/workflows/util/README.md index 573a02d65..e98211d7c 100644 --- a/workflows/util/README.md +++ b/workflows/util/README.md @@ -33,6 +33,8 @@ graph TD; create-thumbnails-->publish-thumbnails; ``` +Note: `#alert-argo-workflows` Slack channel is notified once the workflow is completed. + ### [aws-list](https://github.com/linz/argo-tasks/blob/master/src/commands/list/list.ts) Recursively loops through the provided source path and lists all the files within this location. Some listing parameters are currently hard-coded due to the current bespoke purpose of this workflow: diff --git a/workflows/util/create-thumbnails.yaml b/workflows/util/create-thumbnails.yaml index d526eac7e..304fe3897 100644 --- a/workflows/util/create-thumbnails.yaml +++ b/workflows/util/create-thumbnails.yaml @@ -9,6 +9,7 @@ spec: nodeSelector: karpenter.sh/capacity-type: "spot" entrypoint: main + onExit: exit-handler arguments: parameters: # FIXME: Should use camelCase or underscore? @@ -117,6 +118,12 @@ spec: artifacts: - name: files path: /tmp/file_list.json + outputs: + parameters: + - name: count + globalName: count + valueFrom: + path: /tmp/thumbnails/count container: image: "019359803926.dkr.ecr.ap-southeast-2.amazonaws.com/eks:topo-imagery-{{=sprig.trim(workflow.parameters['version-topo-imagery'])}}" resources: @@ -151,6 +158,78 @@ spec: valueFrom: path: "/tmp/location" + - name: exit-handler + steps: + - - name: notify + template: notify-slack + when: "{{workflow.status}} == Succeeded" + + - name: notify-slack + inputs: + parameters: + - name: count + value: "{{workflow.outputs.parameters.count}}" + script: + image: "019359803926.dkr.ecr.ap-southeast-2.amazonaws.com/eks:argo-tasks-{{=sprig.trim(workflow.parameters['version-argo-tasks'])}}" + env: + - name: PARAMS + value: "{{workflow.parameters}}" + - name: WEBHOOK + valueFrom: + secretKeyRef: + name: slack-linz-webhook # name of the secret that stores linz Slack webhook + key: url # the Slack Webhook URL is stored as `url` + command: [node] + source: | + const slackWebhook = process.env.WEBHOOK + const params = JSON.parse(process.env.PARAMS); + + var paramFields = [] + params.forEach((param) => paramFields.push({type: "mrkdwn", text: "*" + param.name + ":*\n " + param.value})); + + const payload = { + icon_url: "https://cncf-branding.netlify.app/img/projects/argo/icon/color/argo-icon-color.png", + username: "Argo Workflows [bot]", + channel: "#alert-argo-workflows", + blocks: [ + { + type: "header", + text: { + type: "plain_text", + text: ":frame_with_picture: Thumbnails Created", + emoji: true + } + }, + { + type: "section", + text: { + type: "mrkdwn", + text: "{{inputs.parameters.count}} files have been generated." + } + }, + { + type: "section", + fields: paramFields + }, + ], + }; + + fetch(slackWebhook, { + method: "POST", + body: JSON.stringify(payload), + headers: { + "Content-Type": "application/json; charset=utf-8", + "Content-Length": JSON.stringify(payload).length, + Accept: "application/json", + }, + }) + .then((res) => { + console.log(res); + }) + .catch((error) => { + console.log(error); + }); + volumes: - name: ephemeral emptyDir: {}