glucose_exporter/Earthfile

79 lines
1.8 KiB
Plaintext
Raw Normal View History

2024-03-20 08:58:17 +01:00
VERSION 0.7
ARG --global GO_VERSION=1.22.0
ARG --global GOLANGCILINT_VERSION=v1.54.2
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
SAVE ARTIFACT httpslog AS LOCAL httpslog
SAVE ARTIFACT internal AS LOCAL internal
code:
COPY go.mod go.sum ./
COPY --dir api ./
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
docker:
FROM scratch
ARG DOCKER_TAG
COPY +goreleaser/dist/glucose_exporter_linux_amd64_v1/glucose_exporter /bin/glucose_exporter
SAVE IMAGE --push ghcr.io/xsteadfastx/glucose_exporter:$DOCKER_TAG