From a9f23c79d2e45392aa23bdc7b07e8f0a5620eb05 Mon Sep 17 00:00:00 2001 From: sneak Date: Mon, 5 Dec 2022 14:40:57 +0400 Subject: [PATCH] latest --- .dockerignore | 1 + .gitignore | 2 ++ Dockerfile | 50 +++++++++++++++++++++++++++++-------------- Makefile | 28 +++++++++++++++++------- bin/docker-prereqs.sh | 14 ------------ go.mod | 23 +++++++++++++++++++- mfer/mf.proto | 1 + 7 files changed, 80 insertions(+), 39 deletions(-) diff --git a/.dockerignore b/.dockerignore index ecdb971..f2bcbb8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ /buildimage /dockerdeps /tmp +*.docker.tzst diff --git a/.gitignore b/.gitignore index 074e7cb..d454731 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ vendor /tmp /buildimage/go.mod /buildimage/go.sum +*.docker.tzst +*.tzst diff --git a/Dockerfile b/Dockerfile index 41c2019..4b1f320 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,47 @@ -## lint image -FROM golangci/golangci-lint:v1.50.1 +FROM golang:1.19.3-bullseye AS cacher +ENV GOPATH /go +ENV DEBIAN_FRONTEND noninteractive +RUN --mount=type=cache,target=/var/cache/apt \ + apt update && apt install -y make zstd curl unzip RUN mkdir -p /build WORKDIR /build -COPY ./ ./ -RUN golangci-lint run -## build image: -FROM sneak/mfer-build AS builder +# install newer protoc +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v21.10/protoc-21.10-linux-aarch_64.zip && \ + unzip *.zip -d /usr/local && rm -v *.zip && protoc --version + +RUN go install -v google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1 + +COPY ./go.mod . +COPY ./go.sum . + +RUN --mount=type=cache,target=/go/pkg go mod download -x +RUN go env +## build image +FROM golang:1.19.3-bullseye AS builder + +COPY --from=cacher /usr/local /usr/local +COPY --from=cacher /usr/bin /usr/bin +COPY --from=cacher /go/bin /go/bin +COPY --from=cacher /build /build + WORKDIR /build -COPY go.mod . -COPY go.sum . - COPY ./ ./ -# don't lint again during build because there's no golangci-lint in this -# image and we already did it in a previous stage -#RUN make lint -RUN make mfer.cmd -#RUN go mod vendor -RUN tar -c . | bzip2 > /src.tbz2 +RUN --mount=type=cache,target=/go/pkg go mod download -x && go mod tidy && cd mfer && go generate . +RUN --mount=type=cache,target=/go/pkg make mfer.cmd && go mod vendor +RUN tar -c . | zstdmt -19 > /src.tzst +## lint image +FROM golangci/golangci-lint:v1.50.1 AS linter + +COPY --from=cacher /build /build +WORKDIR /build +RUN golangci-lint run FROM scratch -COPY --from=builder /src.tbz2 /src.tbz2 +COPY --from=builder /src.tzst /src.tzst COPY --from=builder /build/mfer.cmd /mfer ENTRYPOINT ["/mfer"] diff --git a/Makefile b/Makefile index 40b861e..a813846 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,11 @@ export DOCKER_BUILDKIT := 1 +export PROGRESS_NO_TRUNC := 1 GOPATH := $(shell go env GOPATH) export PATH := $(PATH):$(GOPATH)/bin PROTOC_GEN_GO := $(GOPATH)/bin/protoc-gen-go +SOURCEFILES := mfer/*.go mfer/*.proto internal/*/*.go cmd/*/*.go go.mod go.sum + ARCH := $(shell uname -m) GITREV := $(shell git describe --always --dirty=-dirty) APPNAME := mfer @@ -12,26 +15,30 @@ GOLDFLAGS += -X main.Version=0.1.0 GOLDFLAGS += -X main.Gitrev=$(GITREV) GOFLAGS := -ldflags "$(GOLDFLAGS)" -default: test +.PHONY: docker default run ci test fixme + +default: fmt test run: ./mfer.cmd ./$< ./$< gen --ignore-dotfiles -test: fmt +ci: test + +test: go test -v --timeout 3s ./... $(PROTOC_GEN_GO): - test -e $(PROTOC_GEN_GO) || go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest + test -e $(PROTOC_GEN_GO) || go install -v google.golang.org/protobuf/cmd/protoc-gen-go@v1.28.1 fixme: @grep -nir fixme . | grep -v Makefile devprereqs: which gofumpt || go install -v mvdan.cc/gofumpt@latest - which golangci-lint || go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest + which golangci-lint || go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 -mfer.cmd: mfer/*.go internal/*/*.go cmd/*/*.go +mfer.cmd: $(SOURCEFILES) protoc --version cd mfer && go generate . make test @@ -40,7 +47,8 @@ mfer.cmd: mfer/*.go internal/*/*.go cmd/*/*.go clean: rm -rfv mfer/*.pb.go mfer.cmd cmd/mfer/mfer -fmt: devprereqs +fmt: + devprereqs gofumpt -l -w mfer internal cmd golangci-lint run --fix -prettier -w *.json @@ -50,9 +58,13 @@ lint: golangci-lint run sh -c 'test -z "$$(gofmt -l .)"' -docker: +docker: sneak-mfer.$(ARCH).docker.tzst + +sneak-mfer.$(ARCH).docker.tzst: $(SOURCEFILES) bash -x bin/docker-prereqs.sh - docker build . + docker build --progress plain -t sneak/mfer . + docker save sneak/mfer | pv | zstdmt -19 > $@ + du -sh $@ godoc: open http://127.0.0.1:6060 diff --git a/bin/docker-prereqs.sh b/bin/docker-prereqs.sh index 2cd672b..3ef7f63 100644 --- a/bin/docker-prereqs.sh +++ b/bin/docker-prereqs.sh @@ -2,7 +2,6 @@ set -euxo pipefail GOI="golang:1.19.3-bullseye" CII="golangci/golangci-lint:v1.50.1" -BII="sneak/mfer-build" if [[ ! -d "$DOCKER_IMAGE_CACHE_DIR" ]]; then mkdir -p "$DOCKER_IMAGE_CACHE_DIR" @@ -22,16 +21,6 @@ function buildImageCache() { docker save $CII | pv | zstdmt -19 > $DICD/ci.tzst.tmp && \ mv $DICD/ci.tzst.tmp $DICD/ci.tzst fi - - if [[ ! -e "$DICD/build.tzst" ]]; then - go mod download -x - cd buildimage - cp ../go.mod ../go.sum . - docker build -t $BII . && rm -rf go.mod go.sum && \ - cd .. && \ - docker save $BII | pv | zstdmt -19 > $DICD/build.tzst.tmp && \ - mv $DICD/build.tzst.tmp $DICD/build.tzst - fi } function loadImageCache() { @@ -40,9 +29,6 @@ function loadImageCache() { docker image ls $GOI || \ zstdmt -d --stdout $DICD/go.tzst | pv | docker load - - docker image ls $BII || \ - zstdmt -d --stdout $DICD/build.tzst | pv | docker load } buildImageCache diff --git a/go.mod b/go.mod index 92c0feb..5eec910 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.eeqj.de/sneak/mfer -go 1.16 +go 1.19 require ( github.com/apex/log v1.9.0 @@ -10,4 +10,25 @@ require ( github.com/stretchr/testify v1.8.1 github.com/urfave/cli/v2 v2.3.0 google.golang.org/protobuf v1.28.1 + +) + +require ( + github.com/atomicgo/cursor v0.0.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect + github.com/fatih/color v1.7.0 // indirect + github.com/gookit/color v1.4.2 // indirect + github.com/mattn/go-colorable v0.1.2 // indirect + github.com/mattn/go-isatty v0.0.8 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rivo/uniseg v0.2.0 // indirect + github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect + golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect + golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect + golang.org/x/text v0.3.4 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/mfer/mf.proto b/mfer/mf.proto index 9ea8d2e..9bc86b6 100644 --- a/mfer/mf.proto +++ b/mfer/mf.proto @@ -20,6 +20,7 @@ message MFFileOuter { // and not for cryptographic integrity. int64 size = 103; bytes sha256 = 104; + bytes deleteme = 105; // 2xx for optional manifest root attributes // think we might use gosignify instead of gpg: