-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3a0b6d5
Showing
24 changed files
with
674 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.changelog-generator.yaml | ||
.git/ | ||
.github/ | ||
.gitignore | ||
.golangci.yaml | ||
.idea/ | ||
.pre-commit-config.yaml | ||
README.md | ||
payloads/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SLACK_API_TOKEN= | ||
SLACK_CHANNEL= |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @clevyr/devops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"local>clevyr/renovate-config" | ||
], | ||
"regexManagers": [ | ||
{ | ||
"fileMatch": "Dockerfile$", | ||
"matchStrings": [ | ||
"ARG RIE_VERSION=(?<currentValue>.*)" | ||
], | ||
"datasourceTemplate": "github-releases", | ||
"depNameTemplate": "aws/aws-lambda-runtime-interface-emulator" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Editor | ||
.idea | ||
|
||
# Compiled | ||
coverage.out | ||
dist/ | ||
lambda-cloudwatch-slack | ||
out/ | ||
|
||
# Config | ||
.env* | ||
!.env.example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<EOT | ||
set -eux | ||
|
||
case "$TARGETPLATFORM" in | ||
'linux/amd64') export GOARCH=amd64 ;; | ||
'linux/arm/v6') export GOARCH=arm GOARM=6 ;; | ||
'linux/arm/v7') export GOARCH=arm GOARM=7 ;; | ||
'linux/arm64') export GOARCH=arm64 ;; | ||
*) echo "Unsupported target: $TARGETPLATFORM" && exit 1 ;; | ||
esac | ||
|
||
export CGO_ENABLED=0 | ||
go build -ldflags='-w -s' -tags lambda.norpc -trimpath -o cloudwatch-slack-alerts . | ||
EOT | ||
|
||
FROM alpine:3.19 AS rie | ||
WORKDIR /app | ||
ARG TARGETPLATFORM | ||
ARG RIE_VERSION=v1.18 | ||
RUN <<EOT | ||
set -eux | ||
|
||
case "$TARGETPLATFORM" in | ||
'linux/amd64') export SUFFIX=x86_64 ;; | ||
'linux/arm64') export SUFFIX=arm64 ;; | ||
*) echo "Unsupported target: $TARGETPLATFORM" && exit 1 ;; | ||
esac | ||
|
||
wget \ | ||
-O aws-lambda-rie \ | ||
"https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/$RIE_VERSION/aws-lambda-rie-$SUFFIX" | ||
chmod +x aws-lambda-rie | ||
EOT | ||
|
||
FROM alpine:3.19 AS base | ||
WORKDIR /app | ||
COPY --from=builder /app/cloudwatch-slack-alerts . | ||
|
||
FROM base AS local | ||
COPY --from=rie /app/aws-lambda-rie . | ||
|
||
FROM base | ||
CMD ["./cloudwatch-slack-alerts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/clevyr/cloudwatch-slack-alerts/internal/alert" | ||
"github.com/clevyr/cloudwatch-slack-alerts/internal/config" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
conf := config.New() | ||
|
||
cmd := &cobra.Command{ | ||
Use: "cloudwatch-slack-alerts", | ||
Short: "Send AWS CloudWatch notifications to a Slack channel using Lambda", | ||
PreRunE: func(cmd *cobra.Command, _ []string) error { | ||
return conf.Load(cmd) | ||
}, | ||
Run: func(_ *cobra.Command, _ []string) { | ||
lambda.Start(alert.Handler(conf)) | ||
}, | ||
} | ||
|
||
conf.RegisterFlags(cmd) | ||
cmd.SetContext(config.NewContext(context.Background(), conf)) | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/clevyr/cloudwatch-slack-alerts/internal/config" | ||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCmdDbFlags(t *testing.T) { | ||
t.Setenv("SLACK_API_TOKEN", "123") | ||
t.Setenv("SLACK_CHANNEL", "alerts") | ||
|
||
rootCmd := NewCommand() | ||
rootCmd.Run = func(_ *cobra.Command, _ []string) {} | ||
|
||
require.NoError(t, rootCmd.Execute()) | ||
|
||
conf, ok := config.FromContext(rootCmd.Context()) | ||
require.True(t, ok) | ||
assert.Equal(t, "123", conf.SlackAPIToken) | ||
assert.Equal(t, "alerts", conf.SlackChannel) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
services: | ||
app: | ||
image: ghcr.io/clevyr/cloudwatch-slack-alerts:local | ||
build: | ||
context: . | ||
target: local | ||
env_file: | ||
- .env | ||
entrypoint: | ||
- ./aws-lambda-rie | ||
command: | ||
- ./cloudwatch-slack-alerts | ||
ports: | ||
- 127.0.0.1:9000:8080 | ||
develop: | ||
watch: | ||
- action: rebuild | ||
path: . |
Oops, something went wrong.