diff options
| author | Robert Günzler <r@gnzler.io> | 2020-04-29 22:28:12 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2020-04-29 23:31:35 +0200 |
| commit | d33fd7092e21ece68da41e21179a6ebf3305a1e4 (patch) | |
| tree | 0ca15c826a395dba58b1d00c4394190ea3152c3a /.config/yamlfs | |
| parent | 4e2d42677a8a15b3c6d058227aeb8b86861bb3dc (diff) | |
yamlfs: Add platform support to go template
also adds buildkit multi-platform builder
Diffstat (limited to '.config/yamlfs')
| -rw-r--r-- | .config/yamlfs/go.yml | 91 | ||||
| -rw-r--r-- | .config/yamlfs/helm.yml | 16 |
2 files changed, 86 insertions, 21 deletions
diff --git a/.config/yamlfs/go.yml b/.config/yamlfs/go.yml index 82f57fe..a634f92 100644 --- a/.config/yamlfs/go.yml +++ b/.config/yamlfs/go.yml @@ -25,57 +25,84 @@ go.mod: | go {% $goversion %} Dockerfile: | - #syntax=docker/dockerfile:experimental + # syntax=docker/dockerfile:1.1-experimental + # vim: ft=dockerfile - FROM docker.io/library/golang:{% $goversion %}-alpine AS base - RUN apk add -U --no-cache \ - ca-certificates + FROM --platform=$BUILDPLATFORM docker.io/library/alpine:3.11 AS base + RUN apk add -U --no-cache ca-certificates - FROM base AS build + FROM --platform=$BUILDPLATFORM docker.io/tonistiigi/xx:golang AS xx + FROM --platform=$BUILDPLATFORM docker.io/library/golang:{% $goversion %}-alpine AS build + COPY --from=xx / / + ARG TARGETPLATFORM WORKDIR /src + RUN apk add -U --no-cache make RUN --mount=target=/src,rw \ --mount=type=cache,target=/go/pkg \ - --mount=type=cache,target=/root/.cache/go-build \ - make all + --mount=type=cache,target=/root/.cache \ + make DESTDIR=/out clean build + + FROM scratch AS final + COPY --from=build /out/{% .name %} / FROM base AS run - COPY --from=dev /src/{% .name %} /usr/local/bin/ + COPY --from=build /out/{% .name %} /usr/local/bin/ ENTRYPOINT [ "{% .name %}" ] - FROM scratch AS final - COPY --from=build /src/{% .name %} / - Makefile: | .POSIX: all: validate test {% .name %} + DESTDIR ?= . + PREFIX ?= + VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='+dev' --always --tags) + REVISION ?= $(shell git rev-parse HEAD) + GO ?= go GO_PKG ?= {% $gopkg %} GO_BUILDTAGS ?= netgo osusergo static_build GO_LDFLAGS ?= -s -w -extldflags "-static" - - VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='+dev' --always --tags) - REVISION ?= $(shell git rev-parse HEAD) GO_VERSIONFLAGS = -X {% $gopkg %}/version.Version=$(VERSION) -X {% $gopkg %}/version.Revision=$(REVISION) + .PHONY: build build: {% .name %} {% .name %}: $(GO) build \ -tags '$(GO_BUILDTAGS)' -ldflags '$(GO_LDFLAGS) $(GO_VERSIONFLAGS)' \ - -o {% .name %} \ + -o $(DESTDIR)$(PREFIX)/{% .name %} \ ./cmd/{% .name %} - RM ?= rm -f - - clean: - $(RM) {% .name %} + PLATFORM ?= linux/amd64 + REPO ?= {% .name %} + TAG ?= $(VERSION) + .PHONY: container-build container-build: DOCKER_BUILDKIT=1 \ - docker build --target final -o . . + docker build --platform $(PLATFORM) --target final -o . . + + .PHONY: container-image + container-image: + DOCKER_BUILDKIT=1 \ + docker build --platform $(PLATFORM) --target run -t $(REPO):$(TAG) . + + .PHONY: cross + cross: + docker run --rm -it --privileged \ + --mount type=bind,src=$(PWD),dst=/src \ + --entrypoint buildctl-daemonless.sh \ + moby/buildkit:latest \ + buildctl build --frontend=dockerfile.v0 \ + --local context=/src --local dockerfile=/src \ + --opt filename=Dockerfile \ + --opt platform=$(PLATFORM) \ + --opt target=run \ + --output type=image,name=$(REPO):$(TAG),push=true GOLANGCI_LINT ?= golangci-lint + + .PHONY: validate validate: $(GOLANGCI_LINT) run --build-tags "$(GO_BUILDTAGS)" @@ -85,6 +112,8 @@ Makefile: | else GOTEST ?= go test endif + + .PHONY: test test: $(GOTEST) \ -tags '$(GO_BUILDTAGS)' \ @@ -92,7 +121,27 @@ Makefile: | -covermode=atomic \ $(GOTEST_FLAGS) - .PHONY: all build clean container-build test validate + RM ?= rm -f + + .PHONY: clean + clean: + $(RM) {% .name %} + + .PHONY: help + help: + @printf "usage:\n" + @printf "\n" + @printf " build local build\n" + @printf " validate linter\n" + @printf " test tests\n" + @printf " container-build build w/ docker\n" + @printf " container-image image build\n" + @printf " cross build w/ buildkit (multi-platform support)\n" + @printf "\n" + @printf " DESTDIR, PREFIX output location\n" + @printf " PLATFORM output platform\n" + @printf " REPO, TAG image repository:tag\n" + @printf "\n" .editorconfig: | ; http://editorconfig.org/ diff --git a/.config/yamlfs/helm.yml b/.config/yamlfs/helm.yml index f15f02c..67d9995 100644 --- a/.config/yamlfs/helm.yml +++ b/.config/yamlfs/helm.yml @@ -41,6 +41,22 @@ README.md: |- | resources.limits.memory | | | resources.limits.cpu | | +.editorconfig: |- + ; http://editorconfig.org/ + + root = true + + [*] + charset = utf-8 + end_of_line = lf + indent_style = space + + [*.yaml] + indent_size = 2 + + [*.md] + trim_trailing_whitespace = false + Chart.yaml: |- apiVersion: v1 name: {% .name %} |