From 3e323b7301b76582e5c12db61ed00ff8ceb6d00f Mon Sep 17 00:00:00 2001 From: Daniel Voogsgerd Date: Mon, 28 Oct 2024 17:17:14 +0100 Subject: [PATCH 1/2] feat: Add Makefile I opted for Makefile here as it is ubiquitous and I hope the limitations of the language can keep us from creating overly complex build systems. --- Makefile | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..46f28471 --- /dev/null +++ b/Makefile @@ -0,0 +1,79 @@ +# Makefile +# This file is used to compile various parts of the Brane infrastructure and tooling +# +# +CENTRAL_SERVICES := brane-api brane-drv brane-plr +WORKER_SERVICES := brane-job brane-reg brane-chk +SHARED_SERVICES := brane-prx + +BINARY_TARGETS := brane-ctl brane-cli brane-let + +BUILD_DIR := target +IMAGE_DIR := $(BUILD_DIR)/debug +BIN_DIR := $(BUILD_DIR)/debug + +WORKSPACE_MEMBERS := $(sort $(CENTRAL_SERVICES) $(WORKER_SERVICES) $(SHARED_SERVICES)) + +BUILDX_ARGS := build +CARGO_BUILD_ARGS := +IMAGE_DOCKER_FILE := ./Dockerfile.dev + +# The binaries we can build in either debug or release mode +ifeq ($(PROFILE),release) + CARGO_BUILD_ARGS += --release + IMAGE_DOCKER_FILE := ./Dockerfile.rls + IMAGE_DIR := $(BUILD_DIR)/release + BIN_DIR := $(BUILD_DIR)/release +endif + +# Sometimes docker buildx can take a cached version while there are actually some changes. With +# `FORCE` you can make sure it is rebuild anyway. +ifeq ($(FORCE),1) + BUILDX_ARGS += --no-cache +endif + +# Universal targets +.PHONY: all +all: $(WORKSPACE_MEMBERS) + +.PHONY: binaries +binaries: $(BINARY_TARGETS) + +.PHONY: images +images: $(WORKSPACE_MEMBERS) + +.PHONY: worker-images +worker-images: $(WORKER_SERVICES) $(SHARED_SERVICES) + +.PHONY: central-images +central-images: $(CENTRAL_SERVICES) $(SHARED_SERVICES) + +# Compilation of images +# Building of images relies heavily on docker buildx. This is due to the dynamic linking requirements of Brane +# This way we can compile Brane in a similar/identical environment as we will end up running them. +.PHONY: $(WORKSPACE_MEMBERS) +$(WORKSPACE_MEMBERS): $(IMAGE_DIR) + @echo "Building $@" + docker buildx $(BUILDX_ARGS) --output type="docker,dest=$(IMAGE_DIR)/$@.tar" --file $(IMAGE_DOCKER_FILE) --target $@ . + +# Compilation of binaries +.PHONY: $(BINARY_TARGETS) +$(BINARY_TARGETS): $(BIN_DIR) + @echo "Building $@" + cargo build $(CARGO_BUILD_ARGS) --package $@ + +# Directory creation +# It is important that we flag this directory as a CACHETAG.DIR. Various backup solutions for example will otherwise backup +# the directory. This might seem nice, but these artifacts can be very large in size and should be reproducible anyway. +.PHONY: $(BUILD_DIR) +$(BUILD_DIR): + mkdir $(BUILD_DIR) || echo "Directory $(BUILD_DIR) already exists" + [ -f "$(BUILD_DIR)/CACHEDIR.TAG" ] || echo "Signature: 8a477f597d28d172789f06886806bc55" > "$(BUILD_DIR)/CACHEDIR.TAG" + +.PHONY: $(IMAGE_DIR) +$(IMAGE_DIR): $(BUILD_DIR) + mkdir $(IMAGE_DIR) || echo "Directory $(IMAGE_DIR) already exists" + +.PHONY: $(BIN_DIR) +$(BIN_DIR): $(BUILD_DIR) + mkdir $(BIN_DIR) || echo "Directory $(BIN_DIR) already exists" From ca06895b46850b17ee0079620d2fae80f87c42b6 Mon Sep 17 00:00:00 2001 From: Daniel Voogsgerd Date: Mon, 28 Oct 2024 20:25:24 +0100 Subject: [PATCH 2/2] feat(make): Add BUILDX_BUILDER argument --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 46f28471..6a25084b 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,11 @@ ifeq ($(FORCE),1) BUILDX_ARGS += --no-cache endif +# Add a way to select what buildx builder to use +ifdef BUILDX_BUILDER + BUILDX_ARGS += --builder $(BUILDX_BUILDER) +endif + # Universal targets .PHONY: all all: $(WORKSPACE_MEMBERS)