Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 ./
Expand All @@ -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/..."]
CMD ["go", "test", "-race", "./..."]
33 changes: 31 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down