From 3a0b6d584969f2813970e432d029e4a8d1743e4c Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Thu, 25 Apr 2024 23:09:44 -0500 Subject: [PATCH] feat: Initial commit --- .changelog-generator.yaml | 14 ++++++ .dockerignore | 9 ++++ .env.example | 2 + .github/CODEOWNERS | 1 + .github/renovate.json | 16 +++++++ .github/workflows/build.yml | 90 +++++++++++++++++++++++++++++++++++++ .gitignore | 12 +++++ .golangci.yaml | 88 ++++++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 7 +++ Dockerfile | 56 +++++++++++++++++++++++ cmd/cmd.go | 29 ++++++++++++ cmd/cmd_test.go | 25 +++++++++++ compose.yaml | 18 ++++++++ go.mod | 22 +++++++++ go.sum | 45 +++++++++++++++++++ internal/alert/event.go | 58 ++++++++++++++++++++++++ internal/alert/handler.go | 29 ++++++++++++ internal/config/config.go | 10 +++++ internal/config/context.go | 16 +++++++ internal/config/flags.go | 13 ++++++ internal/config/load.go | 29 ++++++++++++ main.go | 13 ++++++ payloads/alarm.json | 42 +++++++++++++++++ payloads/composite.json | 30 +++++++++++++ 24 files changed, 674 insertions(+) create mode 100644 .changelog-generator.yaml create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 .github/CODEOWNERS create mode 100644 .github/renovate.json create mode 100644 .github/workflows/build.yml create mode 100644 .gitignore create mode 100644 .golangci.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 Dockerfile create mode 100644 cmd/cmd.go create mode 100644 cmd/cmd_test.go create mode 100644 compose.yaml create mode 100644 go.mod create mode 100644 go.sum create mode 100644 internal/alert/event.go create mode 100644 internal/alert/handler.go create mode 100644 internal/config/config.go create mode 100644 internal/config/context.go create mode 100644 internal/config/flags.go create mode 100644 internal/config/load.go create mode 100644 main.go create mode 100644 payloads/alarm.json create mode 100644 payloads/composite.json diff --git a/.changelog-generator.yaml b/.changelog-generator.yaml new file mode 100644 index 0000000..54674fc --- /dev/null +++ b/.changelog-generator.yaml @@ -0,0 +1,14 @@ +# yaml-language-server: $schema=https://gabe565.github.io/changelog-generator/config.schema.json +filters: + exclude: + - "^docs" + - "^test" +groups: + - title: Features + order: 0 + regexp: "^(feat)" + - title: Fixes + order: 1 + regexp: "^(fix|perf)" + - title: Others + order: 999 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bae4df7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.changelog-generator.yaml +.git/ +.github/ +.gitignore +.golangci.yaml +.idea/ +.pre-commit-config.yaml +README.md +payloads/ diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..3887e1d --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +SLACK_API_TOKEN= +SLACK_CHANNEL= diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..1a1a071 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @clevyr/devops diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..0c42e3b --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "local>clevyr/renovate-config" + ], + "regexManagers": [ + { + "fileMatch": "Dockerfile$", + "matchStrings": [ + "ARG RIE_VERSION=(?.*)" + ], + "datasourceTemplate": "github-releases", + "depNameTemplate": "aws/aws-lambda-runtime-interface-emulator" + } + ] +} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..978eabf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,90 @@ +name: Build + +on: push + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: false + - name: Lint + uses: golangci/golangci-lint-action@v5 + + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Test + run: go test ./... + + build: + name: Build Image + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/clevyr/lambda-cloudwatch-slack + tags: | + type=raw,priority=1000,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=raw,value=beta,enable=${{ github.ref_name == 'main' }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} + - name: Build and Push + id: docker_build + uses: docker/build-push-action@v5 + with: + context: . + pull: true + push: ${{ steps.meta.outputs.tags != '' }} + platforms: linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + release: + name: Release + runs-on: ubuntu-latest + needs: [lint, test, build] + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Generate Changelog + id: changelog + uses: gabe565/changelog-generator@v0 + - name: Release + uses: softprops/action-gh-release@v2 + with: + body: ${{ steps.changelog.outputs.changelog }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c4664b --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Editor +.idea + +# Compiled +coverage.out +dist/ +lambda-cloudwatch-slack +out/ + +# Config +.env* +!.env.example diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..594c368 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,88 @@ +run: + timeout: 5m + +issues: + max-same-issues: 50 + exclude-rules: + - path: "_test\\.go" + linters: + - dupl + +linters: + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - copyloopvar + - decorder + - dupl + - durationcheck + - errcheck + - errname + - errorlint + - execinquery + - exportloopref + - forbidigo + - gci + - ginkgolinter + - gocheckcompilerdirectives + - gochecknoglobals + - gochecknoinits + - gochecksumtype + - goconst + - gocritic + - gocyclo + - godox + - goerr113 + - gofumpt + - goheader + - goimports + - gomoddirectives + - gomodguard + - goprintffuncname + - gosec + - gosimple + - gosmopolitan + - govet + - importas + - inamedparam + - ineffassign + - interfacebloat + - intrange + - loggercheck + - makezero + - mirror + - musttag + - nakedret + - nilerr + - nilnil + - noctx + - nolintlint + - nonamedreturns + - nosprintfhostport + - paralleltest + - perfsprint + - prealloc + - predeclared + - promlinter + - protogetter + - reassign + - revive + - rowserrcheck + - sloglint + - spancheck + - sqlclosecheck + - staticcheck + - stylecheck + - tenv + - testableexamples + - testifylint + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + - zerologlint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..70fecf5 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: https://github.com/TekWizely/pre-commit-golang + rev: v1.0.0-rc.1 + hooks: + - id: go-mod-tidy-repo + - id: golangci-lint-mod + args: [--fix] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dbc3862 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +#syntax=docker/dockerfile:1.7 + +FROM --platform=$BUILDPLATFORM golang:1.22.2-alpine as builder +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY cmd cmd +COPY internal internal +COPY *.go ./ +# Set Golang build envs based on Docker platform string +ARG TARGETPLATFORM +RUN --mount=type=cache,target=/root/.cache <