summary refs log tree commit diff
path: root/.config/yamlfs/go.yml
diff options
context:
space:
mode:
Diffstat (limited to '.config/yamlfs/go.yml')
-rw-r--r--.config/yamlfs/go.yml123
1 files changed, 112 insertions, 11 deletions
diff --git a/.config/yamlfs/go.yml b/.config/yamlfs/go.yml
index f7797be..82f57fe 100644
--- a/.config/yamlfs/go.yml
+++ b/.config/yamlfs/go.yml
@@ -1,21 +1,122 @@
+{% $goversion := 1.14 %}
+{% $gopkg := (printf "example.com/%s" .name) %}
+{% with .pkg %}{% $gopkg = . %}{% end %}
 cmd:
-  app:
-    main.go: |-
+  {% .name %}:
+    main.go: |
       package main
 
       func main() {
         println("hello world")
       }
 
-go.mod: |-
-  module example.com/app
+version:
+  version.go: |
+    package version
 
-  go 1.13
+    var (
+    	Version = "0.0.0+unknown"
+    	Revision = ""
+    )
 
-contrib:
-  data: {}
+go.mod: |
+  module {% $gopkg %}
 
-README.md: |-
-  # app
-  
-  this is an app
+  go {% $goversion %}
+
+Dockerfile: |
+  #syntax=docker/dockerfile:experimental
+
+  FROM docker.io/library/golang:{% $goversion %}-alpine AS base
+  RUN apk add -U --no-cache \
+      ca-certificates
+
+  FROM base AS build
+  WORKDIR /src
+  RUN --mount=target=/src,rw \
+      --mount=type=cache,target=/go/pkg \
+      --mount=type=cache,target=/root/.cache/go-build \
+      make all
+
+  FROM base AS run
+  COPY --from=dev /src/{% .name %} /usr/local/bin/
+  ENTRYPOINT [ "{% .name %}" ]
+
+  FROM scratch AS final
+  COPY --from=build /src/{% .name %} /
+
+Makefile: |
+  .POSIX:
+
+  all: validate test {% .name %}
+
+  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)
+
+  build: {% .name %}
+  {% .name %}:
+  	$(GO) build \
+  		-tags '$(GO_BUILDTAGS)' -ldflags '$(GO_LDFLAGS) $(GO_VERSIONFLAGS)' \
+  		-o {% .name %} \
+  		./cmd/{% .name %}
+
+  RM ?= rm -f
+
+  clean:
+  	$(RM) {% .name %}
+
+  container-build:
+  	DOCKER_BUILDKIT=1 \
+  	docker build --target final -o . .
+
+  GOLANGCI_LINT ?= golangci-lint
+  validate:
+  	$(GOLANGCI_LINT) run --build-tags "$(GO_BUILDTAGS)"
+
+  GOTEST_FLAGS ?=
+  ifneq ($(shell which gotestsum),)
+  GOTEST ?= gotestsum --format=testname --
+  else
+  GOTEST ?= go test
+  endif
+  test:
+  	$(GOTEST) \
+  		-tags '$(GO_BUILDTAGS)' \
+  		-cover \
+  		-covermode=atomic \
+  		$(GOTEST_FLAGS)
+
+  .PHONY: all build clean container-build test validate
+
+.editorconfig: |
+  ; http://editorconfig.org/
+
+  root = true
+
+  [*]
+  insert_final_newline = true
+  charset = utf-8
+  trim_trailing_whitespace = true
+  indent_style = space
+  indent_size = 2
+
+  [{Makefile,go.mod,go.sum,*go}]
+  indent_style = tab
+  indent_size = 8
+
+  [*.md]
+  trim_trailing_whitespace = false
+
+  [Dockerfile]
+  indent_size = 4
+
+README.md: |
+  # {% .name %}
+
+  TODO