-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.clj
More file actions
159 lines (144 loc) · 5.68 KB
/
build.clj
File metadata and controls
159 lines (144 loc) · 5.68 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
;; ============================================================================
;; PurpleOPS BAS - Build Script
;;
;; LICENSE: MIT License
;; Copyright (c) 2024-2026 Mauro Risonho de Paula Assumpção
;; Licensed under the MIT License. See LICENSE file in the project root.
;; ============================================================================
;; Description: Script de build usando clojure.tools.build
;; Author: Mauro Risonho de Paula Assumpção
;; Created: 2024-01-01
;; Modified: 2026-01-06
;; Detailed Description:
;; - Automatiza processo de build do projeto
;; - Generates uberjars para deployment
;; - Gerencia dependências e compilação
;; LICENSE: MIT
;; ============================================================================
(ns build
(:require [clojure.tools.build.api :as b]
[clojure.java.shell :as shell]))
(def lib 'purpleops-bas/backend)
(def version "1.0.0")
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def uber-file "target/purpleops-backend.jar")
(def orch-uber-file "target/purpleops-orchestrator.jar")
(defn clean [_]
(b/delete {:path "target"}))
(defn uber [_]
(clean nil)
(b/copy-dir {:src-dirs ["backend/src" "orchestrator/src" "connectors/src"]
:target-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis basis
:main 'purpleops-bas.backend.core
:manifest {"Main-Class" "clojure.main"
"Clojure-Main" "purpleops-bas.backend.core"}}))
(defn uber-orchestrator [_]
(clean nil)
(b/copy-dir {:src-dirs ["orchestrator/src" "connectors/src" "backend/src"]
:target-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file orch-uber-file
:basis basis
:main 'purpleops-bas.orchestrator.core
:manifest {"Main-Class" "clojure.main"
"Clojure-Main" "purpleops-bas.orchestrator.core"}}))
;; ==============================================================================
;; ML Module Build Tasks
;; ==============================================================================
(defn test
"Run unit tests"
[_]
(println "Running tests...")
(let [{:keys [exit]} (shell/sh "clojure" "-X:test" :inherit true)]
(if (zero? exit)
(println "✓ All tests passed")
(do (println "✗ Tests failed")
(System/exit 1)))))
(defn test-ml
"Run ML-specific tests"
[_]
(println "Running ML tests...")
(let [{:keys [exit]} (shell/sh "clojure" "-X:test/ml" :inherit true)]
(if (zero? exit)
(println "✓ ML tests passed")
(do (println "✗ ML tests failed")
(System/exit 1)))))
(defn lint
"Run code linter"
[_]
(println "Running code linter...")
(try
(shell/sh "clj-kondo" "--lint" "backend/src" :inherit true)
(println "✓ Lint check complete")
(catch Exception e
(println "Note: clj-kondo not installed"))))
(defn docker-build
"Build Docker image for backend"
[_]
(println "Building Docker image for backend...")
(let [{:keys [exit]} (shell/sh "docker"
"build"
"-f" "infra/Dockerfile.backend"
"-t" "purpleops/backend:latest"
"."
:inherit true)]
(if (zero? exit)
(println "✓ Docker image built successfully")
(println "✗ Docker build failed"))))
(defn docker-compose-up
"Start services with docker-compose"
[_]
(println "Starting services with docker-compose...")
(shell/sh "docker-compose" "up" "-d" :inherit true))
(defn docker-compose-down
"Stop services with docker-compose"
[_]
(println "Stopping services...")
(shell/sh "docker-compose" "down" :inherit true))
(defn deploy
"Full deployment: test, build, and create images"
[_]
(println "=================================")
(println "PurpleOPS BAS - Full Deployment")
(println "=================================")
(test nil)
(test-ml nil)
(uber nil)
(docker-build nil)
(println "✓ Deployment artifacts ready")
(println " - Backend JAR: target/purpleops-backend.jar")
(println " - Docker image: purpleops/backend:latest"))
(defn performance-test
"Run performance benchmarks"
[_]
(println "Running performance benchmarks...")
(shell/sh "clojure" "-X:test/ml" :inherit true))
(defn info
"Display build information"
[_]
(println "======================================")
(println "PurpleOPS BAS - Build Information")
(println "======================================")
(println (format "Project: %s" lib))
(println (format "Version: %s" version))
(println (format "Build class dir: %s" class-dir))
(println (format "Backend JAR: %s" uber-file))
(println (format "Orchestrator JAR: %s" orch-uber-file))
(println "======================================")
(println "Available tasks:")
(println " clojure -T:build clean - Clean build artifacts")
(println " clojure -T:build uber - Build backend JAR")
(println " clojure -T:build uber-orchestrator - Build orchestrator JAR")
(println " clojure -T:build test - Run unit tests")
(println " clojure -T:build test-ml - Run ML tests")
(println " clojure -T:build lint - Lint code")
(println " clojure -T:build docker-build - Build Docker image")
(println " clojure -T:build docker-compose-up - Start services")
(println " clojure -T:build docker-compose-down - Stop services")
(println " clojure -T:build deploy - Full deployment")
(println " clojure -T:build performance-test - Run benchmarks")
(println "======================================"))