diff --git a/.travis.yml b/.travis.yml index b331039..ecd047a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,10 @@ go: services: - docker +before_install: + - wget https://kubernetes-helm.storage.googleapis.com/helm-v2.6.1-linux-amd64.tar.gz + - tar xzf helm-v2.6.1-linux-amd64.tar.gz + install: - go get @@ -12,6 +16,7 @@ script: - go vet - gofmt -e -d *.go - go build + - linux-amd64/helm lint ./chart/stack2slack after_success: - test -n "$TRAVIS_TAG" && docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" diff --git a/README.md b/README.md index 4594f8c..9ae38e4 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,23 @@ in a dedicated channel of the Slack of [Les-Tilleuls.coop](https://les-tilleuls. ## Installing -The easiest way to get started is to use the official [Docker](https://www.docker.com/) image: - 1. [Register a new Slack bot](https://my.slack.com/services/new/bot) and grab the generated API token -2. Start the daemon: `docker run -e DEBUG=1 -e SLACK_API_TOKEN= -e TAG_TO_CHANNEL='{"stackoverflow-tag": "slack-channel"}' dunglas/stack2slack` -6. Finally, invite the bot in channels it will post: `/invite @bot-name` +2. [Download](https://github.com/dunglas/stack2slack/releases) and extract the binary corresponding to your platform +3. Start the daemon: `DEBUG=1 SLACK_API_TOKEN= TAG_TO_CHANNEL='{"stackoverflow-tag": "slack-channel"}' ./stack2slack` +4. Finally, invite the bot in channels it will post: `/invite @bot-name` + +Alternatively, you can use the official [Docker](https://www.docker.com/) image instead of downloading a binary: `docker run -e DEBUG=1 -e SLACK_API_TOKEN= -e TAG_TO_CHANNEL='{"stackoverflow-tag": "slack-channel"}' dunglas/stack2slack` + +If you use a [Kubernetes](https://kubernetes.io/) (e.g. a Google Container Engine cluster), you can install Stack 2 Slack +very easily with the [Helm](https://helm.sh/) package manager: + +1. Clone this repository: `git clone git@github.com:dunglas/stack2slack.git` +2. Install the provided chart: + + helm install \ + --set slackApiToken= \ + --set tagToChannel.stackExchangeTag=slackChannel \ + ./chart/stack2slack ## Building from Sources diff --git a/chart/stack2slack/.helmignore b/chart/stack2slack/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/chart/stack2slack/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/chart/stack2slack/Chart.yaml b/chart/stack2slack/Chart.yaml new file mode 100644 index 0000000..8d8de6e --- /dev/null +++ b/chart/stack2slack/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +description: A Slack bot to monitor StackOverflow/StackExchange tags +name: stack2slack +version: 0.1.0 +sources: +- https://github.com/dunglas/stack2slack +maintainers: +- name: Kévin Dunglas + email: dunglas@gmail.com diff --git a/chart/stack2slack/README.md b/chart/stack2slack/README.md new file mode 100644 index 0000000..e0816f0 --- /dev/null +++ b/chart/stack2slack/README.md @@ -0,0 +1,69 @@ +# Stack to Slack + +[Stack to Slack](https://github.com/dunglas/stack2slack) is a Slack bot that monitors StackExchange tags and automatically +publishes new questions in configured Slack channels. + +## Introduction + +This chart adds a Stack to Slack deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) +package manager. + +## Prerequisites + +- Kubernetes 1.2+ with Beta APIs enabled + +## Installing the Chart + +To install the chart with the release name `my-release`, [retrieve a Slack API token for bot](https://my.slack.com/services/new/bot) and run: + +```bash +$ helm install --name my-release \ + --set slackApiToken= \ + --set tagToChannel.stackExchangeTag=slackChannel stable/stack2slack +``` + +Then, from Slack, invite the bot in the channel: `/invite @theBotName` + +After a few minutes, you should see all new questions posted on StackExchange appearing in the Slack channel. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```bash +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following tables lists the configurable parameters of the Stack to Slack chart and their default values. + +| Parameter | Description | Default | +|-----------------------------|------------------------------------------|-------------------------------------| +| `slackApiToken` | The Slack API token for the bot | `Nil` You must provide your own key | +| `tagToChannel` | StackExchange tags to Slack channels map | Empty | +| `debug` | Enable debug logs | 0 | +| `stackSite` | The StackExchange site to monitor | stackoverflow | +| `image.repository` | The image repository to pull from | `sysdig/agent` | +| `image.tag` | The image tag to pull | `latest` | +| `image.pullPolicy` | The Image pull policy | `Always` | + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```bash +$ helm install --name my-release \ + --set slackApiToken=YOUR-KEY-HERE,tagToChannel.mytag=mychan \ + stable/stack2slack +``` + +Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example, + +```bash +$ helm install --name my-release -f values.yaml stable/stack2slack +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) diff --git a/chart/stack2slack/templates/NOTES.txt b/chart/stack2slack/templates/NOTES.txt new file mode 100644 index 0000000..dd01c31 --- /dev/null +++ b/chart/stack2slack/templates/NOTES.txt @@ -0,0 +1,14 @@ +{{- if eq (printf "%s" .Values.slackApiToken) "" }} +####################################################################################### +#### ERROR: You did not provided a Slack API token in your 'helm install' call. #### +####################################################################################### + +This deployment will be incomplete until you provide a Slack API token: + + helm upgrade {{ .Release.Name }} \ + --set slackApiToken= stable/stack2slack +{{- end }} + +Don't forget to invite the bot in channels it will post. + +From Slack: `/invite @bot-name` diff --git a/chart/stack2slack/templates/_helpers.tpl b/chart/stack2slack/templates/_helpers.tpl new file mode 100644 index 0000000..f0d83d2 --- /dev/null +++ b/chart/stack2slack/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/chart/stack2slack/templates/configmap.yaml b/chart/stack2slack/templates/configmap.yaml new file mode 100644 index 0000000..77acb6f --- /dev/null +++ b/chart/stack2slack/templates/configmap.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: + tagToChannel: |- + {{ toJson .Values.tagToChannel }} + stackSite: {{ .Values.stackSite | quote }} + debug: {{ .Values.debug | quote }} diff --git a/chart/stack2slack/templates/deployment.yaml b/chart/stack2slack/templates/deployment.yaml new file mode 100644 index 0000000..d684235 --- /dev/null +++ b/chart/stack2slack/templates/deployment.yaml @@ -0,0 +1,63 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + template: + metadata: + labels: + app: {{ template "name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: SLACK_API_TOKEN + valueFrom: + secretKeyRef: + name: {{ template "fullname" . }} + key: slackApiToken + - name: TAG_TO_CHANNEL + valueFrom: + configMapKeyRef: + name: {{ template "fullname" . }} + key: tagToChannel + - name: STACK_SITE + valueFrom: + configMapKeyRef: + name: {{ template "fullname" . }} + key: stackSite + - name: DEBUG + valueFrom: + configMapKeyRef: + name: {{ template "fullname" . }} + key: debug + livenessProbe: + exec: + command: + - sh + - -c + - ps -ef | grep /go/bin/stack2slack | grep -v grep + initialDelaySeconds: 5 + periodSeconds: 5 + readinessProbe: + exec: + command: + - sh + - -c + - ps -ef | grep /go/bin/stack2slack | grep -v grep + initialDelaySeconds: 5 + periodSeconds: 5 + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/chart/stack2slack/templates/secrets.yaml b/chart/stack2slack/templates/secrets.yaml new file mode 100644 index 0000000..6369566 --- /dev/null +++ b/chart/stack2slack/templates/secrets.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +type: Opaque +data: + slackApiToken : {{ default "MISSING" .Values.slackApiToken | b64enc | quote }} diff --git a/chart/stack2slack/values.yaml b/chart/stack2slack/values.yaml new file mode 100644 index 0000000..0fa5c35 --- /dev/null +++ b/chart/stack2slack/values.yaml @@ -0,0 +1,10 @@ +# Required +slackApiToken: '' +debug: '0' +tagToChannel: + #api-platform.com: stackoverflow +stackSite: 'stackoverflow' +image: + repository: dunglas/stack2slack + tag: latest + pullPolicy: IfNotPresent