-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (65 loc) · 2.64 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
# Makefile for ASWA project
# Variables
CLUSTER_INFO ?=
DOCKER_COMPOSE_CMD ?= docker compose run --rm
PROM_AGGREGATION_GATEWAY_URL ?=
SLACK_CHANNEL_ID ?=
SKIP_BUILD ?= 0
# Set to 1 to skip building the images
# Targets
.PHONY: all build check_env clean conditional-build container container-run go-run init run run-app test
# Default target: build the images, run tests and run the app in a container
all: container test container-run
# Build binary for aswa
build:
@echo "Building aswa binary..."
go build -o aswa ./cmd
# Check if the required environment variables are set
check_env:
@MISSING_VARS=""; \
UNSET_COUNT=0; \
if [ -z "$(SLACK_CHANNEL_ID)" ]; then MISSING_VARS="SLACK_CHANNEL_ID"; UNSET_COUNT=$$((UNSET_COUNT + 1)); fi; \
if [ -z "$(CLUSTER_INFO)" ]; then MISSING_VARS="$$MISSING_VARS$${MISSING_VARS:+, }CLUSTER_INFO"; UNSET_COUNT=$$((UNSET_COUNT + 1)); fi; \
if [ -z "$(PROM_AGGREGATION_GATEWAY_URL)" ]; then MISSING_VARS="$$MISSING_VARS$${MISSING_VARS:+, }PROM_AGGREGATION_GATEWAY_URL"; UNSET_COUNT=$$((UNSET_COUNT + 1)); fi; \
if [ $$UNSET_COUNT -gt 0 ]; then \
echo "$$MISSING_VARS $$([ $$UNSET_COUNT -gt 1 ] && echo 'are' || echo 'is') not set. Please set $$([ $$UNSET_COUNT -gt 1 ] && echo 'them' || echo 'it') and try again."; \
exit 1; \
fi
# Clean up the project
clean:
@echo "Cleaning up..."
rm -f aswa
docker compose down --rmi all --volumes --remove-orphans
@echo "Remember to manually unset YAML_PATH if it was exported in your shell."
# Conditionally run the build target based on the value of SKIP_BUILD
conditional-build:
@if [ "$(SKIP_BUILD)" = "0" ]; then $(MAKE) container; fi
# Build images for the aswa app and the test container
container:
@echo "Building images..."
docker compose build
# Run the aswa app in a Docker container
container-run: conditional-build
@echo "Running aswa in a Docker container..."
$(DOCKER_COMPOSE_CMD) aswa
# Run the aswa app with 'go run'
go-run:
@echo "Running aswa with 'go run'..."
go run ./cmd
# Initialize the project by checking if the environment variables are set
init: check_env
# Run aswa using the built binary
run: build
@echo "Running aswa..."
./aswa
# Run the synthetic test on the app with the given name in a container
run-app: conditional-build
@if [ -z "$(filter-out $@,$(MAKECMDGOALS))" ]; then echo "Error: Please provide an app name. Usage: make run-app your_app_name_here"; exit 1; fi
$(DOCKER_COMPOSE_CMD) aswa /aswa $(filter-out $@,$(MAKECMDGOALS))
# Ignore any targets that are not files
%:
@:
# Run tests using the aswa_test container and ensure images are built before running
test: conditional-build
@echo "Running tests..."
$(DOCKER_COMPOSE_CMD) test