Compare commits
3 Commits
fix/module
...
5d3e0667de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d3e0667de | ||
| 12446f9f79 | |||
| 877fb2c0c5 |
45
Dockerfile
45
Dockerfile
@@ -1,24 +1,6 @@
|
|||||||
# Build stage
|
# Lint stage — fast feedback on formatting and lint issues
|
||||||
# golang:1.25-alpine
|
# golangci/golangci-lint:v2.10.1
|
||||||
FROM golang@sha256:f6751d823c26342f9506c03797d2527668d095b0a15f1862cddb4d927a7a4ced AS builder
|
FROM golangci/golangci-lint@sha256:ea84d14c2fef724411be7dc45e09e6ef721d748315252b02df19a7e3113ee763 AS lint
|
||||||
|
|
||||||
RUN apk add --no-cache git make gcc musl-dev
|
|
||||||
|
|
||||||
# Install golangci-lint v2 (pre-built binary — go install fails in alpine due to missing linker)
|
|
||||||
RUN set -e; \
|
|
||||||
GOLANGCI_VERSION="2.10.1"; \
|
|
||||||
case "$(uname -m)" in \
|
|
||||||
x86_64) ARCH="amd64"; SHA256="dfa775874cf0561b404a02a8f4481fc69b28091da95aa697259820d429b09c99" ;; \
|
|
||||||
aarch64) ARCH="arm64"; SHA256="6652b42ae02915eb2f9cb2a2e0cac99514c8eded8388d88ae3e06e1a52c00de8" ;; \
|
|
||||||
*) echo "unsupported arch: $(uname -m)" >&2; exit 1 ;; \
|
|
||||||
esac; \
|
|
||||||
wget -q -O /tmp/golangci-lint.tar.gz \
|
|
||||||
"https://github.com/golangci/golangci-lint/releases/download/v${GOLANGCI_VERSION}/golangci-lint-${GOLANGCI_VERSION}-linux-${ARCH}.tar.gz"; \
|
|
||||||
echo "${SHA256} /tmp/golangci-lint.tar.gz" | sha256sum -c -; \
|
|
||||||
tar -xzf /tmp/golangci-lint.tar.gz -C /usr/local/bin --strip-components=1 "golangci-lint-${GOLANGCI_VERSION}-linux-${ARCH}/golangci-lint"; \
|
|
||||||
rm /tmp/golangci-lint.tar.gz; \
|
|
||||||
golangci-lint version
|
|
||||||
RUN go install golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0 # v0.42.0
|
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
@@ -26,10 +8,25 @@ RUN go mod download
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Run all checks - build fails if any check fails
|
RUN make fmt-check
|
||||||
RUN make check
|
RUN make lint
|
||||||
|
|
||||||
# Build the binary
|
# Build stage — tests and compilation
|
||||||
|
# golang:1.25-alpine
|
||||||
|
FROM golang@sha256:f6751d823c26342f9506c03797d2527668d095b0a15f1862cddb4d927a7a4ced AS builder
|
||||||
|
|
||||||
|
# Force BuildKit to run the lint stage by creating a stage dependency
|
||||||
|
COPY --from=lint /src/go.sum /dev/null
|
||||||
|
|
||||||
|
RUN apk add --no-cache git make gcc musl-dev
|
||||||
|
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN make test
|
||||||
RUN make build
|
RUN make build
|
||||||
|
|
||||||
# Runtime stage
|
# Runtime stage
|
||||||
|
|||||||
15
Makefile
15
Makefile
@@ -1,4 +1,4 @@
|
|||||||
.PHONY: all build lint fmt test check clean
|
.PHONY: all build lint fmt fmt-check test check clean
|
||||||
|
|
||||||
BINARY := upaasd
|
BINARY := upaasd
|
||||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
@@ -18,20 +18,15 @@ fmt:
|
|||||||
goimports -w .
|
goimports -w .
|
||||||
npx prettier --write --tab-width 4 static/js/*.js
|
npx prettier --write --tab-width 4 static/js/*.js
|
||||||
|
|
||||||
|
fmt-check:
|
||||||
|
@test -z "$$(gofmt -l .)" || (echo "Files not formatted:" && gofmt -l . && exit 1)
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v -race -cover ./...
|
go test -v -race -cover ./...
|
||||||
|
|
||||||
# Check runs all validation without making changes
|
# Check runs all validation without making changes
|
||||||
# Used by CI and Docker build - fails if anything is wrong
|
# Used by CI and Docker build - fails if anything is wrong
|
||||||
check:
|
check: fmt-check lint test
|
||||||
@echo "==> Checking formatting..."
|
|
||||||
@test -z "$$(gofmt -l .)" || (echo "Files not formatted:" && gofmt -l . && exit 1)
|
|
||||||
@echo "==> Running linter..."
|
|
||||||
golangci-lint run --config .golangci.yml ./...
|
|
||||||
@echo "==> Running tests..."
|
|
||||||
go test -v -race ./...
|
|
||||||
@echo "==> Building..."
|
|
||||||
go build -ldflags "$(LDFLAGS)" -o /dev/null ./cmd/upaasd
|
|
||||||
@echo "==> All checks passed!"
|
@echo "==> All checks passed!"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
Reference in New Issue
Block a user