This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
112 lines (88 loc) · 3.96 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
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
.PHONY: clean build build-daemon create-app-image create-daemon-image test start-daemon deploy-daemon start-daemon-container sonar
-include .build_file
-include gradle.properties
TAG := latest
DOCKER_IMAGE := profiles-example
DAEMON_IMAGE := pdaemon
PLATFORM ?= linux/amd64 # linux/arm64
VERSION ?= 6.6.0-SNAPSHOT
ifndef DAEMON_TAG
curr_hash:=$(shell git rev-parse --short HEAD)
ifneq ($(curr_hash), $(GIT_HASH))
GIT_HASH=$(curr_hash)
SKILL_VERSION=-1
else
ifndef SKILL_VERSION
SKILL_VERSION=-1
endif
endif
SKILL_VERSION:=$(shell expr $(SKILL_VERSION) + 1)
dummy1:=$(shell echo "GIT_HASH=$(shell git rev-parse --short HEAD)" >".build_file")
dummy:=$(shell echo "SKILL_VERSION=$(SKILL_VERSION)">> ".build_file")
endif
DAEMON_TAG?=$(GIT_HASH)-$(SKILL_VERSION)
SCALECOUNT?=3
URL=$(shell cat ~/.cortex/config | jq .profiles[.currentProfile].url)
ifndef DOCKER_PREGISTRY_URL
DOCKER_PREGISTRY_URL=$(shell curl ${URL}/fabric/v4/info | jq -r .endpoints.registry.url | sed 's~http[s]*://~~g')
endif
SPARK_CONTAINER := ${DOCKER_PREGISTRY_URL}/${DOCKER_IMAGE}:${TAG}
DAEMON_CONTAINER := ${DOCKER_PREGISTRY_URL}/${DAEMON_IMAGE}:${DAEMON_TAG}
all: clean build create-app-image deploy-skill
create-app-image:
docker buildx build --platform $(PLATFORM) --build-arg base_img=c12e/profiles-sdk:$(PROFILES_SDK_VERSION) -t ${DOCKER_IMAGE}:${TAG} -f ./main-app/build/resources/main/Dockerfile ./main-app/build
create-daemon-image:
docker build --no-cache -t ${DAEMON_IMAGE}:${DAEMON_TAG} -f ./profiles-daemon/Dockerfile .
# Build the Application
build:
./gradlew -Pversion=$(VERSION) build
sonar:
./gradlew -Pversion=$(VERSION) sonar
build-daemon:
./gradlew :profile-daemon:build
# Test the Application
test:
./gradlew -Pversion=$(VERSION) test
clean:
./gradlew clean
# Start the Daemon locally
start-daemon:
./gradlew -Pversion=$(VERSION) :profile-daemon:bootRun
# Tag the latest create-app-image built container
tag-container: check-env
docker tag ${DOCKER_IMAGE}:${TAG} ${SPARK_CONTAINER}
# Tag the latest create-daemon-image built container
tag-daemon-container: check-env
docker tag ${DAEMON_IMAGE}:${DAEMON_TAG} ${DAEMON_CONTAINER}
# Push the container
push-container: check-env
docker push ${SPARK_CONTAINER}
push-daemon-container: check-env
docker push ${DAEMON_CONTAINER}
# Deploy the action and save the skill
skill-save: check-env
cortex actions deploy --actionName ${DOCKER_IMAGE} --actionType job --docker ${SPARK_CONTAINER} --project ${PROJECT_NAME} --cmd '["scuttle", "python", "submit_job.py"]' --podspec ./templates/podspec.yaml
cortex skills save -y templates/skill.yaml --project ${PROJECT_NAME}
daemon-skill-save: check-env
cortex actions deploy --actionName ${DAEMON_IMAGE} --actionType daemon --docker ${DAEMON_CONTAINER} --project ${PROJECT_NAME} --port '8080' --environmentVariables '"REDIS_HOST"="${REDIS_HOST}","REDIS_PORT"="${REDIS_PORT}","REDIS_USER"="${REDIS_USER}","REDIS_PASSWORD"="${REDIS_PASSWORD}"' --scaleCount ${SCALECOUNT}
cortex skills save -y profiles-daemon/skill.yaml --project ${PROJECT_NAME}
# Save types
types-save: check-env
cortex types save -y templates/types.yaml --project ${PROJECT_NAME}
# Start redis locally in a container
start-redis:
cd services/redis && docker-compose up -d && cd ../..
# Building and pushing the skill container, saving the skill and the types
deploy-skill: tag-container push-container types-save skill-save
# Building and pushing the daemon skill container, saving the skill and the action
deploy-daemon: build-daemon create-daemon-image tag-daemon-container push-daemon-container daemon-skill-save
# Invoke the skill with payload
invoke: check-env
cortex skills invoke --params-file templates/payload.json profiles-example params --project ${PROJECT_NAME}
check-env:
ifndef DOCKER_PREGISTRY_URL
$(error environment variable DOCKER_PREGISTRY_URL is not set. Set it like <docker-registry-url>/<namespace-org>)
endif
ifndef PROJECT_NAME
$(error environment variable PROJECT_NAME is not set. Set this to Cortex project name.)
endif