-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
130 lines (91 loc) · 2.41 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# Makefile for One-Shot Docker Builder
#
# Note that this is for development and container image builds.
#
# Set this to a Docker image to use something other than the default.
# CONTAINER_FROM := ghcr.io/perfsonar/unibuild/el9:latest
# Set this to clone a Git repo instead of using the provided example.
#CLONE := https://github.com/perfsonar/unibuild.git
# Example: Build Unibuild.
# # CONTAINER_FROM := The default is fine.
# CLONE := https://github.com/perfsonar/unibuild.git
# # CLONE_BRANCH := Not Applicable
# Example: Build pScheduler
#CONTAINER_FROM := ghcr.io/perfsonar/unibuild/el8:latest
#CLONE := https://github.com/perfsonar/pscheduler.git
#CLONE_BRANCH := 5.0.0
# ----- NO USER-SERVICEABLE PARTS BELOW THIS LINE -----
ifndef CONTAINER_IMAGE
CONTAINER_FROM=almalinux:8
endif
ifneq ($(shell id -u),0)
DOCKER=sudo docker
else
DOCKER=docker
endif
default: run
# Where the build happens.
BUILD_AREA := ./build-area
$(BUILD_AREA)::
rm -rf "$@"
mkdir -p "$@"
TO_CLEAN += $(BUILD_AREA)
ifdef CLONE
BUILD_DIR := $(BUILD_AREA)/$(shell basename '$(CLONE)' .git)
ifdef CLONE_BRANCH
BRANCH_ARG := --branch '$(CLONE_BRANCH)'
endif
else
BUILD_DIR := $(BUILD_AREA)/test-product
endif
$(BUILD_DIR): $(BUILD_AREA)
ifdef CLONE
git -C $(BUILD_AREA) clone $(BRANCH_ARG) "$(CLONE)"
else
cp -r test-product "$(BUILD_AREA)"
endif
IMAGE := builder
CONTAINER_NAME := builder-test
default: run
BUILT := .built
ifdef CONTAINER_FROM
IMAGE_ARG := --build-arg 'FROM=$(CONTAINER_FROM)'
endif
$(BUILT): prep Dockerfile Makefile
$(DOCKER) build \
$(IMAGE_ARG) \
--tag $(IMAGE) \
.
touch $@
TO_CLEAN += $(BUILT)
image: $(BUILT)
BUILD_ARGS += \
--name "$(CONTAINER_NAME)" \
--absolute \
"$(BUILD_DIR)" "$(IMAGE)"
# Show the command to run the container (for debug)
command::
@./build --command $(BUILD_ARGS)
RUN_DEPS := $(BUILT) $(BUILD_DIR) build
# Run the container and exit
run: $(RUN_DEPS)
./build $(BUILD_ARGS)
# Run the container but don't exit (for debug)
persist: $(RUN_DEPS)
./build --no-halt $(BUILD_ARGS)
# Log into the persisted container
shell:
$(DOCKER) exec -it "$(CONTAINER_NAME)" bash
# Stop the persisted container
halt:
$(DOCKER) exec -it "$(CONTAINER_NAME)" halt
# Remove the container
rm:
-$(DOCKER) exec -it "$(CONTAINER_NAME)" halt
$(DOCKER) rm -f "$(CONTAINER_NAME)"
clean: rm
make -C prep clean
make -C test-product clean
$(DOCKER) image rm -f "$(IMAGE)"
rm -rf $(TO_CLEAN) *~