diff --git a/build/Dockerfile b/build/Dockerfile index 37afd89..8b69bba 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,5 +1,8 @@ FROM golang:1.25.1-alpine AS base +# CGo is not Go +ENV CGO_ENABLED=0 + # Install go dependencies WORKDIR /src COPY ./go.mod ./go.sum ./ @@ -9,6 +12,14 @@ RUN go mod download COPY ./cmd /src/cmd COPY ./internal /src/internal -ENV CGO_ENABLED=0 +CMD ["go", "run", "./cmd/..."] + +FROM base AS test + +# CGo must be enabled for the -race flag +ENV CGO_ENABLED=1 + +# need to pull in gcc for -race flag +RUN apk add build-base -CMD ["go", "run", "./cmd/..."] \ No newline at end of file +CMD ["go", "test", "-race", "./..."] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 14e338a..a8d24dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,8 +17,7 @@ services: - ./go.mod:/src/go.mod:delegated - ./go.sum:/src/go.sum:delegated - ./cmd:/src/cmd:delegated - - ./service:/src/service:delegated - - ./store:/src/store:delegated + - ./internal:/src/internal:delegated # go cache for compiling - go-mod-cache:/go/pkg/mod/cache - go-build-cache:/root/.cache @@ -107,6 +106,36 @@ services: interval: 2s timeout: 1s retries: 5 + test: + build: + context: . + dockerfile: build/Dockerfile + target: test + volumes: + # Mount only the Go code into src + - ./go.mod:/src/go.mod:delegated + - ./go.sum:/src/go.sum:delegated + - ./cmd:/src/cmd:delegated + - ./internal:/src/internal:delegated + # go cache for compiling + - go-mod-cache:/go/pkg/mod/cache + - go-build-cache:/root/.cache + + lint: + image: golangci/golangci-lint:v2.5.0-alpine + command: golangci-lint fmt && golangci-lint run + working_dir: /src + volumes: + # Mount only the Go code into src + - ./go.mod:/src/go.mod:delegated + - ./go.sum:/src/go.sum:delegated + - ./cmd:/src/cmd:delegated + - ./internal:/src/internal:delegated + # mount linter config + - ./.golangci.yml:/src/.golangci.yml + # go cache for compiling + - go-mod-cache:/go/pkg/mod/cache + - go-build-cache:/root/.cache volumes: go-mod-cache: