-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (90 loc) · 4.42 KB
/
Makefile
File metadata and controls
125 lines (90 loc) · 4.42 KB
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
#####################################################################
# Makefile for automating some docker related stuff. #
#####################################################################
# Makefile directory.
MAKEFILE_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
# Project top-level, relative to MAKEFILE_DIR.
PROJECT_ROOT = .
# Variables that influence the build process.
include $(PROJECT_ROOT)/Makefile.vars
# Python virtualenv wrapper. Used for running j2.
PYRUN = $(PROJECT_ROOT)/scripts/pyrun.sh
# All makefile variables - determined at runtime to use as dependencies.
MAKEFILE_VARS = $(wildcard $(PROJECT_ROOT)/Makefile.vars $(PROJECT_ROOT)/Makefile.local.vars)
# Copy command.
CP = cp -vf
# Bootstrap files.
BOOTSTRAP_FILES=$(wildcard resources/bootstrap-*/*)
# Stub file used to determine whether the docker image needs to be updated.
DOCKER_STUB = $(DOCKER_BOOTSTRAP)/.docker_stub
# Files used for docker image bootstrap.
DOCKER_BOOTSTRAP_FILES=$(addprefix $(DOCKER_BOOTSTRAP)/tarballs/,panda.tar bootstrap.tar)
# Directory name to use for runtime bootstrapping of containers when testing.
CTEST_BOOTSTRAP ?= run.1
# GNU extension - all commands of a recipe are executed in the same shell.
.ONESHELL:
#####################################################################
# Prints the addresses of available containers.
define containers_addr
$(shell docker network inspect bridge -f "{{ range .Containers }}{{ .IPv4Address }} {{ end }}")
endef
# Prints name:address pairs for the available containers.
define containers_name_addr
$(shell docker network inspect bridge -f "{{ range .Containers }}{{ .Name }}:{{ .IPv4Address }} {{ end }}")
endef
#####################################################################
.PHONY: all help clean-files clean-ssh clean-docker lsaddr lscont lsimg build
.NOTPARALLEL: all
all: build
$(DOCKER_STUB): Dockerfile $(DOCKER_BOOTSTRAP_FILES) $(MAKEFILE_VARS)
@printf "Changed files: %s\n" "$(?)"
docker build . -t $(IMAGE_NAME) \
--build-arg image_maintainer="$(IMAGE_MAINTAINER)" \
--build-arg image_description="$(IMAGE_DESCRIPTION)" \
--build-arg image_version="$(IMAGE_VERSION)" \
--build-arg image_extra_packages="$(IMAGE_EXTRA_PACKAGES)" \
--build-arg docker_bootstrap="$(DOCKER_BOOTSTRAP)" \
--build-arg panda_path="$(PANDA_PATH)"
touch $(@)
$(DOCKER_BOOTSTRAP)/%:
make -C $(DOCKER_BOOTSTRAP) $(*)
#####################################################################
build: $(DOCKER_STUB) ##- build or refresh the image
sh-%: ##- start a root shell on a running container
@docker exec -t -u root -i $(*) zsh -l
ush-%: ##- start a root shell on a running container
@docker exec -t -u $(DOCKER_USER) -i $(*) zsh -l
ssh-%: ##- ssh to a running container as root
@ssh root@$$(echo $(containers_name_addr) | grep ^$(*) | awk -F'[/:]' '{print $$2}')
ussh-%: ##- ssh to a running container as user
echo ssh $(DOCKER_USER)@$$(echo $(containers_name_addr) | grep ^$(*) | awk -F'[/:]' '{print $$2}')
ctest-%: ##- start a new container with the specified name using IMAGE_NAME
export IMAGE_NAME=$(IMAGE_NAME)
export DOCKER_RUN="$(realpath $(RUNTIME_BOOTSTRAP)/$(CTEST_BOOTSTRAP)/docker)"
[ -z "$$DOCKER_RUN" ] && export DOCKER_RUN="/dev/null"
docker run --net=test --name $(*) -h $(*) \
--mount "type=bind,src=$$DOCKER_RUN,dst=$(PANDA_PATH)/share/bootstrap" \
-i -t "$$IMAGE_NAME"
ctest: ##- start a new container using IMAGE_NAME
export IMAGE_NAME=$(IMAGE_NAME)
export DOCKER_RUN="$(realpath $(RUNTIME_BOOTSTRAP)/$(CTEST_BOOTSTRAP)/docker)"
[ -z "$$DOCKER_RUN" ] && export DOCKER_RUN="/dev/null"
docker run --net=test \
--mount "type=bind,src=$$DOCKER_RUN,dst=$(PANDA_PATH)/share/bootstrap" \
-i -t "$$IMAGE_NAME"
lsimg: ##- list available docker images
@docker image list
lscont: ##- list available docker containers
@docker container list
lsaddr: ##- list IP addresses of available docker containers
@echo $(containers_name_addr) | sed -E 's/ /\n/g' | \
awk -F'[/:]' '{printf("%-20s %s\n", $$1, $$2);}'
clean-docker: ##- clean docker containers
docker container prune -f
docker image prune -f
clean-ssh: ##- remove entries for existing containers from your ssh known_hosts file
$(foreach ip,$(call containers_addr),__a="$(ip)"; ssh-keygen -R $${__a%%/*};)
clean-files: ##- clean files generated during the build process
make -C $(DOCKER_BOOTSTRAP) clean
help: ##- show this help
@sed -e '/#\{2\}-/!d; s/\\$$//; s/:[^#\t]*/:/; s/#\{2\}- *//' $(MAKEFILE_LIST)