glucose_exporter/Earthfile

90 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

2024-03-20 08:58:17 +01:00
VERSION 0.7
2024-03-21 11:19:32 +01:00
ARG --global GO_VERSION=1.22.1
2024-04-02 09:01:41 +02:00
ARG --global GOLANGCILINT_VERSION=v1.57.1
2024-03-20 08:58:17 +01:00
ARG --global GORELEASER_VERSION=v1.24.0
FROM golang:$GO_VERSION-alpine3.18
WORKDIR /glucose_exporter
SAVE_CODE:
COMMAND
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
SAVE ARTIFACT api AS LOCAL api
2024-03-21 11:19:32 +01:00
SAVE ARTIFACT cmd AS LOCAL cmd
2024-03-20 08:58:17 +01:00
SAVE ARTIFACT httpslog AS LOCAL httpslog
SAVE ARTIFACT internal AS LOCAL internal
code:
COPY go.mod go.sum ./
COPY --dir api ./
2024-03-21 11:19:32 +01:00
COPY --dir cmd ./
2024-03-20 08:58:17 +01:00
COPY --dir httpslog ./
COPY --dir internal ./
COPY --dir vendor ./
SAVE ARTIFACT . code
ci:
FROM +deps
ARG SNAPSHOT=true
ARG GITHUB_TOKEN
2024-03-20 08:58:17 +01:00
BUILD +test
BUILD +lint
COPY (+goreleaser/dist/metadata.json --SNAPSHOT=$SNAPSHOT --GITHUB_TOKEN=$GITHUB_TOKEN) /tmp/metadata.json
ARG DOCKER_TAG=$(cat /tmp/metadata.json|jq -r .version)
BUILD +docker --DOCKER_TAG=$DOCKER_TAG
2024-03-20 08:58:17 +01:00
test:
COPY +code/code ./
RUN go test -v ./...
tidy:
RUN apk add --no-cache git
COPY +code/code ./
RUN go mod tidy
RUN go mod vendor
SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum
SAVE ARTIFACT vendor AS LOCAL vendor
deps:
FROM +base
RUN (cd /tmp; go install github.com/golangci/golangci-lint/cmd/golangci-lint@$GOLANGCILINT_VERSION)
RUN (cd /tmp; go install github.com/goreleaser/goreleaser@$GORELEASER_VERSION)
RUN apk add --no-cache \
git \
jq
2024-03-20 08:58:17 +01:00
lint:
FROM +deps
COPY +code/code ./
COPY .golangci.yml .golangci.yml
RUN golangci-lint run
goreleaser:
FROM +deps
ARG SNAPSHOT=true
ARG GITHUB_TOKEN
IF [ "$SNAPSHOT" = "true" ]
ARG CMD="release --snapshot --clean"
ELSE
ARG CMD="release --clean"
END
COPY . .
RUN goreleaser $CMD
SAVE ARTIFACT dist dist
2024-03-21 11:19:32 +01:00
ssl-certs:
2024-04-02 16:26:32 +02:00
RUN set -ex \
&& apk add --no-cache ca-certificates
SAVE ARTIFACT /etc/ssl/certs/ca-certificates.crt ca-certificates.crt
2024-03-21 11:19:32 +01:00
docker:
FROM scratch
ARG DOCKER_TAG
2024-04-02 16:26:32 +02:00
COPY +ssl-certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
2024-03-21 11:19:32 +01:00
COPY +goreleaser/dist/glucose_exporter_linux_amd64_v1/glucose_exporter /glucose_exporter
VOLUME /var/cache/glucose_exporter
2024-04-02 16:26:32 +02:00
ENTRYPOINT ["/glucose_exporter"]
2024-03-21 11:19:32 +01:00
CMD ["serve"]
SAVE IMAGE --push ghcr.io/xsteadfastx/glucose_exporter:$DOCKER_TAG