From 28d0d041b08d275ae22c3c5c4b5b500510ef1181 Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 14 Jun 2024 05:47:35 -0700 Subject: [PATCH] lint and check fmt on docker build --- Dockerfile | 39 +++++++++++++++++++++++++++++++++++++++ Makefile | 3 +++ 2 files changed, 42 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d67989a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +# First stage: Use the golangci-lint image to run the linter +FROM golangci/golangci-lint:latest as lint + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy the go.mod file and the rest of the application code +COPY go.mod ./ +COPY . . + +# Run golangci-lint +RUN golangci-lint run + +RUN sh -c 'test -z "$(gofmt -l .)"' + +# Second stage: Use the official Golang image to run tests +FROM golang:1.22 as test + +# Set the Current Working Directory inside the container +WORKDIR /app + +# Copy the go.mod file and the rest of the application code +COPY go.mod ./ +COPY . . + +# Run tests +RUN go test -v ./... + +# Final stage: Combine the linting and testing stages +FROM golang:1.22 as final + +# Ensure that the linting stage succeeded +WORKDIR /app +COPY --from=lint /app . +COPY --from=test /app . + +# Set the final CMD to something minimal since we only needed to verify lint and tests during build +CMD ["echo", "Build and tests passed successfully!"] + diff --git a/Makefile b/Makefile index 923eac9..6ef9919 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,6 @@ fmt: lint: golangci-lint run sh -c 'test -z "$$(gofmt -l .)"' + +docker: + docker build --progress plain .