-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMakefile
More file actions
221 lines (204 loc) · 8.72 KB
/
Makefile
File metadata and controls
221 lines (204 loc) · 8.72 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#
# Apache v2 license
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
INCLUDE ?= default_INCLUDE
DOCKER_COMPOSE_FILE = ./docker-compose.yml
DOCKER_COMPOSE_VALIDATION_FILE=./docker-compose-validation.override.yml
DOCKER_COMPOSE = docker compose
SECURE_MODE='false'
DRI_MOUNT_PATH := $(shell [ -d /dev/dri ] && [ -n "$$(ls -A /dev/dri 2>/dev/null)" ] && echo "/dev/dri" || echo "/dev/null")
export DRI_MOUNT_PATH
# Define the path to the .env file and scripts
ENV_FILE = ./.env
HELM_PACKAGE_SCRIPT = ./package_helm.sh
include $(ENV_FILE)
export $(shell sed 's/=.*//' $(ENV_FILE))
# Default values
KEY_LENGTH=3072
DAYS=365
SHA_ALGO="sha384"
# Build Docker containers
.PHONY: build
build:
@echo "Building Docker containers..."
$(DOCKER_COMPOSE) build;
.PHONY: build_copyleft_sources
build_copyleft_sources:
@echo "Building Docker containers including copyleft licensed sources..."
$(DOCKER_COMPOSE) build --build-arg COPYLEFT_SOURCES=true;
.PHONY: validate_host_ip
validate_host_ip:
@echo "Validating HOST_IP in .env..."
@host_ip=$$(grep -E "^HOST_IP=" $(ENV_FILE) | cut -d'=' -f2); \
if [ -z "$$host_ip" ]; then \
echo "HOST_IP is not set in $(ENV_FILE)."; \
exit 1; \
fi; \
if ! echo "$$host_ip" | grep -Eq '^([0-9]{1,3}\.){3}[0-9]{1,3}$$'; then \
echo "HOST_IP ($$host_ip) is not a valid IPv4 address format."; \
exit 1; \
fi; \
for octet in $$(echo "$$host_ip" | tr '.' ' '); do \
if [ "$$octet" -lt 0 ] || [ "$$octet" -gt 255 ]; then \
echo "HOST_IP ($$host_ip) has an invalid octet: $$octet"; \
exit 1; \
fi; \
done; \
echo "HOST_IP ($$host_ip) is valid."
# Check if multiple particular variables in .env are assigned with values
.PHONY: check_env_variables
check_env_variables:
@echo "Checking if username/password in .env are matching the rules set..."
@variables="INFLUXDB_USERNAME INFLUXDB_PASSWORD VISUALIZER_GRAFANA_USER VISUALIZER_GRAFANA_PASSWORD MTX_WEBRTCICESERVERS2_0_USERNAME MTX_WEBRTCICESERVERS2_0_PASSWORD S3_STORAGE_USERNAME S3_STORAGE_PASSWORD"; \
for variable_name in $$variables; do \
value=$$(grep -E "^$$variable_name=" $(ENV_FILE) | cut -d'=' -f2); \
if [ -z "$$value" ]; then \
echo "'$$variable_name' in $(ENV_FILE) is unassigned."; \
exit 1; \
fi; \
case "$$variable_name" in \
INFLUXDB_USERNAME) \
if [ "$$value" = "admin" ]; then \
echo "INFLUXDB_USERNAME must not be admin."; \
exit 1; \
fi; \
if ! echo "$$value" | grep -Eq "^[A-Za-z]{5,}$$"; then \
echo "INFLUXDB_USERNAME must contain only alphabets and be at least 5 characters minimum"; \
exit 1; \
fi \
;; \
INFLUXDB_PASSWORD) \
if ! echo "$$value" | grep -Eq "^[A-Za-z0-9]{10,}$$" || ! echo "$$value" | grep -q "[0-9]" || ! echo "$$value" | grep -q "[A-Za-z]"; then \
echo "The INFLUXDB_PASSWORD length must be a minimum of 10 alphanumeric characters with at least one digit"; \
exit 1; \
fi \
;; \
VISUALIZER_GRAFANA_USER) \
if ! echo "$$value" | grep -Eq "^[A-Za-z]{5,}$$"; then \
echo "VISUALIZER_GRAFANA_USER must contain only alphabets and be at least 5 characters minimum"; \
exit 1; \
fi \
;; \
VISUALIZER_GRAFANA_PASSWORD) \
if ! echo "$$value" | grep -Eq "^[A-Za-z0-9]{10,}$$" || ! echo "$$value" | grep -q "[0-9]" || ! echo "$$value" | grep -q "[A-Za-z]"; then \
echo "VISUALIZER_GRAFANA_PASSWORD length must be a minimum of 10 alphanumeric characters with at least one digit"; \
exit 1; \
fi \
;; \
MTX_WEBRTCICESERVERS2_0_USERNAME) \
if ! echo "$$value" | grep -Eq "^[A-Za-z]{5,}$$"; then \
echo "MTX_WEBRTCICESERVERS2_0_USERNAME must contain only alphabets and be at least 5 characters minimum"; \
exit 1; \
fi \
;; \
MTX_WEBRTCICESERVERS2_0_PASSWORD) \
if ! echo "$$value" | grep -Eq "^[A-Za-z0-9]{10,}$$" || ! echo "$$value" | grep -q "[0-9]" || ! echo "$$value" | grep -q "[A-Za-z]"; then \
echo "MTX_WEBRTCICESERVERS2_0_PASSWORD length must be a minimum of 10 alphanumeric characters with at least one digit"; \
exit 1; \
fi \
;; \
S3_STORAGE_USERNAME) \
if ! echo "$$value" | grep -Eq "^[A-Za-z]{5,}$$"; then \
echo "S3_STORAGE_USERNAME must contain only alphabets and be at least 5 characters minimum"; \
exit 1; \
fi \
;; \
S3_STORAGE_PASSWORD) \
if ! echo "$$value" | grep -Eq "^[A-Za-z0-9]{10,}$$" || ! echo "$$value" | grep -q "[0-9]" || ! echo "$$value" | grep -q "[A-Za-z]"; then \
echo "S3_STORAGE_PASSWORD length must be a minimum of 10 alphanumeric characters with at least one digit"; \
exit 1; \
fi \
;; \
esac; \
done
.PHONY: up
up: check_env_variables validate_host_ip down
@export TELEGRAF_INPUT_PLUGIN=$$(if [ $(INCLUDE) = 'validation' ]; then echo "mqtt_consumer:net:cpu:disk:docker:diskio:kernel:mem:processes:swap:system"; else echo "mqtt_consumer"; fi); \
echo "Starting Docker containers..."; \
echo "GPU device path set to: $(DRI_MOUNT_PATH) based on its existence"; \
if [ $(INCLUDE) = 'validation' ]; then \
$(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE) -f $(DOCKER_COMPOSE_VALIDATION_FILE) up -d; \
else \
$(DOCKER_COMPOSE) up -d; \
fi;
# Status of the deployed containers
.PHONY: status
status:
@echo "Status of the deployed containers..."; \
docker ps -a --filter "name=^ia-" --filter "name=mr_" --filter "name=model_" --filter "name=wind-turbine" --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"; \
echo "Parsing the logs of all containers to catch any error messages..."; \
sleep 20; \
containers=$$(docker ps -a --filter "name=^ia-" --filter "name=mr_" --filter "name=model_" --filter "name=wind-turbine" --format "{{.Names}}"); \
failure_cont_flag=0; \
for container in $$containers; do \
errors=$$(docker logs --tail 5 $$container 2>&1 | grep -i "error"); \
error_count=0; \
if [ -n "$$errors" ]; then \
error_count=$$(echo "$$errors" | wc -l); \
fi; \
if [ $$error_count -gt 0 ]; then \
echo ""; \
echo "=============Found errors in container $$container========"; \
echo "$$errors"; \
echo "******************************************************"; \
echo ""; \
failure_cont_flag=1; \
fi; \
done; \
if [ $$failure_cont_flag -eq 0 ]; then \
echo ""; \
echo "All containers are up and running without errors."; \
echo ""; \
else \
echo ""; \
echo "Some containers have errors. Please check the logs above."; \
echo ""; \
fi;
# Removes docker compose containers and volumes
.PHONY: down
down:
@echo "Stopping Docker containers...";
$(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_FILE) down -v --remove-orphans
# Push the docker images to docker registry, ensure to configure DOCKER_REGISTRY in .env
# and have logged into that. Applies mainly when one is dealing with internal docker registry.
# If you are using docker hub, ensure to have logged in with `docker login` command
# before running this command.
.PHONY: push_images
push_images: build
@echo "Pushing the images to docker registry"
docker compose -f $(DOCKER_COMPOSE_FILE) push
# Generate helm packages
.PHONY: gen_helm_charts
gen_helm_charts:
@echo "Generating Helm packages"
$(eval version := $(shell if [ -n "$(WEEKLY_BUILD_DATE)" ] && [ "$(WEEKLY_BUILD_DATE)" != '""' ]; then echo "2026.0.0-$(WEEKLY_BUILD_DATE)-weekly"; else echo "2026.0.0"; fi))
@cp -f configs/grafana/* helm/
@cp -f configs/influxdb/config/*.conf helm/
@cp -f configs/influxdb/init-influxdb.sh helm/
@cp -f configs/mqtt-broker/*.conf helm/
@cp -f configs/telegraf/config/*.conf helm/
@cp -f configs/telegraf/entrypoint.sh helm/telegraf_entrypoint.sh
@cp -f configs/time-series-analytics-microservice/config.json helm/
@cp -f configs/nginx/nginx-cert-gen.sh helm/nginx-cert-gen.sh
@cp -f configs/nginx/nginx.conf helm/nginx.conf
@cp -f configs/dlstreamer-pipeline-server/config.json helm/dlstreamer-pipeline-server.json
@sed -i 's/"auto_start": true,/"auto_start": false,/' helm/dlstreamer-pipeline-server.json
@sed -i "s/version: .*/version: ${version}/" "helm/Chart.yaml"
@sed -i "s/appVersion: .*/appVersion: \"${version}\"/" "helm/Chart.yaml"
@sed -i "s/weekly_build_date: .*/weekly_build_date: \"$(WEEKLY_BUILD_DATE)\"/" "helm/values.yaml"
@echo "Helm packages generated with version: ${version}"
# Help
.PHONY: help
help:
@echo "Makefile commands:"
@echo " make build - Build Docker containers"
@echo " make build_copyleft_sources - Build Docker containers including copyleft licensed sources"
@echo " make up - Start Docker containers"
@echo " make down - Stop Docker containers"
@echo " make restart - Restart Docker containers"
@echo " make clean - Remove all stopped containers and unused images"
@echo " make push_images - Push the images to docker registry"
@echo " make gen_helm_charts - Generate Helm packages for the selected sample app"
@echo " make help - Display this help message"