Skip to content

Commit

Permalink
initial commit (#1)
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
karl-johan-grahn authored Oct 20, 2021
1 parent 20c9a68 commit fece265
Show file tree
Hide file tree
Showing 48 changed files with 3,590 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @karl-johan-grahn
6 changes: 6 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: ".github/workflows"
schedule:
interval: "daily"
7 changes: 7 additions & 0 deletions .github/md_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ignorePatterns": [
{
"pattern": "^http"
}
]
}
15 changes: 15 additions & 0 deletions .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Docker image

on:
push:
branches: main
pull_request:
branches: main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: make image.iid
17 changes: 17 additions & 0 deletions .github/workflows/docker-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Dockerfile lint

on:
push:
branches: main
pull_request:
branches: main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Docker lint
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
failure-threshold: warning
44 changes: 44 additions & 0 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Docker publish

on:
push:
branches: main
# Publish semantic version tags as releases
tags: [ '^[0-9]+.[0-9]+.[0-9]+$' ]
pull_request:
branches: main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{github.repository}}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
# Login against a Docker registry except on PR
- name: Log into Docker registry ${{env.REGISTRY}}
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ${{env.REGISTRY}}
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
# Extract metadata for Docker for subsequent registry push
- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}
# Build and push Docker image with Buildx (don't push on PR)
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
push: ${{github.event_name != 'pull_request'}}
tags: ${{steps.meta.outputs.tags}}
labels: ${{steps.meta.outputs.labels}}
44 changes: 44 additions & 0 deletions .github/workflows/documentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Documentation checks

on:
push:
branches: main
pull_request:
branches: main
jobs:
link_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Link check
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: .github/md_config.json
spell_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Spell check
uses: errata-ai/[email protected]
with:
styles: https://github.com/errata-ai/write-good/releases/latest/download/write-good.zip
files: docs/src
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
build_and_deploy:
runs-on: ubuntu-latest
concurrency:
group: ${{github.workflow}}-${{github.ref}}
steps:
- uses: actions/checkout@v2
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: 0.4.13
- run: mdbook build ./docs
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{github.ref == 'refs/heads/main'}}
with:
github_token: ${{secrets.GITHUB_TOKEN}}
publish_dir: ./book
37 changes: 37 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Go lint, build, and test

on:
push:
branches: main
pull_request:
branches: main
jobs:
lint:
runs-on: ubuntu-latest
container: ghcr.io/opencontainers/golangci-lint:v1.39.0
steps:
- uses: actions/checkout@v2
- name: Lint
run: make lint
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17.1
- name: Build
run: make build
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17.1
- name: Formatting
run: if [ -n "$(go fmt)" ]; then echo 'Code is not formatted with "go fmt"'; false; fi
- name: Test
run: make test
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Jetbrains
*.iml
*.ipr
*.iws
.idea

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# web dependencies
/web/node_modules

# web build dir
/web/build

# test and coverage
coverage.xml
coverage.html

bin
c.out
*.iid
*.tag
*.cid
/version.txt
7 changes: 7 additions & 0 deletions .vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
StylesPath = spellingstyles
MinAlertLevel = warning

# Only check MarkDown files
[*.md]

BasedOnStyles = Vale
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2021-10-18
### Adds
- Initial commit
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM golang:1.17.1 AS builder

WORKDIR /go/src/github.com/karl-johan-grahn/devopsbot

COPY . ./

RUN make build

FROM alpine:3.14.2

RUN apk add --no-cache ca-certificates=20191127-r5

ARG VERSION
ARG REVISION

LABEL org.opencontainers.image.url="ghcr.io/karl-johan-grahn/devopsbot"
LABEL org.opencontainers.image.source="https://github.com/karl-johan-grahn/devopsbot"
LABEL org.opencontainers.image.version=$VERSION
LABEL org.opencontainers.image.revision=$REVISION

COPY --from=builder /go/src/github.com/karl-johan-grahn/devopsbot/bin/devopsbot /devopsbot
# Copy over string translations
COPY --from=builder /go/src/github.com/karl-johan-grahn/devopsbot/bot/active.*.json /

USER 1001:1001

CMD [ "/devopsbot" ]
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
PREFIX := .
PKG_NAME := devopsbot
SHELL := /bin/bash
.SHELLFLAGS := -euxo pipefail -c

export GOPRIVATE=github.com/karl-johan-grahn/devopsbot

