aboutsummaryrefslogtreecommitdiffstats
path: root/docs/usecases/vpp_testbench/src/Makefile
blob: 4433edbe4d7f51b98c04aa1fc1e7e823c07a7ce5 (plain)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
################################################################################
# @brief:       Makefile for building the VPP testbench example.
# @author:      Matthew Giassa.
# @copyright:   (C) Cisco 2021.
################################################################################
#------------------------------------------------------------------------------#
# Constants and settings.
#------------------------------------------------------------------------------#
SHELL=/bin/bash
.DEFAULT_GOAL: all

# Image names.
# TODO: semver2 format if we want to publish these to a registry.
DOCKER_CLIENT_IMG               := vpp-testbench-client
DOCKER_CLIENT_REL               := local
DOCKER_CLIENT_IMG_FULL          := $(DOCKER_CLIENT_IMG):$(DOCKER_CLIENT_REL)
DOCKER_SERVER_IMG               := vpp-testbench-server
DOCKER_SERVER_REL               := local
DOCKER_SERVER_IMG_FULL          := $(DOCKER_SERVER_IMG):$(DOCKER_SERVER_REL)
# Docker build-time settings (and run-time settings as well).
DOCKER_HEALTH_PROBE_PORT        := $(shell bash -c ". vpp_testbench_helpers.sh; host_only_get_docker_health_probe_port")

#------------------------------------------------------------------------------#
# Functions.
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# Cleanup running containers, Docker networks, etc.; from previous runs.
define cleanup_everything
	# Terminate the containers.
	bash -c "\
		. vpp_testbench_helpers.sh; \
		host_only_kill_testbench_client_container $(DOCKER_CLIENT_IMG_FULL); \
		host_only_kill_testbench_server_container $(DOCKER_SERVER_IMG_FULL); \
		"

	# Cleanup Docker bridge network.
	bash -c "\
		. vpp_testbench_helpers.sh; \
		host_only_destroy_docker_networks; \
		"
endef

#------------------------------------------------------------------------------#
# Launch our containers and connect them to a private Docker network for
# testing.
define launch_testbench
	# Create Docker bridge network.
	bash -c "\
		. vpp_testbench_helpers.sh; \
		host_only_create_docker_networks; \
		"

	# Launch the containers.
	bash -c "\
		. vpp_testbench_helpers.sh; \
		host_only_run_testbench_client_container $(DOCKER_CLIENT_IMG_FULL); \
		host_only_run_testbench_server_container $(DOCKER_SERVER_IMG_FULL); \
		"

	# Entrypoint scripts will bring up the various links.
	# Use "docker ps" to check status of containers, see if their health
	# probes are working as expected (i.e. "health"), etc.
endef

#------------------------------------------------------------------------------#
# Goals.
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
# Default goal.
.PHONY: all
all: docker
	@echo Done.

#------------------------------------------------------------------------------#
# Build all docker images.
.PHONY: docker
docker: Dockerfile.vpp_testbench Dockerfile.vpp_testbench.dockerignore \
	entrypoint_client.sh entrypoint_server.sh \
	vpp_testbench_helpers.sh
	# Client image.
	DOCKER_BUILDKIT=1 docker build \
			--file Dockerfile.vpp_testbench \
			--build-arg HEALTHCHECK_PORT=$(DOCKER_HEALTH_PROBE_PORT) \
			--tag $(DOCKER_CLIENT_IMG_FULL) \
			--target client_img \
			.
	# Server image.
	DOCKER_BUILDKIT=1 docker build \
			--file Dockerfile.vpp_testbench \
			--build-arg HEALTHCHECK_PORT=$(DOCKER_HEALTH_PROBE_PORT) \
			--tag $(DOCKER_SERVER_IMG_FULL) \
			--target server_img \
			.

#------------------------------------------------------------------------------#
# Execute end-to-end test via containers.
.PHONY: test
test:
	# Cleanup anything from previous runs.
	$(call cleanup_everything)

	# Launch our testbench.
	$(call launch_testbench)

	# Final cleanup.
	$(call cleanup_everything)

#------------------------------------------------------------------------------#
# For manually cleaning up a test that fails partway through its execution.
.PHONY: clean
clean:
	$(call cleanup_everything)

#------------------------------------------------------------------------------#
# For manually launching our testbench for interactive testing.
.PHONY: start
start:
	$(call launch_testbench)

#------------------------------------------------------------------------------#
# For manually stopping (and cleaning up) our testbench.
.PHONY: stop
stop:
	$(call cleanup_everything)

#------------------------------------------------------------------------------#
# Create an interactive shell session connected to the client container (for
# manual testing). Typically preceded by "make start", and concluded with
# "make stop" after exiting the shell.
.PHONY: shell_client
shell_client:
	bash -c "\
		. vpp_testbench_helpers.sh; \
		host_only_shell_client_container; \
		"

#------------------------------------------------------------------------------#
# Create an interactive shell session connected to the server container (for
# manual testing). Typically preceded by "make start", and concluded with
# "make stop" after exiting the shell.
.PHONY: shell_server
shell_server:
	bash -c "\
		. vpp_testbench_helpers.sh; \
		host_only_shell_server_container; \
		"