summary refs log tree commit diff
path: root/.config/yamlfs
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2021-01-21 19:33:10 +0100
committerRobert Günzler <r@gnzler.io>2021-01-21 19:40:20 +0100
commit72c39240811f1def43fca71de51566d206f7728d (patch)
treea33aa1331fc55b587a243f64ef94d781df40a8ae /.config/yamlfs
parent0762801ed9627021e732cdeb225a737f44e3df42 (diff)
Update 2021-01-21T18:33:10Z
Diffstat (limited to '.config/yamlfs')
-rw-r--r--.config/yamlfs/go.yml54
1 files changed, 38 insertions, 16 deletions
diff --git a/.config/yamlfs/go.yml b/.config/yamlfs/go.yml
index a634f92..21fb36d 100644
--- a/.config/yamlfs/go.yml
+++ b/.config/yamlfs/go.yml
@@ -1,6 +1,4 @@
-{% $goversion := 1.14 %}
-{% $gopkg := (printf "example.com/%s" .name) %}
-{% with .pkg %}{% $gopkg = . %}{% end %}
+{% $goversion := 1.15 %}
 cmd:
   {% .name %}:
     main.go: |
@@ -15,12 +13,13 @@ version:
     package version
 
     var (
-    	Version = "0.0.0+unknown"
+    	Package = "{% .gopkg %}"
     	Revision = ""
+    	Version = "0.0.0+unknown"
     )
 
 go.mod: |
-  module {% $gopkg %}
+  module {% .gopkg %}
 
   go {% $goversion %}
 
@@ -28,15 +27,30 @@ Dockerfile: |
   # syntax=docker/dockerfile:1.1-experimental
   # vim: ft=dockerfile
 
-  FROM --platform=$BUILDPLATFORM docker.io/library/alpine:3.11 AS base
-  RUN apk add -U --no-cache ca-certificates
+  ARG GO_VERSION={% $goversion %}
 
-  FROM --platform=$BUILDPLATFORM docker.io/tonistiigi/xx:golang AS xx
-  FROM --platform=$BUILDPLATFORM docker.io/library/golang:{% $goversion %}-alpine AS build
+  FROM --platform=${BUILDPLATFORM:?err} docker.io/tonistiigi/xx:golang AS xx
+  FROM --platform=${BUILDPLATFORM:?err} docker.io/library/golang:${GO_VERSION:?err}-alpine AS buildenv
   COPY --from=xx / /
   ARG TARGETPLATFORM
   WORKDIR /src
-  RUN apk add -U --no-cache make
+  RUN apk --update-cache --no-cache add make
+
+  FROM buildenv AS gotestsum
+  RUN go get gotest.tools/gotestsum@0.6.0
+
+  FROM buildenv AS golangcilint
+  RUN go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.27.0
+
+  FROM buildenv AS test
+  COPY --from=gotestsum /go/bin/gotestsum /usr/local/bin/
+  COPY --from=golangcilint /go/bin/golangci-lint /usr/local/bin/
+  RUN --mount=target=/src,rw \
+      --mount=type=cache,target=/go/pkg \
+      --mount=type=cache,target=/root/.cache \
+      make DESTDIR=/out clean validate test
+
+  FROM buildenv AS build
   RUN --mount=target=/src,rw \
       --mount=type=cache,target=/go/pkg \
       --mount=type=cache,target=/root/.cache \
@@ -45,7 +59,10 @@ Dockerfile: |
   FROM scratch AS final
   COPY --from=build /out/{% .name %} /
 
-  FROM base AS run
+  FROM --platform=${TARGETPLATFORM:?err} docker.io/library/alpine:3.11 AS runtime-base
+  RUN apk --update-cache --no-cache add ca-certificates
+
+  FROM runtime-base AS run
   COPY --from=build /out/{% .name %} /usr/local/bin/
   ENTRYPOINT [ "{% .name %}" ]
 
@@ -60,10 +77,10 @@ Makefile: |
   REVISION ?= $(shell git rev-parse HEAD)
 
   GO ?= go
-  GO_PKG ?= {% $gopkg %}
+  GO_PKG ?= {% .gopkg %}
   GO_BUILDTAGS ?= netgo osusergo static_build
   GO_LDFLAGS ?= -s -w -extldflags "-static"
-  GO_VERSIONFLAGS = -X {% $gopkg %}/version.Version=$(VERSION) -X {% $gopkg %}/version.Revision=$(REVISION)
+  GO_VERSIONFLAGS = -X $(GO_PKG)/version.Version=$(VERSION) -X $(GO_PKG)/version.Revision=$(REVISION)
 
   .PHONY: build
   build: {% .name %}
@@ -82,6 +99,11 @@ Makefile: |
   	DOCKER_BUILDKIT=1 \
   	docker build --platform $(PLATFORM) --target final -o . .
 
+  .PHONY: container-test
+  container-test:
+  	DOCKER_BUILDKIT=1 \
+  	docker build --platform $(PLATFORM) --target test -o type=tar,dest=/dev/null .
+
   .PHONY: container-image
   container-image:
   	DOCKER_BUILDKIT=1 \
@@ -138,9 +160,9 @@ Makefile: |
   	@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 "  DESTDIR, PREFIX   output location (default: $(DESTDIR)/$(PREFIX))\n"
+  	@printf "  PLATFORM          output platform (default: $(PLATFORM))\n"
+  	@printf "  REPO, TAG         image repository:tag (default: $(REPO):$(TAG))\n"
   	@printf "\n"
 
 .editorconfig: |