From 12c3b5f7848507ed641ba603ad5520089ce56257 Mon Sep 17 00:00:00 2001 From: Ruben Jenster Date: Mon, 20 Dec 2021 21:43:20 +0000 Subject: [PATCH] add Dockerfile and build script --- Dockerfile | 12 ++++++++++++ Makefile | 25 +++++++++++++++---------- build.sh | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 Dockerfile create mode 100755 build.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7a70e35 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM docker.io/library/golang:1.17-alpine3.14 as build +RUN apk --no-cache add make build-base git +ARG GONOSUMDB +ARG GOPROXY +ARG GOBIN=/opt/bin +ARG RELEASE="${RELEASE:-undefined}" +WORKDIR /build +ADD . . +RUN STATIC=true make install + +FROM scratch +COPY --from=build /opt/bin/goget / diff --git a/Makefile b/Makefile index 9c6c786..6092bc2 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,17 @@ -BUILD_HASH := $(shell git describe --always --tags --long) -LDFLAGS := "-X main.version=${BUILD_HASH} -s -w" +COMMIT = $(shell git describe --always --tags --long --dirty) + +RELEASE ?= $(COMMIT) +LDFLAGS := -X main.version=$(RELEASE) + +ifdef STATIC +LDFLAGS += -w -s -extldflags=-static +export CGO_ENABLED=0 +endif + +all: fmt install + +fmt: + go fmt ./... -.PHONY: install install: - go fmt ./... - go install -ldflags ${LDFLAGS} ./... - -.PHONY: build -build: - go fmt ./... - go build -ldflags ${LDFLAGS} ./... + go install -ldflags "${LDFLAGS}" ./... diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..05f6330 --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +#!/bin/sh -eu + +image="harbor.intern.drachenfels.de/shieldos/goget" +version="$(git describe --always --tags --dirty)" + +buildah bud --layers \ + --build-arg GOPROXY=$GOPROXY \ + --build-arg GONOSUMDB=$GONOSUMDB \ + --build-arg RELEASE=$version \ + -t $image:latest \ + -t $image:$version + +buildah push $image:latest +buildah push $image:$version