REVISION = $(shell git rev-parse --short HEAD)
VERSION = $(shell cat version.txt)

REVISION_FLAG = -X $(shell go list ./version).Revision=$(REVISION)
VERSION_FLAG = -X $(shell go list ./version).Version=$(VERSION)

# Get the string before and after the forward slash of go version arch
GOOS ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/')
GOARCH ?= $(shell go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/')

version.txt:
@./gen_version.sh > $@

image.iid: version.txt Dockerfile
@docker build \
--build-arg REVISION=$(REVISION) \
--build-arg VERSION=$(VERSION) \
--iidfile $@ \
.

lint:
@golangci-lint run --disable-all \
--enable deadcode \
--enable depguard \
--enable dupl \
--enable errcheck \
--enable goconst \
--enable gocritic \
--enable gocyclo \
--enable gofmt \
--enable goimports \
--enable gosec \
--enable gosimple \
--enable govet \
--enable ineffassign \
--enable misspell \
--enable nakedret \
--enable prealloc \
--enable staticcheck \
--enable structcheck \
--enable stylecheck \
--enable typecheck \
--enable unconvert \
--enable unused \
--enable varcheck

$(PREFIX)/bin/$(PKG_NAME)_%: version.txt go.mod go.sum $(shell find $(PREFIX) -type f -name '*.go')
GO111MODULE=on GOOS=$(shell echo $* | cut -f1 -d-) GOARCH=$(shell echo $* | cut -f2 -d- | cut -f1 -d.) CGO_ENABLED=0 \
go build \
-ldflags "$(REVISION_FLAG) $(VERSION_FLAG)" \
-o $@ \
./cmd/$(PKG_NAME)

$(PREFIX)/bin/$(PKG_NAME): $(PREFIX)/bin/$(PKG_NAME)_$(GOOS)-$(GOARCH)
cp $< $@

build: $(PREFIX)/bin/$(PKG_NAME)

clean:
@-rm -Rf $(PREFIX)/bin
@-rm -f $(PREFIX)/*.[ci]id $(PREFIX)/*.tag $(PREFIX)/version.txt $(PREFIX)/c.out

test: build
go test -v -coverprofile=c.out ./...

.PHONY: all build clean test lint
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Devopsbot - Development Operations Bot
Devopsbot is a Slack bot written in Go using the [Slack API in Go](https://github.com/slack-go/slack).
It improves development efficiency by automating tasks such as:
- Declaring incidents
- Resolving incidents

The bot essentially automates the Incident Command System (ICS).

## Design Principles
The application is built around three key principles:
1. Everything the bot can do, any person is able to do - if it goes down and is unavailable, it will not block anyone
1. Secrets are maintained externally, for example via Hashicorp Vault
1. Configuration is maintained externally, for example via Kubernetes config maps
28 changes: 28 additions & 0 deletions bot/active.en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"ArchiveIncidentChannel": "Archive incident channel",
"BroadcastChannel": "Broadcast channel",
"BroadcastChannelHint": "DevOpsBot will be invited to this channel if it is not already a member",
"Cancel": "Cancel",
"Commander": "Commander",
"DeclareIncident": "Declare incident",
"DeclareNewIncident": "Declare a new incident",
"Environment": "Environment",
"HelpMessage": "These are the available commands:\n> `/devopsbot help` - Get this help\n> `/devopsbot incident` - Declare an incident\n> `/devopsbot resolve` - Resolve an incident",
"Incident": "Incident",
"IncidentChannelNamePattern": "Choose a channel that starts with 'inc_'",
"IncidentCreationDescription": "This will create a slack channel #inc_&lt;Incident Name&gt;_&lt;date&gt;, and notify the organization about the incident",
"IncidentName": "Incident name",
"IncidentNameHint": "Incident names may only contain lowercase letters, numbers, hyphens, and underscores, and must be 60 characters or less",
"Invitees": "Invitees",
"No": "No",
"Region": "Region",
"Resolution": "Resolution",
"ResolveAnIncident": "Resolve an incident",
"ResolveIncident": "Resolve incident",
"ResolveIncidentDescription": "This will resolve an incident by archiving the incident slack channel and notify the organization about the resolution",
"Responder": "Responder",
"SecurityIncident": "Security Incident",
"SecurityIncidentLabel": "Mark to make incident channel private",
"Summary": "Summary",
"Yes": "Yes"
}
Loading

0 comments on commit fece265

Please sign in to comment.