blob: 4433edbe4d7f51b98c04aa1fc1e7e823c07a7ce5 [file] [log] [blame]
Matthew Giassa4a0dd382021-11-19 17:06:11 +00001################################################################################
2# @brief: Makefile for building the VPP testbench example.
3# @author: Matthew Giassa.
4# @copyright: (C) Cisco 2021.
5################################################################################
6#------------------------------------------------------------------------------#
7# Constants and settings.
8#------------------------------------------------------------------------------#
9SHELL=/bin/bash
10.DEFAULT_GOAL: all
11
12# Image names.
13# TODO: semver2 format if we want to publish these to a registry.
14DOCKER_CLIENT_IMG := vpp-testbench-client
15DOCKER_CLIENT_REL := local
16DOCKER_CLIENT_IMG_FULL := $(DOCKER_CLIENT_IMG):$(DOCKER_CLIENT_REL)
17DOCKER_SERVER_IMG := vpp-testbench-server
18DOCKER_SERVER_REL := local
19DOCKER_SERVER_IMG_FULL := $(DOCKER_SERVER_IMG):$(DOCKER_SERVER_REL)
20# Docker build-time settings (and run-time settings as well).
21DOCKER_HEALTH_PROBE_PORT := $(shell bash -c ". vpp_testbench_helpers.sh; host_only_get_docker_health_probe_port")
22
23#------------------------------------------------------------------------------#
24# Functions.
25#------------------------------------------------------------------------------#
26#------------------------------------------------------------------------------#
27# Cleanup running containers, Docker networks, etc.; from previous runs.
28define cleanup_everything
29 # Terminate the containers.
30 bash -c "\
31 . vpp_testbench_helpers.sh; \
32 host_only_kill_testbench_client_container $(DOCKER_CLIENT_IMG_FULL); \
33 host_only_kill_testbench_server_container $(DOCKER_SERVER_IMG_FULL); \
34 "
35
36 # Cleanup Docker bridge network.
37 bash -c "\
38 . vpp_testbench_helpers.sh; \
39 host_only_destroy_docker_networks; \
40 "
41endef
42
43#------------------------------------------------------------------------------#
44# Launch our containers and connect them to a private Docker network for
45# testing.
46define launch_testbench
47 # Create Docker bridge network.
48 bash -c "\
49 . vpp_testbench_helpers.sh; \
50 host_only_create_docker_networks; \
51 "
52
53 # Launch the containers.
54 bash -c "\
55 . vpp_testbench_helpers.sh; \
56 host_only_run_testbench_client_container $(DOCKER_CLIENT_IMG_FULL); \
57 host_only_run_testbench_server_container $(DOCKER_SERVER_IMG_FULL); \
58 "
59
60 # Entrypoint scripts will bring up the various links.
61 # Use "docker ps" to check status of containers, see if their health
62 # probes are working as expected (i.e. "health"), etc.
63endef
64
65#------------------------------------------------------------------------------#
66# Goals.
67#------------------------------------------------------------------------------#
68#------------------------------------------------------------------------------#
69# Default goal.
70.PHONY: all
71all: docker
72 @echo Done.
73
74#------------------------------------------------------------------------------#
75# Build all docker images.
76.PHONY: docker
77docker: Dockerfile.vpp_testbench Dockerfile.vpp_testbench.dockerignore \
78 entrypoint_client.sh entrypoint_server.sh \
79 vpp_testbench_helpers.sh
80 # Client image.
81 DOCKER_BUILDKIT=1 docker build \
82 --file Dockerfile.vpp_testbench \
83 --build-arg HEALTHCHECK_PORT=$(DOCKER_HEALTH_PROBE_PORT) \
84 --tag $(DOCKER_CLIENT_IMG_FULL) \
85 --target client_img \
86 .
87 # Server image.
88 DOCKER_BUILDKIT=1 docker build \
89 --file Dockerfile.vpp_testbench \
90 --build-arg HEALTHCHECK_PORT=$(DOCKER_HEALTH_PROBE_PORT) \
91 --tag $(DOCKER_SERVER_IMG_FULL) \
92 --target server_img \
93 .
94
95#------------------------------------------------------------------------------#
96# Execute end-to-end test via containers.
97.PHONY: test
98test:
99 # Cleanup anything from previous runs.
100 $(call cleanup_everything)
101
102 # Launch our testbench.
103 $(call launch_testbench)
104
105 # Final cleanup.
106 $(call cleanup_everything)
107
108#------------------------------------------------------------------------------#
109# For manually cleaning up a test that fails partway through its execution.
110.PHONY: clean
111clean:
112 $(call cleanup_everything)
113
114#------------------------------------------------------------------------------#
115# For manually launching our testbench for interactive testing.
116.PHONY: start
117start:
118 $(call launch_testbench)
119
120#------------------------------------------------------------------------------#
121# For manually stopping (and cleaning up) our testbench.
122.PHONY: stop
123stop:
124 $(call cleanup_everything)
125
126#------------------------------------------------------------------------------#
127# Create an interactive shell session connected to the client container (for
128# manual testing). Typically preceded by "make start", and concluded with
129# "make stop" after exiting the shell.
130.PHONY: shell_client
131shell_client:
132 bash -c "\
133 . vpp_testbench_helpers.sh; \
134 host_only_shell_client_container; \
135 "
136
137#------------------------------------------------------------------------------#
138# Create an interactive shell session connected to the server container (for
139# manual testing). Typically preceded by "make start", and concluded with
140# "make stop" after exiting the shell.
141.PHONY: shell_server
142shell_server:
143 bash -c "\
144 . vpp_testbench_helpers.sh; \
145 host_only_shell_server_container; \
146 "
147