-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
355 lines (261 loc) · 11.2 KB
/
setup.py
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/usr/bin/env python3
import os
import subprocess
import sys
import platform
import time
def run_command(cmd, cwd=None, print_output=True, raise_on_error=True):
"""
Runs a shell command with transparency.
:param cmd: Command string or list of strings (e.g. ['brew', 'install', 'wget'])
:param cwd: Directory to run the command from
:param print_output: If True, prints stdout/stderr as they come
:param raise_on_error: If True, raises RuntimeError on non-zero exit code
:return: (exit_code, stdout, stderr)
This function:
- Prints the command being executed
- Times how long it takes to run
- Prints output (stdout/stderr) if print_output=True
- Raises an error if the command fails and raise_on_error=True
"""
if isinstance(cmd, str):
cmd_list = cmd.split()
else:
cmd_list = cmd
print(f"\n[RUN] Command: {' '.join(cmd_list)}")
if cwd:
print(f"[RUN] Working Directory: {cwd}")
else:
print("[RUN] Working Directory: (current directory)")
start_time = time.time()
process = subprocess.Popen(
cmd_list,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
out, err = process.communicate()
exit_code = process.returncode
end_time = time.time()
duration = end_time - start_time
print(f"[INFO] Command finished in {duration:.2f} seconds.")
if print_output:
if out.strip():
print("[STDOUT]\n" + out.strip())
if err.strip():
print("[STDERR]\n" + err.strip(), file=sys.stderr)
if raise_on_error and exit_code != 0:
raise RuntimeError(f"Command '{cmd_list}' failed with exit code {exit_code}")
return exit_code, out, err
def ensure_homebrew():
"""
Checks if Homebrew is installed; if not, installs it.
"""
try:
run_command("brew --version", raise_on_error=False, print_output=False)
print("[OK] Homebrew is already installed.")
except RuntimeError:
print("[INFO] Homebrew not found. Attempting to install...")
run_command('/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
print("[OK] Homebrew installed successfully.")
os.environ["PATH"] += os.pathsep + "/usr/local/bin"
os.environ["PATH"] += os.pathsep + "/opt/homebrew/bin"
def brew_install(package_name):
"""
Installs a package via Homebrew if not already installed.
"""
print(f"[INFO] Installing {package_name} via brew if not present...")
cmd = f"brew list {package_name}"
exit_code, _, _ = run_command(cmd, raise_on_error=False, print_output=False)
if exit_code == 0:
print(f"[OK] {package_name} is already installed.")
else:
run_command(f"brew install {package_name}")
print(f"[OK] {package_name} installed.")
def check_java_8():
"""
Checks if Java 8 is installed. If not, attempts to install Temurin 8 via brew cask.
"""
print("[INFO] Checking Java version(s) ...")
exit_code, out, err = run_command("java -version", raise_on_error=False)
if "1.8" in err or "1.8" in out:
print("[OK] Java 8 appears to be available.")
return True
print("[WARN] Java 8 not found, installing Temurin8 via Homebrew cask ...")
run_command("brew tap homebrew/cask-versions", raise_on_error=False)
run_command("brew install --cask temurin8")
exit_code, out, err = run_command("java -version", raise_on_error=False)
if "1.8" in err or "1.8" in out:
print("[OK] Java 8 is now installed via Temurin.")
return True
print("[ERROR] Could not verify Java 8 installation. Please check manually.")
return False
def install_maven_3_6_3(target_dir="/usr/local/apache-maven-3.6.3"):
"""
Installs Maven 3.6.3 if not found. We specifically need that version.
Installs to /usr/local/apache-maven-3.6.3 by default (adjust if desired).
"""
print("[INFO] Checking if Maven 3.6.3 is installed ...")
exit_code, out, err = run_command("mvn -version", raise_on_error=False)
if exit_code == 0 and "3.6.3" in out:
print("[OK] Maven 3.6.3 is already installed & in PATH.")
return
print("[INFO] Downloading Apache Maven 3.6.3 ...")
maven_url = "https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip"
maven_zip = "apache-maven-3.6.3-bin.zip"
if not os.path.exists(maven_zip):
run_command(f"wget {maven_url} -O {maven_zip}")
print("[INFO] Extracting Maven 3.6.3 ...")
if not os.path.exists("apache-maven-3.6.3"):
run_command(f"unzip -o {maven_zip}")
if os.path.exists(target_dir):
print(f"[WARN] {target_dir} already exists, skipping move.")
else:
run_command(f"sudo mv apache-maven-3.6.3 {target_dir}")
print("[INFO] Adding Maven 3.6.3 bin to your PATH. (Temporary for this session)")
new_path = os.path.join(target_dir, "bin")
os.environ["PATH"] = f"{new_path}:{os.environ['PATH']}"
exit_code, out, err = run_command("mvn -version", raise_on_error=False)
if exit_code == 0 and "3.6.3" in out:
print("[OK] Maven 3.6.3 installed and verified.")
else:
print("[ERROR] Could not verify Maven 3.6.3. Please check your environment manually.")
def clone_repo(repo_url, dest_dir):
"""
Generic function to clone a Git repo (used for JanusGraph).
If already cloned, it skips.
"""
if os.path.exists(dest_dir):
print(f"[OK] Directory '{dest_dir}' already exists, skipping clone.")
else:
run_command(f"git clone {repo_url} {dest_dir}")
def install_lazydocker():
"""
Installs lazydocker via Homebrew.
"""
print("[INFO] Installing lazydocker (terminal UI for Docker)...")
brew_install("lazydocker")
print("[OK] lazydocker installation complete. Remember you still need Docker Engine running.")
def install_docker_cli_tools():
"""
Installs docker-credential-helper, docker-compose, and Postman via brew.
"""
brew_install("docker-credential-helper")
brew_install("docker-compose")
print("[INFO] Installing Postman (via cask) ...")
run_command("brew install --cask postman", raise_on_error=False)
def build_keycloak():
"""
Downloads the keycloak-15.0.2.1.zip from S3 and unzips it into ~/.m2/repository/org/keycloak.
"""
print("[INFO] Building Keycloak 15.0.2.1 locally ...")
keycloak_dir = os.path.expanduser("~/.m2/repository/org/keycloak")
if not os.path.exists(keycloak_dir):
os.makedirs(keycloak_dir, exist_ok=True)
zip_name = "keycloak-15.0.2.1.zip"
keycloak_url = "https://atlan-public.s3.eu-west-1.amazonaws.com/artifact/keycloak-15.0.2.1.zip"
if not os.path.exists(zip_name):
run_command(f"wget {keycloak_url} -O {zip_name}")
run_command(f"unzip -o {zip_name} -d {keycloak_dir}")
print("[OK] Keycloak 15.0.2.1 setup is done.")
def build_janusgraph():
"""
Clones the atlan-janusgraph repo at branch=atlan-v0.6.0
and runs 'mvn clean install ...' to install in the local m2 repo.
NOTE: This version clones atlan-janusgraph as a sibling
to the 'atlas-metastore' folder in which this script resides.
"""
print("[INFO] Cloning & building atlan-janusgraph ...")
repo_url = "https://github.com/atlanhq/atlan-janusgraph.git"
repo_parent_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..")
)
repo_dir = os.path.join(repo_parent_dir, "atlan-janusgraph")
clone_repo(repo_url, repo_dir)
run_command("git fetch atlan-v0.6.0", cwd=repo_dir)
run_command("git checkout atlan-v0.6.0", cwd=repo_dir)
build_cmd = [
"mvn", "clean", "install",
"-Dgpg.skip=true",
"-Pjanusgraph-release",
"-DskipTests=true",
"-Dcheckstyle.skip=true",
"-Drat.skip=true",
"-Dit.skip=true",
"-Denforcer.skip=true",
"--batch-mode",
"--also-make"
]
print("[INFO] Building JanusGraph. This might take a while...")
run_command(build_cmd, cwd=repo_dir)
print("[OK] JanusGraph built successfully.")
def build_atlas():
"""
Attempts to build the atlas-metastore with skip tests and dist profile.
"""
print("[INFO] Building atlas-metastore ...")
repo_dir = os.path.dirname(os.path.abspath(__file__))
build_cmd = [
"mvn", "clean",
"-DskipTests", "package",
"-Pdist",
"-Drat.skip=true",
"-DskipEnunciate=true"
]
try:
run_command(build_cmd, cwd=repo_dir)
print("[OK] Built atlas-metastore with the dist profile.")
except Exception:
print("[WARN] Simple build command failed or partial. Attempting fallback build ...")
fallback_cmd = [
"mvn",
"-pl",
"!test-tools,!addons/hdfs-model,!addons/hive-bridge,!addons/hive-bridge-shim,"
"!addons/falcon-bridge-shim,!addons/falcon-bridge,!addons/sqoop-bridge,!addons/sqoop-bridge-shim,"
"!addons/hbase-bridge,!addons/hbase-bridge-shim,!addons/hbase-testing-util,"
"!addons/kafka-bridge,!addons/impala-hook-api,!addons/impala-bridge-shim,!addons/impala-bridge",
"-Dmaven.test.skip",
"-DskipTests",
"-Drat.skip=true",
"-DskipEnunciate=true",
"package",
"-Pdist"
]
run_command(fallback_cmd, cwd=repo_dir)
print("[OK] Fallback build command succeeded.")
def main():
if platform.system().lower() != "darwin":
print("[ERROR] This script is designed for macOS only.")
sys.exit(1)
print("=======================================================")
print(" Automating Apache Atlas (Metastore) Local Setup Steps ")
print(" (Installing lazydocker instead of Rancher Desktop) ")
print("=======================================================")
ensure_homebrew()
brew_install("wget")
brew_install("unzip")
check_java_8()
install_maven_3_6_3()
install_docker_cli_tools()
ans = input("\nDo you already have a Docker client? (yes/no): ").strip().lower()
if ans in ("yes", "y"):
print("[INFO] Skipping lazydocker installation.")
else:
install_lazydocker()
build_keycloak()
build_janusgraph()
build_atlas()
print("\n=======================================================")
print(" All core dependencies should now be installed.")
print(" Next Steps:")
print(" 1. Ensure you have Docker Engine running (Docker Desktop, Colima, etc.).")
print(" 2. Place the 'deploy' folder into your atlas-metastore root (if not already).")
print(" 3. Start your containers with docker-compose in ~/atlas (or your chosen dir).")
print(" 4. In IntelliJ, create the Run Configuration for 'org.apache.atlas.Atlas' (Java 8).")
print(" 5. Use the VM options from the instructions to point to deploy/conf, logs, etc.")
print(" 6. Run/Debug Atlas in IntelliJ, which should be on http://localhost:21000.")
print("=======================================================")
print("[INFO] Setup script completed. Some manual steps remain as described above.")
if __name__ == "__main__":
main()