forked from onnovalkering/brane
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
84 lines (67 loc) · 2.63 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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
# 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)
.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"