forked from rhdhorchestrator/serverless-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
177 lines (154 loc) · 5.95 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
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
# Requirements
# docker or podman installed and running
# git installed
# .git_token file exists with current Token (or injected as the GIT_TOKEN env var)
# Linux OS
WORKFLOWS = \
greeting \
extendable-workflow \
escalation \
move2kube \
mta-v7.x \
create-ocp-project \
request-vm-cnv \
mtv-migration \
modify-vm-resources \
rpj \
$(NULL)
# Dynamic rule patten that uses one of the workflows and sets the workflow id
# for the rest of the execution. Use with other targets, e.g, make move2kube gen-manifests
.PHONY: $(WORKFLOWS)
$(WORKFLOWS):
$(eval WORKFLOW_ID="$@")
@echo Specify one of the targets: build-image, push-image, gen-manifests
# Empty value is used to work with the default builder image from the dockerfile.
BUILDER_IMAGE = ""
ifndef APPLICATION_ID
APPLICATION_ID = UNDEFINED
endif
ifndef LOCAL_TEST
LOCAL_TEST = false
endif
ifeq ($(APPLICATION_ID), UNDEFINED)
IS_WORKFLOW = true
IS_APPLICATION = false
else
IS_WORKFLOW = false
IS_APPLICATION = true
endif
CONTAINER_ENGINE ?= $(shell which podman >/dev/null 2>&1 && echo podman || echo docker)
ifneq (,$(wildcard $(CURDIR)/.docker))
DOCKER_CONF := $(CURDIR)/.docker
else
DOCKER_CONF := $(HOME)/.docker
endif
WORKDIR := $(shell mktemp -d)
ifeq ($(shell uname),Darwin)
# Use a fixed folder to simplify limactl configuration (must be mounted with Write permissions)
WORKDIR := /tmp/serverless-workflows
endif
ifeq ($(LOCAL_TEST), true)
WORKDIR := ~/workdir
endif
SCRIPTS_DIR := scripts
GIT_USER_NAME ?= $(shell git config --get user.name)
GIT_USER_EMAIL ?= $(shell git config --get user.email)
GIT_REMOTE_URL := $(shell git config --get remote.origin.url)
GIT_REMOTE_URL := $(shell echo "$(GIT_REMOTE_URL)" | sed 's/\.git//')
GIT_REMOTE_URL := $(shell echo "$(GIT_REMOTE_URL)" | sed 's/git@/https:\/\//')
GIT_REMOTE_URL := $(shell echo "$(GIT_REMOTE_URL)" | sed 's/com:/com\//')
PR_OR_COMMIT_URL ?= "$(GIT_REMOTE_URL)/commits/$(shell git rev-parse --short=8 HEAD)"
LINUX_IMAGE ?= quay.io/orchestrator/ubi9-pipeline:latest
JDK_IMAGE ?= registry.access.redhat.com/ubi9/openjdk-17:1.17
BUILD_APPLICATION_SCRIPT ?= $(SCRIPTS_DIR)/build_application.sh
MVN_OPTS ?= -B
IMAGE_NAME := ""
REGISTRY ?= quay.io
REGISTRY_REPO ?= $(shell id -un)
REGISTRY_USERNAME ?= ""
REGISTRY_PASSWORD ?= ""
IMAGE_PREFIX ?= serverless-workflow
IMAGE_TAG ?= $(shell git rev-parse --short=8 HEAD)
ifeq ($(IS_WORKFLOW),true)
DOCKERFILE ?= pipeline/workflow-builder.Dockerfile
else
DOCKERFILE ?= src/main/docker/Dockerfile.jvm
endif
ifeq ($(IS_WORKFLOW),true)
IMAGE_NAME = $(REGISTRY)/$(REGISTRY_REPO)/$(IMAGE_PREFIX)-$(WORKFLOW_ID)
else
IMAGE_NAME = $(REGISTRY)/$(REGISTRY_REPO)/$(IMAGE_PREFIX)-$(APPLICATION_ID)
endif
ENABLE_PERSISTENCE ?= true
.PHONY: all
all: build-image push-image gen-manifests
for-local-tests: build-image push-image gen-manifests
# Target: prepare-workdir
# Description: copies the local repo content in a temporary WORKDIR for file manipulation.
# Usage: make prepare-workdir
prepare-workdir:
@echo "Preparing workdir $(WORKDIR)"
@rm -rf $(WORKDIR)
@mkdir -p $(WORKDIR)
@cp -R . $(WORKDIR)
@cp -R $(WORKDIR)/workflows/shared $(WORKDIR)/workflows/$(WORKFLOW_ID)/shared
@find $(WORKDIR) -type d -name target -prune -exec rm -rf {} \;
# Target: build-image
# Description: Builds the workflow containerized image from the given WORKDIR.
# Depends on: prepare-workdir target.
# Usage: make build-image
ifeq ($(IS_WORKFLOW),true)
build-image: BUILD_ARGS=--build-arg-file=workflows/$(WORKFLOW_ID)/argfile.conf --build-arg=BUILDER_IMAGE=$(BUILDER_IMAGE) --build-arg WF_RESOURCES=workflows/$(WORKFLOW_ID)
endif
build-image: EXTRA_ARGS=--ulimit nofile=4096:4096
build-image: prepare-workdir
@echo "Building $(IMAGE_NAME)"
ifeq ($(IS_APPLICATION),true)
# First build the application
$(BUILD_APPLICATION_SCRIPT) $(CONTAINER_ENGINE) $(WORKDIR) $(WORKFLOW_ID) $(APPLICATION_ID) $(JDK_IMAGE) $(MVN_OPTS)
# Then build the containerized image from the application source
@cd $(WORKDIR)/workflows/$(WORKFLOW_ID)/$(APPLICATION_ID) && $(CONTAINER_ENGINE) build -f $(DOCKERFILE) \
$(BUILD_ARGS) $(EXTRA_ARGS) \
--tag ${IMAGE_NAME}:${IMAGE_TAG} --tag ${IMAGE_NAME}:latest .
else
@cd $(WORKDIR)/ && $(CONTAINER_ENGINE) build -f $(DOCKERFILE) \
$(BUILD_ARGS) $(EXTRA_ARGS) \
--tag ${IMAGE_NAME}:${IMAGE_TAG} --tag ${IMAGE_NAME}:latest .
endif
# Target: push-image
# Description: Pushes the workflow containerized image to the configured REGISTRY.
# Usage: make push-image
push-image:
@echo "Pushing $(IMAGE_NAME)"
ifneq ($(strip $(REGISTRY_USERNAME)),"")
ifneq ($(strip $(REGISTRY_PASSWORD)),"")
@echo "${REGISTRY_PASSWORD}" | $(CONTAINER_ENGINE) login -u ${REGISTRY_USERNAME} --password-stdin ${REGISTRY}
endif
endif
@$(CONTAINER_ENGINE) push ${IMAGE_NAME}:latest
@$(CONTAINER_ENGINE) push ${IMAGE_NAME}:${IMAGE_TAG}
# Target: save-oci
# Description: Extracts the containerized image to a local file in the current folder.
# Depends on: build-image target.
# Usage: make save-oci
ifeq ($(IS_WORKFLOW),true)
save-oci: OCI_NAME=$(IMAGE_PREFIX)-$(WORKFLOW_ID)-$(IMAGE_TAG).tar
else
save-oci: OCI_NAME=$(IMAGE_PREFIX)-$(APPLICATION_ID)-$(IMAGE_TAG).tar
endif
save-oci: build-image
@echo "Saving OCI archive $(OCI_NAME)"
@$(CONTAINER_ENGINE) save ${IMAGE_NAME}:${IMAGE_TAG} -o ${OCI_NAME}
# Target: gen-manifests
# Description: Generates the k8s manifests for the WORKFLOW_ID workflow under the configured WORKDIR.
# Depends on: prepare-workdir target.
# Usage: make gen-manifests
gen-manifests: prepare-workdir
cd $(WORKDIR)
$(CONTAINER_ENGINE) run --rm -v $(WORKDIR):/workdir:Z -w /workdir \
$(LINUX_IMAGE) /bin/bash -c "ENABLE_PERSISTENCE=$(ENABLE_PERSISTENCE) WORKFLOW_IMAGE_TAG=$(IMAGE_TAG) ${SCRIPTS_DIR}/gen_manifests.sh workflows/$(WORKFLOW_ID) $(WORKFLOW_ID)"
@echo "Manifests are available in workdir $(WORKDIR)/workflows/$(WORKFLOW_ID)/manifests"
remove-trailing-whitespaces:
@echo "Removing all trailing whitespaces from application.properties files"
@find . -type f -name "application.properties" -exec sed -i 's/[[:space:]]\+$$//' {} +
@echo "Trailing whitespaces were removed."