-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·144 lines (114 loc) · 5.46 KB
/
Makefile
File metadata and controls
executable file
·144 lines (114 loc) · 5.46 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
#
# Makefile for building Docker images for the OpenECPDS application.
# This file provides commands to streamline the process of creating
# and managing Docker images for deployment and testing.
#
# (c) Copyright ECMWF 2019-2024 - Laurent Gougeon (syi@ecmwf.int)
#
# Use bash by default
SHELL=/bin/bash
# Gets credentials for container registry (CR_URL, CR_UID & CR_PWD)
-include ../.settings/.cr-credentials
# Extract the tag number from the Maven file
VERSION=$(shell grep '<version>' ../pom.xml | head -n 1 | sed 's/.*>\(.*\)<.*/\1/')
BUILD=$(shell grep '<build.number>' ../pom.xml | head -n 1 | sed 's/.*>\(.*\)<.*/\1/')
TAG="$(VERSION)-$(BUILD)"
# Define color codes
GREEN := \033[32m
RED := \033[31m
RESET := \033[0m
# Source directories for the rpms and licences
RPM_DIR := ../target/rpm
LICENSES_DIR := ../target/generated-resources
# Detect container manager (Docker or Podman)
ifeq ($(shell command -v podman 2> /dev/null),)
DOCKER=docker
BUILD_OPTS=
else
DOCKER=podman
BUILD_OPTS=--format docker --cap-add all
endif
# Set the docker or podman version
DOCKER_VERSION := $(shell $(DOCKER) --version)
# Check HTTPS access (required to build images)
HTTPS_ACCESS := $(shell curl -s --max-time 2 -I https://google.com | sed 's/^[^ ]* *\([0-9]\).*/\1/; 1q')
# Output the help for each task
.PHONY: help all get-rpms get-licenses build-db build-ai build-backend build images bk-images rm-images clean .clean info
help: ## Show this help message
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-14s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Display help by default
.DEFAULT_GOAL := help
all: ## Get RPMs, licenses and build images
@$(MAKE) clean
@$(MAKE) get-rpms
@$(MAKE) get-licenses
@$(MAKE) build
.https-access: ## Check HTTPS access (required to build images)
@if [ "$(HTTPS_ACCESS)" != "2" -a "$(HTTPS_ACCESS)" != "3" ]; then \
printf "$(RED)** HTTPS connectivity is down **$(RESET)\n" && exit 1; \
fi
get-rpms: ## Get RPMs from the source RPM directories
@$(MAKE) .get-rpm app=mover rpm=mover arch=$(shell uname -m)
@$(MAKE) .get-rpm app=master rpm=master arch=$(shell uname -m)
@$(MAKE) .get-rpm app=monitor rpm=monitor arch=noarch
.get-rpm: # Create the target directory and get the specified RPM (args: app, rpm, arch)
mkdir -p ecpds/$(app)/rpms && cp -f $(RPM_DIR)/ecpds-$(rpm)/RPMS/$(arch)/ecpds-$(rpm)-$(TAG).$(arch).rpm ecpds/$(app)/rpms/.
get-licenses: ## Get the licenses for the java image
cp -fr $(LICENSES_DIR)/licenses* ecpds/java/.
cp -f ../AUTHORS ../LICENSE.txt ../NOTICE ../VERSION ecpds/java/.
build-db: .https-access ## Build database image for VS Code and Eclipse debugging/running
@$(MAKE) .build app=database tag=$(TAG)
build-ai: .https-access ## Build AI images for VS Code and Eclipse debugging/running
@$(MAKE) .build app=ai tag=$(TAG)
build: build-db build-ai ## Build database, AI, Java, and service images
@$(MAKE) .build app=java tag=graalvm
@$(MAKE) .build app=mover tag=$(TAG)
@$(MAKE) .build app=master tag=$(TAG)
@$(MAKE) .build app=monitor tag=$(TAG)
.build: # Build the image (args: app, tag)
$(DOCKER) build $(BUILD_OPTS) --build-arg SDKMAN_JDK=$(SDKMAN_JDK) --build-arg OLLAMA_FAST_MODEL_NAME=$(OLLAMA_FAST_MODEL_NAME) --build-arg OLLAMA_DEEP_MODEL_NAME=$(OLLAMA_DEEP_MODEL_NAME) --build-arg OLLAMA_EMBD_MODEL_NAME=$(OLLAMA_EMBD_MODEL_NAME) --build-arg TAG=$(tag) --label "app=$(app)" --label "tag=$(tag)" -t ecpds/$(app):$(tag) ecpds/$(app)
images: ## List images
@$(DOCKER) images --format "{{.ID}}@{{.Repository}}:{{.Tag}}" | grep 'ecpds/$(app)' | grep ':$(tag)' | awk -F'[@/]' '{print $$1 "@" $$(NF-1)":"$$NF}' | sed 's/:/-/g' | egrep -v '\-latest$$' | uniq
bk-images: ## Backup images (args: app, tag)
@for line in $$($(MAKE) -s images tag=$(tag) app=$(app)); do \
id=$$(echo $$line | cut -d'@' -f1); \
name=$$(echo $$line | cut -d'@' -f2); \
echo "Backing up image $$id with name $$name ..."; \
$(DOCKER) save $$id | gzip > $$name.tar.gz; \
done
rm-images: ## Remove images (args: app, tag)
@for line in $$($(MAKE) -s images tag=$(tag) app=$(app)); do \
id=$$(echo $$line | cut -d'@' -f1); \
echo "Removing image $$id ..."; \
$(DOCKER) rmi -f $$id; \
done
.checkcr: ## Check if the credentials are configured
@if [ "$(CR_URL)" == "" -o "$(CR_UID)" == "" -o "$(CR_PWD)" == "" ]; then \
printf "$(RED)** No CR credentials found (CR_URL, CR_UID & CR_PWD) **$(RESET)\n" && exit 1; \
fi
login: .checkcr ## Log in to the CR registry (according to '../.settings/.cr-credential')
@echo -n '$(CR_PWD)' | $(DOCKER) login -u '$(CR_UID)' --password-stdin $(CR_URL);
push: .checkcr ## Push images to CR
@$(MAKE) .push app=database tag=$(TAG)
@$(MAKE) .push app=ai tag=$(TAG)
@$(MAKE) .push app=mover tag=$(TAG)
@$(MAKE) .push app=master tag=$(TAG)
@$(MAKE) .push app=monitor tag=$(TAG)
.push: ## Push image and tag as latest (args: from, to, app, tag)
$(DOCKER) tag ecpds/$(app):$(tag) $(CR_URL)/$(app):$(tag)
$(DOCKER) tag ecpds/$(app):$(tag) $(CR_URL)/$(app)
$(DOCKER) push $(CR_URL)/$(app):$(tag)
$(DOCKER) push $(CR_URL)/$(app)
clean: ## Remove all RPMs and licenses
@$(MAKE) .clean app=mover
@$(MAKE) .clean app=master
@$(MAKE) .clean app=monitor
cd ecpds/java && rm -fr AUTHORS LICENSE.txt NOTICE VERSION licenses*
.clean: # Remove RPMs for the specified app (arg: app)
rm -f ecpds/$(app)/rpms/ecpds-*-*.*.rpm
info: ## Output the configuration
@echo "Software tag number: $(TAG)"
@echo "Docker command: $(DOCKER) ($(DOCKER_VERSION))"
@if [ -n "$(BUILD_OPTS)" ]; then \
echo "Docker options: $(BUILD_OPTS)"; \
fi