-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·1035 lines (909 loc) · 30.4 KB
/
setup.sh
File metadata and controls
executable file
·1035 lines (909 loc) · 30.4 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
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# ==============================================
# NDP-EP API Setup Script
# ==============================================
# This script installs the NDP-EP API on a fresh Ubuntu system
# by fetching configuration from the NDP Federation API.
#
# It will:
# 1. Install Docker (if not present)
# 2. Fetch configuration from Federation API
# 3. Generate docker-compose.yml and .env files
# 4. Start the services
#
# Usage:
# curl -fsSL <script_url> | bash -s -- --config_id <ep_id>
# ./setup.sh --config_id <ep_id>
# ./setup.sh --config_id <ep_id> --federation_url <url>
#
# Example:
# ./setup.sh --config_id 695383e17c1d8951b04621c6
# ==============================================
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Default values
DEFAULT_FEDERATION_URL="http://localhost:8000"
EP_API_IMAGE="rbardaji/ndp-ep-api:latest"
INSTALL_DIR="ndp-ep"
DEFAULT_CATALOG_BACKEND="ckan"
CKAN_DOCKER_REPO="https://github.com/sci-ndp/pop-ckan-docker.git"
# Print banner
print_banner() {
echo -e "${CYAN}"
cat <<'EOF'
███╗ ██╗██████╗ ██████╗ ███████╗██████╗
████╗ ██║██╔══██╗██╔══██╗ ██╔════╝██╔══██╗
██╔██╗ ██║██║ ██║██████╔╝█████╗█████╗ ██████╔╝
██║╚██╗██║██║ ██║██╔═══╝ ╚════╝██╔══╝ ██╔═══╝
██║ ╚████║██████╔╝██║ ███████╗██║
╚═╝ ╚═══╝╚═════╝ ╚═╝ ╚══════╝╚═╝
NDP Endpoint API - Setup Script
EOF
echo -e "${NC}"
}
# Print functions
print_step() {
echo -e "\n${GREEN}[STEP]${NC} $1"
}
print_info() {
echo -e "${YELLOW}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
# Show usage
show_usage() {
echo "Usage: $0 --config_id <ep_id> [OPTIONS]"
echo ""
echo "Required:"
echo " --config_id <id> EP configuration ID from Federation API"
echo ""
echo "Options:"
echo " --federation_url <url> Federation API URL (default: $DEFAULT_FEDERATION_URL)"
echo " --install_dir <dir> Installation directory (default: $INSTALL_DIR)"
echo " --catalog_backend <type> Local catalog backend: ckan or mongodb (default: $DEFAULT_CATALOG_BACKEND)"
echo " --no-start Don't start services after configuration"
echo " --help Show this help message"
echo ""
echo "Example:"
echo " $0 --config_id 695383e17c1d8951b04621c6"
echo " $0 --config_id abc123 --federation_url https://federation.ndp.utah.edu"
echo " $0 --config_id abc123 --catalog_backend mongodb"
}
# ----------- PARSE ARGS ----------- #
config_id=""
federation_url="$DEFAULT_FEDERATION_URL"
install_dir="$INSTALL_DIR"
catalog_backend="$DEFAULT_CATALOG_BACKEND"
no_start=false
while [[ "$#" -gt 0 ]]; do
case $1 in
--config_id) config_id="$2"; shift ;;
--federation_url) federation_url="$2"; shift ;;
--install_dir) install_dir="$2"; shift ;;
--catalog_backend) catalog_backend="$2"; shift ;;
--no-start) no_start=true ;;
--help) show_usage; exit 0 ;;
*) echo -e "${RED}Unknown parameter: $1${NC}"; show_usage; exit 1 ;;
esac
shift
done
# Validate required parameters
if [[ -z "$config_id" ]]; then
print_error "--config_id is required"
echo ""
show_usage
exit 1
fi
# Validate catalog_backend
if [[ "$catalog_backend" != "ckan" && "$catalog_backend" != "mongodb" ]]; then
print_error "--catalog_backend must be 'ckan' or 'mongodb'"
echo ""
show_usage
exit 1
fi
# ----------- MAIN SCRIPT ----------- #
print_banner
# ----------- CHECK/INSTALL DEPENDENCIES ----------- #
print_step "Checking dependencies..."
# Check for curl
if ! command -v curl &> /dev/null; then
print_info "Installing curl..."
sudo apt-get update && sudo apt-get install -y curl
fi
# Check for jq
if ! command -v jq &> /dev/null; then
print_info "Installing jq..."
sudo apt-get update && sudo apt-get install -y jq
fi
# Check for git (needed for CKAN backend)
if [[ "$catalog_backend" == "ckan" ]]; then
if ! command -v git &> /dev/null; then
print_info "Installing git..."
sudo apt-get update && sudo apt-get install -y git
fi
fi
# Check for Docker
if ! command -v docker &> /dev/null; then
print_info "Docker not found. Installing..."
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
print_success "Docker installed"
print_info "You may need to log out and back in for docker group permissions"
else
print_info "Docker is installed: $(docker --version)"
fi
# Check Docker Compose
if docker compose version &> /dev/null; then
print_info "Docker Compose is available: $(docker compose version)"
DOCKER_COMPOSE_CMD="docker compose"
elif command -v docker-compose &> /dev/null; then
print_info "Docker Compose (standalone) is available"
DOCKER_COMPOSE_CMD="docker-compose"
else
print_error "Docker Compose is not available. Please install it."
exit 1
fi
# ----------- FETCH CONFIGURATION ----------- #
print_step "Fetching configuration from Federation API..."
print_info "Config ID: $config_id"
print_info "Federation URL: $federation_url"
config_json=$(curl -s "${federation_url}/ep/${config_id}")
if [[ -z "$config_json" || "$config_json" == "null" ]]; then
print_error "Failed to fetch configuration from Federation API"
print_error "URL: ${federation_url}/ep/${config_id}"
exit 1
fi
# Check for error response
if echo "$config_json" | jq -e '.error' > /dev/null 2>&1; then
error_msg=$(echo "$config_json" | jq -r '.message // "Unknown error"')
print_error "Federation API returned an error: $error_msg"
exit 1
fi
print_success "Configuration fetched successfully"
# ----------- EXTRACT VALUES ----------- #
print_step "Extracting configuration values..."
# Extract values from JSON (with defaults)
organization=$(echo "$config_json" | jq -r '.organization // "My-Organization"')
ep_name=$(echo "$config_json" | jq -r '.ep_name // "My-EP"')
pre_ckan_url=$(echo "$config_json" | jq -r '.pre_ckan_url // ""')
pre_ckan_key=$(echo "$config_json" | jq -r '.pre_ckan_key // ""')
enable_staging=$(echo "$config_json" | jq -r '.enable_staging // false')
streaming=$(echo "$config_json" | jq -r '.streaming // false')
jhub=$(echo "$config_json" | jq -r '.jhub // false')
group_name=$(echo "$config_json" | jq -r '.group_name // ""')
jupyter_url=$(echo "$config_json" | jq -r '.jupyter_url // ""')
# Display fetched values
echo ""
echo -e "${BLUE}Configuration values:${NC}"
echo " Organization: $organization"
echo " EP Name: $ep_name"
echo " Pre-CKAN URL: ${pre_ckan_url:-"(not set)"}"
echo " Enable Staging: $enable_staging"
echo " Streaming: $streaming"
echo " JupyterHub: $jhub"
echo " Group Name: ${group_name:-"(not set)"}"
# ----------- NORMALIZE BOOLEAN VALUES ----------- #
normalize_bool() {
local val="$1"
case "$val" in
true|True|TRUE|1) echo "True" ;;
false|False|FALSE|0|"") echo "False" ;;
*) echo "False" ;;
esac
}
KAFKA_CONNECTION=$(normalize_bool "$streaming")
USE_JUPYTERLAB=$(normalize_bool "$jhub")
# Set PRE_CKAN based on availability of url and key
if [[ -n "$pre_ckan_url" && "$pre_ckan_url" != "null" && -n "$pre_ckan_key" && "$pre_ckan_key" != "null" ]]; then
PRE_CKAN_ENABLED="True"
PRE_CKAN_URL="$pre_ckan_url"
PRE_CKAN_API_KEY="$pre_ckan_key"
else
PRE_CKAN_ENABLED="False"
PRE_CKAN_URL=""
PRE_CKAN_API_KEY=""
fi
# Kafka settings (port must always have a default value for pydantic validation)
if [[ "$KAFKA_CONNECTION" == "True" ]]; then
KAFKA_HOST="kafka"
KAFKA_PORT="9093"
else
KAFKA_HOST="localhost"
KAFKA_PORT="9093"
fi
# JupyterLab settings
if [[ "$USE_JUPYTERLAB" == "True" ]]; then
if [[ -n "$jupyter_url" && "$jupyter_url" != "null" ]]; then
JUPYTER_URL="$jupyter_url"
else
JUPYTER_URL="http://jupyterlab:8888"
fi
else
JUPYTER_URL=""
fi
# Group-based access control
if [[ -n "$group_name" && "$group_name" != "null" ]]; then
ENABLE_GROUP_BASED_ACCESS="True"
GROUP_NAMES="$group_name"
else
ENABLE_GROUP_BASED_ACCESS="False"
GROUP_NAMES=""
fi
# ----------- GET MACHINE IP ----------- #
machine_ip=$(hostname -I | awk '{print $1}' 2>/dev/null || echo "localhost")
# ----------- CREATE INSTALLATION DIRECTORY ----------- #
print_step "Creating installation directory: $install_dir"
mkdir -p "$install_dir"
cd "$install_dir"
print_info "Catalog backend: $catalog_backend"
print_info "Machine IP: $machine_ip"
# ----------- SETUP CKAN BACKEND ----------- #
if [[ "$catalog_backend" == "ckan" ]]; then
print_step "Setting up CKAN backend..."
# Clone CKAN Docker repository
print_info "Cloning CKAN Docker repository..."
git clone "$CKAN_DOCKER_REPO" ckan-docker
# Configure CKAN
cd ckan-docker
cp .env.example .env
# Get CKAN credentials from Federation API config
ckan_name=$(echo "$config_json" | jq -r '.ckan_name // "ckan_admin"')
ckan_password=$(echo "$config_json" | jq -r '.ckan_password // "test1234"')
# Configure CKAN environment
sed -i "s/^CKAN_SYSADMIN_NAME=.*/CKAN_SYSADMIN_NAME=${ckan_name}/" .env
sed -i "s/^CKAN_SYSADMIN_PASSWORD=.*/CKAN_SYSADMIN_PASSWORD=${ckan_password}/" .env
sed -i "s|^CKAN_SITE_URL=.*|CKAN_SITE_URL=https://${machine_ip}:8443|" .env
print_success "CKAN configured"
# Go back to install_dir for API setup
cd ..
# Set CKAN URL and API key variables for .env
CKAN_URL="https://ckan:8443"
CKAN_API_KEY="" # Will be generated after CKAN starts
fi
# ----------- GENERATE DOCKER-COMPOSE.YML ----------- #
print_step "Generating docker-compose.yml..."
if [[ "$catalog_backend" == "mongodb" ]]; then
# MongoDB backend docker-compose
cat > docker-compose.yml << 'COMPOSE_EOF'
services:
# ==============================================
# API Service (always starts)
# ==============================================
api:
image: rbardaji/ndp-ep-api:latest
container_name: ndp-ep-api
ports:
- "8002:8000"
env_file:
- .env
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- ndp-network
restart: unless-stopped
depends_on:
mongodb:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# ==============================================
# MongoDB - Local Catalog Backend
# ==============================================
mongodb:
image: mongo:7
container_name: ndp-mongodb
ports:
- "27018:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin123
MONGO_INITDB_DATABASE: ndp_local_catalog
volumes:
- mongodb_data:/data/db
- mongodb_config:/data/configdb
networks:
- ndp-network
restart: unless-stopped
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 10s
timeout: 5s
retries: 5
start_period: 20s
# ==============================================
# Mongo Express - MongoDB Web UI
# ==============================================
mongo-express:
image: mongo-express:latest
container_name: ndp-mongo-express
ports:
- "8082:8081"
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
ME_CONFIG_MONGODB_ADMINPASSWORD: admin123
ME_CONFIG_MONGODB_URL: mongodb://admin:admin123@mongodb:27017/
ME_CONFIG_BASICAUTH_USERNAME: admin
ME_CONFIG_BASICAUTH_PASSWORD: admin123
ME_CONFIG_MONGODB_ENABLE_ADMIN: 'true'
networks:
- ndp-network
depends_on:
mongodb:
condition: service_healthy
restart: unless-stopped
# ==============================================
# MinIO - S3-Compatible Object Storage
# ==============================================
minio:
image: minio/minio:latest
container_name: ndp-minio
ports:
- "9002:9000"
- "9003:9001"
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin123
command: server /data --console-address ":9001"
volumes:
- minio_data:/data
networks:
- ndp-network
restart: unless-stopped
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 10s
timeout: 5s
retries: 5
# ==============================================
# Zookeeper - Required for Kafka
# ==============================================
zookeeper:
image: confluentinc/cp-zookeeper:7.6.0
container_name: ndp-zookeeper
profiles: ["kafka"]
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_LOG4J_ROOT_LOGLEVEL: WARN
volumes:
- zookeeper_data:/var/lib/zookeeper/data
- zookeeper_log:/var/lib/zookeeper/log
networks:
- ndp-network
restart: unless-stopped
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "2181"]
interval: 10s
timeout: 5s
retries: 5
# ==============================================
# Kafka - Streaming Platform
# ==============================================
kafka:
image: confluentinc/cp-kafka:7.6.0
container_name: ndp-kafka
profiles: ["kafka"]
ports:
- "9094:9092"
- "9095:9093"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9093,PLAINTEXT_HOST://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_LOG4J_ROOT_LOGLEVEL: WARN
KAFKA_TOOLS_LOG4J_LOGLEVEL: ERROR
volumes:
- kafka_data:/var/lib/kafka/data
networks:
- ndp-network
depends_on:
zookeeper:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD", "kafka-broker-api-versions", "--bootstrap-server", "localhost:9093"]
interval: 10s
timeout: 10s
retries: 5
start_period: 30s
# ==============================================
# Kafka UI - Web Interface for Kafka Management
# ==============================================
kafka-ui:
image: provectuslabs/kafka-ui:latest
container_name: ndp-kafka-ui
profiles: ["kafka"]
ports:
- "8081:8080"
environment:
KAFKA_CLUSTERS_0_NAME: ndp-cluster
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9093
KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper:2181
DYNAMIC_CONFIG_ENABLED: 'true'
networks:
- ndp-network
depends_on:
kafka:
condition: service_healthy
restart: unless-stopped
# ==============================================
# JupyterLab - Interactive Development Environment
# ==============================================
jupyterlab:
image: jupyter/scipy-notebook:latest
container_name: ndp-jupyterlab
profiles: ["jupyter"]
ports:
- "8888:8888"
environment:
JUPYTER_ENABLE_LAB: 'yes'
JUPYTER_TOKEN: testing_token
volumes:
- jupyterlab_data:/home/jovyan/work
networks:
- ndp-network
restart: unless-stopped
command: start-notebook.sh --NotebookApp.token='testing_token' --NotebookApp.password=''
# ==============================================
# Volumes - Persistent Data Storage
# ==============================================
volumes:
mongodb_data:
driver: local
mongodb_config:
driver: local
minio_data:
driver: local
zookeeper_data:
driver: local
zookeeper_log:
driver: local
kafka_data:
driver: local
jupyterlab_data:
driver: local
# ==============================================
# Network Configuration
# ==============================================
networks:
ndp-network:
driver: bridge
COMPOSE_EOF
else
# CKAN backend docker-compose (API only, CKAN is in separate directory)
cat > docker-compose.yml << 'COMPOSE_EOF'
services:
# ==============================================
# API Service (always starts)
# ==============================================
api:
image: rbardaji/ndp-ep-api:latest
container_name: ndp-ep-api
ports:
- "8002:8000"
env_file:
- .env
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- ndp-network
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# ==============================================
# MinIO - S3-Compatible Object Storage
# ==============================================
minio:
image: minio/minio:latest
container_name: ndp-minio
ports:
- "9002:9000"
- "9003:9001"
environment:
MINIO_ROOT_USER: minioadmin
MINIO_ROOT_PASSWORD: minioadmin123
command: server /data --console-address ":9001"
volumes:
- minio_data:/data
networks:
- ndp-network
restart: unless-stopped
healthcheck:
test: ["CMD", "mc", "ready", "local"]
interval: 10s
timeout: 5s
retries: 5
# ==============================================
# Zookeeper - Required for Kafka
# ==============================================
zookeeper:
image: confluentinc/cp-zookeeper:7.6.0
container_name: ndp-zookeeper
profiles: ["kafka"]
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_LOG4J_ROOT_LOGLEVEL: WARN
volumes:
- zookeeper_data:/var/lib/zookeeper/data
- zookeeper_log:/var/lib/zookeeper/log
networks:
- ndp-network
restart: unless-stopped
healthcheck:
test: ["CMD", "nc", "-z", "localhost", "2181"]
interval: 10s
timeout: 5s
retries: 5
# ==============================================
# Kafka - Streaming Platform
# ==============================================
kafka:
image: confluentinc/cp-kafka:7.6.0
container_name: ndp-kafka
profiles: ["kafka"]
ports:
- "9094:9092"
- "9095:9093"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9093,PLAINTEXT_HOST://localhost:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_LOG4J_ROOT_LOGLEVEL: WARN
KAFKA_TOOLS_LOG4J_LOGLEVEL: ERROR
volumes:
- kafka_data:/var/lib/kafka/data
networks:
- ndp-network
depends_on:
zookeeper:
condition: service_healthy
restart: unless-stopped
healthcheck:
test: ["CMD", "kafka-broker-api-versions", "--bootstrap-server", "localhost:9093"]
interval: 10s
timeout: 10s
retries: 5
start_period: 30s
# ==============================================
# Kafka UI - Web Interface for Kafka Management
# ==============================================
kafka-ui:
image: provectuslabs/kafka-ui:latest
container_name: ndp-kafka-ui
profiles: ["kafka"]
ports:
- "8081:8080"
environment:
KAFKA_CLUSTERS_0_NAME: ndp-cluster
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9093
KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper:2181
DYNAMIC_CONFIG_ENABLED: 'true'
networks:
- ndp-network
depends_on:
kafka:
condition: service_healthy
restart: unless-stopped
# ==============================================
# JupyterLab - Interactive Development Environment
# ==============================================
jupyterlab:
image: jupyter/scipy-notebook:latest
container_name: ndp-jupyterlab
profiles: ["jupyter"]
ports:
- "8888:8888"
environment:
JUPYTER_ENABLE_LAB: 'yes'
JUPYTER_TOKEN: testing_token
volumes:
- jupyterlab_data:/home/jovyan/work
networks:
- ndp-network
restart: unless-stopped
command: start-notebook.sh --NotebookApp.token='testing_token' --NotebookApp.password=''
# ==============================================
# Volumes - Persistent Data Storage
# ==============================================
volumes:
minio_data:
driver: local
zookeeper_data:
driver: local
zookeeper_log:
driver: local
kafka_data:
driver: local
jupyterlab_data:
driver: local
# ==============================================
# Network Configuration
# ==============================================
networks:
ndp-network:
driver: bridge
COMPOSE_EOF
fi
print_success "docker-compose.yml generated"
# ----------- SET BACKEND-SPECIFIC VARIABLES ----------- #
if [[ "$catalog_backend" == "mongodb" ]]; then
MONGODB_CONNECTION_STRING="mongodb://admin:admin123@mongodb:27017"
MONGODB_DATABASE="ndp_local_catalog"
CKAN_URL=""
CKAN_API_KEY=""
else
# CKAN backend
MONGODB_CONNECTION_STRING=""
MONGODB_DATABASE=""
CKAN_URL="https://localhost:8443"
CKAN_API_KEY="" # Will be set after CKAN starts
fi
# ----------- GENERATE .ENV FILE ----------- #
print_step "Generating .env file..."
cat > .env << EOF
# ==============================================
# NDP-EP API Configuration
# Generated by setup.sh on $(date)
# Config ID: $config_id
# ==============================================
# ==============================================
# API CONFIGURATION
# ==============================================
ROOT_PATH=
# ==============================================
# ORGANIZATION
# ==============================================
ORGANIZATION="$organization"
EP_NAME="$ep_name"
# ==============================================
# METRICS CONFIGURATION
# ==============================================
METRICS_INTERVAL_SECONDS=3300
# ==============================================
# ACCESS CONTROL
# ==============================================
ENABLE_GROUP_BASED_ACCESS=$ENABLE_GROUP_BASED_ACCESS
GROUP_NAMES=$GROUP_NAMES
# ==============================================
# LOCAL CATALOG CONFIGURATION
# ==============================================
LOCAL_CATALOG_BACKEND=$catalog_backend
CKAN_LOCAL_ENABLED=True
# ==============================================
# CKAN Configuration
# ==============================================
CKAN_URL=${CKAN_URL:-}
CKAN_API_KEY=${CKAN_API_KEY:-}
CKAN_VERIFY_SSL=False
# ==============================================
# MongoDB Configuration
# ==============================================
MONGODB_CONNECTION_STRING=${MONGODB_CONNECTION_STRING:-}
MONGODB_DATABASE=${MONGODB_DATABASE:-}
# ==============================================
# Pre-CKAN Configuration
# ==============================================
PRE_CKAN_ENABLED=$PRE_CKAN_ENABLED
PRE_CKAN_URL=$PRE_CKAN_URL
PRE_CKAN_API_KEY=$PRE_CKAN_API_KEY
PRE_CKAN_VERIFY_SSL=True
# ==============================================
# Kafka Configuration
# ==============================================
KAFKA_CONNECTION=$KAFKA_CONNECTION
KAFKA_HOST=$KAFKA_HOST
KAFKA_PORT=$KAFKA_PORT
# ==============================================
# Authentication
# ==============================================
TEST_TOKEN=testing_token
AUTH_API_URL=https://idp.nationaldataplatform.org/temp/information
# ==============================================
# JupyterLab
# ==============================================
USE_JUPYTERLAB=$USE_JUPYTERLAB
JUPYTER_URL=$JUPYTER_URL
# ==============================================
# S3 Storage (MinIO)
# ==============================================
S3_ENABLED=True
S3_ENDPOINT=minio:9000
S3_ACCESS_KEY=minioadmin
S3_SECRET_KEY=minioadmin123
S3_SECURE=False
S3_REGION=us-east-1
# ==============================================
# Pelican Federation
# ==============================================
PELICAN_ENABLED=False
PELICAN_FEDERATION_URL=
PELICAN_DIRECT_READS=False
EOF
print_success ".env file generated"
# ----------- GENERATE INFO FILE ----------- #
info_file="setup_info.txt"
cat > "$info_file" << EOF
# ==============================================
# NDP-EP API Setup Information
# Generated: $(date)
# ==============================================
Configuration ID: $config_id
Federation API: $federation_url
Installation Directory: $(pwd)
Catalog Backend: $catalog_backend
Organization: $organization
EP Name: $ep_name
Machine IP: $machine_ip
Services Enabled:
- API: Yes (rbardaji/ndp-ep-api:latest)
- Local Catalog: $catalog_backend
- MinIO (S3): Yes
- Pre-CKAN: $PRE_CKAN_ENABLED
- Kafka Streaming: $KAFKA_CONNECTION
- JupyterLab: $USE_JUPYTERLAB
Access URLs:
- API: http://${machine_ip}:8002
- API Docs: http://${machine_ip}:8002/docs
- MinIO Console: http://${machine_ip}:9003
EOF
if [[ "$catalog_backend" == "mongodb" ]]; then
echo " - MongoDB Express: http://${machine_ip}:8082" >> "$info_file"
else
echo " - CKAN: https://${machine_ip}:8443" >> "$info_file"
fi
if [[ "$KAFKA_CONNECTION" == "True" ]]; then
echo " - Kafka UI: http://${machine_ip}:8081" >> "$info_file"
fi
if [[ "$USE_JUPYTERLAB" == "True" ]]; then
echo " - JupyterLab: http://${machine_ip}:8888" >> "$info_file"
fi
print_info "Setup info saved to $info_file"
# ----------- START SERVICES ----------- #
if [[ "$no_start" == false ]]; then
print_step "Starting services..."
# Build docker compose command with profiles
compose_profiles=""
if [[ "$KAFKA_CONNECTION" == "True" ]]; then
compose_profiles="$compose_profiles --profile kafka"
fi
if [[ "$USE_JUPYTERLAB" == "True" ]]; then
compose_profiles="$compose_profiles --profile jupyter"
fi
# Start CKAN first if using CKAN backend
if [[ "$catalog_backend" == "ckan" ]]; then
print_info "Starting CKAN services..."
cd ckan-docker
$DOCKER_COMPOSE_CMD up -d --build
print_info "Waiting for CKAN to become healthy (this may take 2-3 minutes)..."
max_attempts=60
attempt=0
while [[ $attempt -lt $max_attempts ]]; do
status=$(docker inspect --format='{{.State.Health.Status}}' ckan 2>/dev/null || echo "starting")
if [[ "$status" == "healthy" ]]; then
print_success "CKAN is healthy!"
break
fi
attempt=$((attempt + 1))
echo -ne "\rWaiting for CKAN... ($attempt/$max_attempts) - status: $status"
sleep 10
done
echo ""
if [[ $attempt -eq $max_attempts ]]; then
print_error "CKAN did not become healthy in time. Check logs with: $DOCKER_COMPOSE_CMD logs ckan"
else
# Generate CKAN API key
print_info "Generating CKAN API key..."
ckan_container=$(docker ps --filter "name=ckan" --format "{{.Names}}" | grep -v solr | grep -v redis | grep -v db | grep -v nginx | grep -v datapusher | head -1)
if [[ -n "$ckan_container" ]]; then
api_key=$(docker exec "$ckan_container" ckan -c /srv/app/ckan.ini user token add "$ckan_name" api_token 2>/dev/null | grep -oE 'eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*' | head -1)
if [[ -n "$api_key" ]]; then
# Update .env with CKAN API key
cd ..
sed -i "s|^CKAN_API_KEY=.*|CKAN_API_KEY=$api_key|" .env
print_success "CKAN API key generated"
else
print_info "Could not generate API key automatically. Generate it from the CKAN web UI."
cd ..
fi
else
cd ..
fi
fi
fi
print_info "Pulling latest images..."
$DOCKER_COMPOSE_CMD $compose_profiles pull
print_info "Starting containers..."
$DOCKER_COMPOSE_CMD $compose_profiles up -d
print_info "Waiting for services to start..."
sleep 10
# Check API health
max_attempts=30
attempt=0
while [[ $attempt -lt $max_attempts ]]; do
if curl -s "http://localhost:8002/" > /dev/null 2>&1; then
print_success "API is running!"
break
fi
attempt=$((attempt + 1))
echo -ne "\rWaiting for API... ($attempt/$max_attempts)"
sleep 2
done
echo ""
if [[ $attempt -eq $max_attempts ]]; then
print_error "API did not start in time. Check logs with: $DOCKER_COMPOSE_CMD logs api"
fi
fi
# ----------- PRINT SUMMARY ----------- #
echo ""
echo -e "${GREEN}========================================"
echo " Setup Complete!"
echo -e "========================================${NC}"
echo ""
echo -e "${BLUE}Installation Directory:${NC} $(pwd)"
echo ""
echo -e "${BLUE}Configuration:${NC}"
echo " Organization: $organization"
echo " EP Name: $ep_name"
echo " Config ID: $config_id"
echo " Catalog Backend: $catalog_backend"
echo ""
echo -e "${BLUE}Services:${NC}"
echo " - API: http://${machine_ip}:8002"