ci(pre-commit): Adds pre-commit script to verify Dockerfile & Go

This commit is contained in:
Iain Sproat
2022-11-07 17:31:34 +00:00
parent 89ef841a7e
commit 2c0628507c
3 changed files with 60 additions and 13 deletions
+46
View File
@@ -0,0 +1,46 @@
repos:
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.0-alpha.4" # Use the sha / tag you want to point at
hooks:
- id: prettier
- repo: https://github.com/hadolint/hadolint
rev: "v2.10.0"
hooks:
- id: hadolint
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.3.0"
hooks:
- id: check-yaml
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-vcs-permalinks
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/syntaqx/git-hooks
rev: "v0.0.17"
hooks:
- id: circleci-config-validate
- repo: https://github.com/Jarmos-san/shellcheck-precommit
rev: "v0.2.0"
hooks:
- id: shellcheck-system
- repo: https://github.com/dnephin/pre-commit-golang
rev: "v0.5.1"
hooks:
- id: go-fmt
- id: go-vet
- id: no-go-testing
- id: go-critic
- id: go-unit-tests
- id: go-build
- id: go-mod-tidy
ci:
autoupdate_schedule: quarterly
+8 -6
View File
@@ -3,15 +3,17 @@
# STEP 1 build executable binary
FROM golang:alpine as builder
# Install SSL ca certificates
RUN apk update && apk add git && apk add ca-certificates
RUN apk update && apk add --no-cache \
git=2.36.3-r0 \
ca-certificates=20220614-r0
# Create appuser
RUN adduser -D -g '' appuser
COPY . $GOPATH/src/mypackage/myapp/
WORKDIR $GOPATH/src/mypackage/myapp/
#get dependancies
RUN go get -d -v
#build the binary
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/alertmanager-discord
RUN go get -d -v \
# build the binary
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/alertmanager-discord
# STEP 2 build a small image
@@ -20,9 +22,9 @@ FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
# Copy our static executable
COPY --from=builder /go/bin/alertmanager-discord /go/bin/alertmanager-discord
COPY --from=builder /go/bin/alertmanager-discord /bin/alertmanager-discord
ENV LISTEN_ADDRESS=0.0.0.0:9094
EXPOSE 9094
USER appuser
ENTRYPOINT ["/go/bin/alertmanager-discord"]
ENTRYPOINT ["/bin/alertmanager-discord"]
+6 -7
View File
@@ -1,5 +1,4 @@
alertmanager-discord
===
# alertmanager-discord
Give this a webhook (with the DISCORD_WEBHOOK environment variable) and point it as a webhook on alertmanager, and it will post your alerts into a discord channel for you as they trigger:
@@ -14,11 +13,11 @@ The standard "dataflow" should be:
```
Prometheus -------------> alertmanager -------------------> alertmanager-discord
alerting: receivers:
alerting: receivers:
alertmanagers: - name: 'discord_webhook' environment:
- static_configs: webhook_configs: - DISCORD_WEBHOOK=https://discordapp.com/api/we...
- targets: - url: 'http://localhost:9094'
- 127.0.0.1:9093
- targets: - url: 'http://localhost:9094'
- 127.0.0.1:9093
@@ -37,7 +36,7 @@ global:
smtp_auth_password: 'password'
# The directory from which notification templates are read.
templates:
templates:
- '/etc/alertmanager/template/*.tmpl'
# The root route on which each incoming alert enters.
@@ -45,7 +44,7 @@ route:
group_by: ['alertname']
group_wait: 20s
group_interval: 5m
repeat_interval: 3h
repeat_interval: 3h
receiver: discord_webhook
receivers: