From 098ba6bcb8fb796d06a32986aec4e3cb6397b56e Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Fri, 12 Jan 2024 10:11:51 +0100 Subject: [PATCH] Get rid of builder dependency --- Dockerfile | 16 +++++++++------- Makefile | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index a10d5fe..6182879 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,11 @@ -# FIXME this points to the last go-1.20 image of the builder, -# go-1.21 can't be used actually because bookworm mangled libsystemd-dev which breaks the build -# and go-1.21 is not available with bullseye. -# maybe we should switch away from depending on the builder image -FROM metalstack/builder@sha256:d2050a3bef9bbd9d9ea769a71a4a70b9ff4b24c537d29d5870b83fc652bb67f8 as builder +FROM golang:1.21-bookworm as builder + +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + libpcap-dev +WORKDIR /work +COPY . . +RUN make all # Install Intel Firmware for e800 based network cards ENV ICE_VERSION=1.13.7 ENV ICE_PKG_VERSION=1.3.35.0 @@ -46,10 +49,9 @@ RUN mkdir -p /work/etc/lvm /work/etc/ssl/certs /work/lib/firmware/intel/ice/ddp/ && cp /usr/share/zoneinfo/Etc/UTC /work/etc/localtime COPY lvmlocal.conf metal.key metal.key.pub passwd varrun Makefile .git /work/ COPY --from=r.metal-stack.io/metal/supermicro:2.13.0 /usr/bin/sum /work/ -COPY --from=builder /common /common COPY --from=builder /work/ice.pkg /work/ice.pkg COPY --from=builder /work/bin/metal-hammer /work/bin/ -RUN COMMONDIR=/common make ramdisk +RUN make ramdisk FROM scratch COPY --from=builder /work/bin/metal-hammer / diff --git a/Makefile b/Makefile index f38e5cb..39b5aae 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,49 @@ +.ONESHELL: +SHA := $(shell git rev-parse --short=8 HEAD) +GITVERSION := $(shell git describe --long --all) +BUILDDATE := $(shell date --iso-8601=seconds) +VERSION := $(or ${VERSION},$(shell git describe --tags --exact-match 2> /dev/null || git symbolic-ref -q --short HEAD || git rev-parse --short HEAD)) +CGO_ENABLED := $(or ${CGO_ENABLED},0) +GO := go +GOSRC = $(shell find . -not \( -path vendor -prune \) -type f -name '*.go') + BINARY := metal-hammer INITRD := ${BINARY}-initrd.img COMPRESSOR := lz4 COMPRESSOR_ARGS := -f -l INITRD_COMPRESSED := ${INITRD}.${COMPRESSOR} MAINMODULE := . -COMMONDIR := $(or ${COMMONDIR},../builder) CGO_ENABLED := 1 # export CGO_LDFLAGS := "-lsystemd" "-lpcap" "-ldbus-1" -in-docker: gofmt test all; -include $(COMMONDIR)/Makefile.inc +.PHONY: all +all:: bin/$(BINARY); + +in-docker: all; + +ifeq ($(CGO_ENABLED),1) + LINKMODE := -linkmode external -extldflags '-static -s -w' +endif + +LINKMODE := $(LINKMODE) \ + -X 'github.com/metal-stack/v.Version=$(VERSION)' \ + -X 'github.com/metal-stack/v.Revision=$(GITVERSION)' \ + -X 'github.com/metal-stack/v.GitSHA1=$(SHA)' \ + -X 'github.com/metal-stack/v.BuildDate=$(BUILDDATE)' + +bin/$(BINARY): test $(GOSRC) + $(info CGO_ENABLED="$(CGO_ENABLED)") + $(GO) build \ + -tags netgo \ + -ldflags \ + "$(LINKMODE)" \ + -o bin/$(BINARY) \ + $(MAINMODULE) -release:: gofmt test all ; +.PHONY: test +test: + CGO_ENABLED=1 $(GO) test -cover ./... .PHONY: clean clean::