b4a48fd928
* Adds development instructions to README * Replaces deprecated io/ioutil with io package * Catch all thrown errors and handle them. - not catching errors could result in unknown behaviour * Fix gofmt formatting issues * Refactor to allow http client to be provided - default client does not have timeout etc., we may instead wish to provide a custom http client. * Refactor to something closer to the standard go layout - separates alert forwarder into separate package to allow for testing/reuse * Split out types, and split Discord client into its own package * Renaming of symbols for readability - no need to abbreviate words in modern IDEs * remove go-vet hook as it is broken when go files are not in root directory * unit tests for ~90% coverage * Update picture in README * Return error status codes to caller in event of error from Discord * Remove panic, replace with error status code response and log message. Improve the status codes that are returned to provide more context on what has occurred. * Graceful shutdown of server, including signal handling * Integration tests - mocks Discord server - tests Happy case and a couple of unhappy cases - most edge conditions are otherwise tested in unit tests * CheckWebHook should return errors instead of logging - additional checks in tests for nil objects - attempt to solve integration test pollution by using different port numbers to prevent potential collision - Temporarily comment out test causing interaction pollution with other tests * structured logging * feat(exponential backoff): Added to Discord client * Serve prometheus metrics - Monitoring for the discord client * adds correlation ID to logging * refactors the mock http client to allow it to work with instrumentation for monitoring * Helm chart service monitor * Improved flag and env var parsing * Application version passed in via build args * Order of precedence of configuration configuration file<environment variable<command line * Mounts secret to file instead of in environment variable * Adds build tag to integration tests to prevent them being run as a unit test
31 lines
1.1 KiB
Docker
31 lines
1.1 KiB
Docker
# Built following https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324
|
|
|
|
# STEP 1 build executable binary
|
|
FROM golang:alpine as builder
|
|
# Install SSL 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/alertmanager-discord/
|
|
WORKDIR $GOPATH/src/alertmanager-discord/
|
|
ARG APPLICATION_VERSION
|
|
ENV APPLICATION_VERSION="${APPLICATION_VERSION:-"0.0.0"}"
|
|
#get dependancies
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s -X 'github.com/specklesystems/alertmanager-discord/pkg/version.Version=${APPLICATION_VERSION}'" -o /go/bin/alertmanager-discord main.go
|
|
|
|
|
|
# STEP 2 build a small image
|
|
# start from scratch
|
|
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 /bin/alertmanager-discord
|
|
|
|
ENV LISTEN_ADDRESS=0.0.0.0:9094
|
|
EXPOSE 9094
|
|
USER appuser
|
|
ENTRYPOINT ["/bin/alertmanager-discord"]
|