next #5

Merged
sneak merged 14 commits from next into master 2022-12-09 00:02:35 +00:00
7 changed files with 80 additions and 39 deletions
Showing only changes of commit a9f23c79d2 - Show all commits

View File

@ -3,3 +3,4 @@
/buildimage /buildimage
/dockerdeps /dockerdeps
/tmp /tmp
*.docker.tzst

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ vendor
/tmp /tmp
/buildimage/go.mod /buildimage/go.mod
/buildimage/go.sum /buildimage/go.sum
*.docker.tzst
*.tzst

View File

@ -1,29 +1,47 @@
## lint image FROM golang:1.19.3-bullseye AS cacher
FROM golangci/golangci-lint:v1.50.1
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 RUN mkdir -p /build
WORKDIR /build WORKDIR /build
COPY ./ ./
RUN golangci-lint run
## build image: # install newer protoc
FROM sneak/mfer-build AS builder 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 WORKDIR /build
COPY go.mod .
COPY go.sum .
COPY ./ ./ COPY ./ ./
# don't lint again during build because there's no golangci-lint in this RUN --mount=type=cache,target=/go/pkg go mod download -x && go mod tidy && cd mfer && go generate .
# image and we already did it in a previous stage RUN --mount=type=cache,target=/go/pkg make mfer.cmd && go mod vendor
#RUN make lint RUN tar -c . | zstdmt -19 > /src.tzst
RUN make mfer.cmd
#RUN go mod vendor
RUN tar -c . | bzip2 > /src.tbz2
## lint image
FROM golangci/golangci-lint:v1.50.1 AS linter
COPY --from=cacher /build /build
WORKDIR /build
RUN golangci-lint run
FROM scratch FROM scratch
COPY --from=builder /src.tbz2 /src.tbz2 COPY --from=builder /src.tzst /src.tzst
COPY --from=builder /build/mfer.cmd /mfer COPY --from=builder /build/mfer.cmd /mfer
ENTRYPOINT ["/mfer"] ENTRYPOINT ["/mfer"]

View File

@ -1,8 +1,11 @@
export DOCKER_BUILDKIT := 1 export DOCKER_BUILDKIT := 1
export PROGRESS_NO_TRUNC := 1
GOPATH := $(shell go env GOPATH) GOPATH := $(shell go env GOPATH)
export PATH := $(PATH):$(GOPATH)/bin export PATH := $(PATH):$(GOPATH)/bin
PROTOC_GEN_GO := $(GOPATH)/bin/protoc-gen-go 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) ARCH := $(shell uname -m)
GITREV := $(shell git describe --always --dirty=-dirty) GITREV := $(shell git describe --always --dirty=-dirty)
APPNAME := mfer APPNAME := mfer
@ -12,26 +15,30 @@ GOLDFLAGS += -X main.Version=0.1.0
GOLDFLAGS += -X main.Gitrev=$(GITREV) GOLDFLAGS += -X main.Gitrev=$(GITREV)
GOFLAGS := -ldflags "$(GOLDFLAGS)" GOFLAGS := -ldflags "$(GOLDFLAGS)"
default: test .PHONY: docker default run ci test fixme
default: fmt test
run: ./mfer.cmd run: ./mfer.cmd
./$< ./$<
./$< gen --ignore-dotfiles ./$< gen --ignore-dotfiles
test: fmt ci: test
test:
go test -v --timeout 3s ./... go test -v --timeout 3s ./...
$(PROTOC_GEN_GO): $(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: fixme:
@grep -nir fixme . | grep -v Makefile @grep -nir fixme . | grep -v Makefile
devprereqs: devprereqs:
which gofumpt || go install -v mvdan.cc/gofumpt@latest 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 protoc --version
cd mfer && go generate . cd mfer && go generate .
make test make test
@ -40,7 +47,8 @@ mfer.cmd: mfer/*.go internal/*/*.go cmd/*/*.go
clean: clean:
rm -rfv mfer/*.pb.go mfer.cmd cmd/mfer/mfer rm -rfv mfer/*.pb.go mfer.cmd cmd/mfer/mfer
fmt: devprereqs fmt:
devprereqs
gofumpt -l -w mfer internal cmd gofumpt -l -w mfer internal cmd
golangci-lint run --fix golangci-lint run --fix
-prettier -w *.json -prettier -w *.json
@ -50,9 +58,13 @@ lint:
golangci-lint run golangci-lint run
sh -c 'test -z "$$(gofmt -l .)"' 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 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: godoc:
open http://127.0.0.1:6060 open http://127.0.0.1:6060

View File

@ -2,7 +2,6 @@
set -euxo pipefail set -euxo pipefail
GOI="golang:1.19.3-bullseye" GOI="golang:1.19.3-bullseye"
CII="golangci/golangci-lint:v1.50.1" CII="golangci/golangci-lint:v1.50.1"
BII="sneak/mfer-build"
if [[ ! -d "$DOCKER_IMAGE_CACHE_DIR" ]]; then if [[ ! -d "$DOCKER_IMAGE_CACHE_DIR" ]]; then
mkdir -p "$DOCKER_IMAGE_CACHE_DIR" mkdir -p "$DOCKER_IMAGE_CACHE_DIR"
@ -22,16 +21,6 @@ function buildImageCache() {
docker save $CII | pv | zstdmt -19 > $DICD/ci.tzst.tmp && \ docker save $CII | pv | zstdmt -19 > $DICD/ci.tzst.tmp && \
mv $DICD/ci.tzst.tmp $DICD/ci.tzst mv $DICD/ci.tzst.tmp $DICD/ci.tzst
fi 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() { function loadImageCache() {
@ -40,9 +29,6 @@ function loadImageCache() {
docker image ls $GOI || \ docker image ls $GOI || \
zstdmt -d --stdout $DICD/go.tzst | pv | docker load zstdmt -d --stdout $DICD/go.tzst | pv | docker load
docker image ls $BII || \
zstdmt -d --stdout $DICD/build.tzst | pv | docker load
} }
buildImageCache buildImageCache

23
go.mod
View File

@ -1,6 +1,6 @@
module git.eeqj.de/sneak/mfer module git.eeqj.de/sneak/mfer
go 1.16 go 1.19
require ( require (
github.com/apex/log v1.9.0 github.com/apex/log v1.9.0
@ -10,4 +10,25 @@ require (
github.com/stretchr/testify v1.8.1 github.com/stretchr/testify v1.8.1
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0
google.golang.org/protobuf v1.28.1 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
) )

View File

@ -20,6 +20,7 @@ message MFFileOuter {
// and not for cryptographic integrity. // and not for cryptographic integrity.
int64 size = 103; int64 size = 103;
bytes sha256 = 104; bytes sha256 = 104;
bytes deleteme = 105;
// 2xx for optional manifest root attributes // 2xx for optional manifest root attributes
// think we might use gosignify instead of gpg: // think we might use gosignify instead of gpg: