Skip to content

Commit

Permalink
Get rid of builder dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Jan 12, 2024
1 parent 0c3e1f0 commit 098ba6b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 /
Expand Down
39 changes: 35 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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::
Expand Down

0 comments on commit 098ba6b

Please sign in to comment.