Skip to content

Commit

Permalink
Container based developer flow
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max authored and thaJeztah committed Aug 3, 2021
1 parent 784c260 commit 566803f
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 146 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/coverage.txt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/coverage.txt
47 changes: 47 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
variable "GO_VERSION" {
default = "1.16"
}

group "default" {
targets = ["test"]
}

group "validate" {
targets = ["lint", "vendor-validate"]
}

target "lint" {
args = {
GO_VERSION = GO_VERSION
}
dockerfile = "./hack/lint.Dockerfile"
target = "lint"
output = ["type=cacheonly"]
}

target "vendor-validate" {
args = {
GO_VERSION = GO_VERSION
}
dockerfile = "./hack/vendor.Dockerfile"
target = "validate"
output = ["type=cacheonly"]
}

target "vendor-update" {
args = {
GO_VERSION = GO_VERSION
}
dockerfile = "./hack/vendor.Dockerfile"
target = "update"
output = ["."]
}

target "test" {
args = {
GO_VERSION = GO_VERSION
}
dockerfile = "./hack/test.Dockerfile"
target = "test-coverage"
output = ["."]
}
117 changes: 0 additions & 117 deletions docs/yamlgen/generate.go

This file was deleted.

19 changes: 0 additions & 19 deletions hack/dockerfiles/yamldocs.Dockerfile

This file was deleted.

10 changes: 0 additions & 10 deletions hack/generate-yamldocs

This file was deleted.

15 changes: 15 additions & 0 deletions hack/lint.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# syntax=docker/dockerfile:1.3
ARG GO_VERSION

FROM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache linux-headers
WORKDIR /src

FROM golangci/golangci-lint:v1.37-alpine AS golangci-lint

FROM base AS lint
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/.cache/golangci-lint \
--mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \
golangci-lint run --timeout 10m0s ./...
20 changes: 20 additions & 0 deletions hack/test.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# syntax=docker/dockerfile:1.2
ARG GO_VERSION

FROM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache gcc linux-headers musl-dev
WORKDIR /src

FROM base AS gomod
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/go/pkg/mod \
go mod tidy && go mod download

FROM gomod AS test
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic -race ./...

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage.txt /coverage.txt
24 changes: 24 additions & 0 deletions hack/vendor.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# syntax=docker/dockerfile:1.3
ARG GO_VERSION

FROM golang:${GO_VERSION}-alpine AS base
RUN apk add --no-cache git
WORKDIR /src

FROM base AS vendored
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/go/pkg/mod \
go mod tidy && go mod download && \
mkdir /out && cp go.mod go.sum /out

FROM scratch AS update
COPY --from=vendored /out /

FROM vendored AS validate
RUN --mount=type=bind,target=.,rw \
git add -A && cp -rf /out/* .; \
if [ -n "$(git status --porcelain -- go.mod go.sum)" ]; then \
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'; \
git status --porcelain -- go.mod go.sum; \
exit 1; \
fi

0 comments on commit 566803f

Please sign in to comment.