|
1 | | -# Elasticsearch for JavaZone |
| 1 | +# JavaZone Elasticsearch Integration |
2 | 2 |
|
3 | | -Elasticsearch deployment on AWS Fargate with EFS persistent storage. |
| 3 | +Complete Elasticsearch integration for JavaZone - all in one repository! |
4 | 4 |
|
5 | | -## Architecture |
| 5 | +## 🎯 What This Deploys |
6 | 6 |
|
7 | | -- **Single Fargate task** running Elasticsearch 8.11 |
8 | | -- **EFS volume** for persistent data storage |
9 | | -- **Service Discovery** for stable DNS: `elasticsearch.javazone.internal:9200` |
10 | | -- **1 vCPU, 2GB RAM** (sufficient for ~10K talks) |
| 7 | +**AWS (via Terraform):** |
| 8 | +- SQS queues (main + DLQ) |
| 9 | +- webhook-receiver Lambda (API Gateway) |
| 10 | +- es-indexer-worker Lambda (SQS triggered) |
11 | 11 |
|
12 | | -## Deployment |
| 12 | +**Coolify (manual):** |
| 13 | +- Elasticsearch 8.11.0 |
13 | 14 |
|
14 | | -### 1. Deploy Infrastructure |
| 15 | +**Cost: ~$2-5/month AWS + $0 Coolify = ~$2-5/month total** |
15 | 16 |
|
16 | | -```bash |
17 | | -cd terraform |
18 | | - |
19 | | -cp terraform.tfvars.example terraform.tfvars |
20 | | -# Edit with your values |
| 17 | +--- |
21 | 18 |
|
22 | | -terraform init |
23 | | -terraform apply |
24 | | -``` |
| 19 | +## 🚀 Quick Start |
25 | 20 |
|
26 | | -**What this creates:** |
27 | | -- ECS Cluster and Fargate task |
28 | | -- EFS file system for data persistence |
29 | | -- Security groups |
30 | | -- Service discovery (optional DNS name) |
31 | | -- SSM parameter for password |
| 21 | +### 1. Deploy Elasticsearch on Coolify |
32 | 22 |
|
33 | | -**Cost:** ~$35-45/month (Fargate + EFS) |
| 23 | +1. Coolify → New Resource → Docker Image |
| 24 | +2. Image: `elasticsearch:8.11.0` |
| 25 | +3. Environment: |
| 26 | + ``` |
| 27 | + discovery.type=single-node |
| 28 | + xpack.security.enabled=true |
| 29 | + ELASTIC_PASSWORD=bi75Xtl3KPXI4CS7QRU8TrFRpF3mV1qX |
| 30 | + ES_JAVA_OPTS=-Xms1g -Xmx1g |
| 31 | + ``` |
| 32 | +4. Volume: `/data/elasticsearch` → `/usr/share/elasticsearch/data` |
| 33 | +5. Port: `9200` |
| 34 | +6. Deploy |
34 | 35 |
|
35 | | -### 2. Wait for Elasticsearch to Start |
| 36 | +7. Create index: |
| 37 | + ```bash |
| 38 | + curl -X PUT "http://your-es-url:9200/javazone_talks" \ |
| 39 | + -u elastic:bi75Xtl3KPXI4CS7QRU8TrFRpF3mV1qX \ |
| 40 | + -H "Content-Type: application/json" \ |
| 41 | + -d @config/index-mapping.json |
| 42 | + ``` |
36 | 43 |
|
37 | | -```bash |
38 | | -# Check task status |
39 | | -aws ecs list-tasks --cluster elasticsearch-javazone --region eu-central-1 |
40 | | - |
41 | | -# Get task IP (if not using service discovery) |
42 | | -aws ecs describe-tasks \ |
43 | | - --cluster elasticsearch-javazone \ |
44 | | - --tasks <task-arn> \ |
45 | | - --region eu-central-1 | grep "privateIpv4Address" |
46 | | -``` |
| 44 | +8. Update GitHub secret with your ES URL: |
| 45 | + ```bash |
| 46 | + gh secret set ELASTICSEARCH_URL --body "http://your-elasticsearch-domain:9200" |
| 47 | + ``` |
47 | 48 |
|
48 | | -### 3. Create Index |
| 49 | +--- |
49 | 50 |
|
50 | | -If using service discovery: |
51 | | -```bash |
52 | | -ES_URL="http://elasticsearch.javazone.internal:9200" |
53 | | -``` |
| 51 | +### 2. Deploy AWS Infrastructure (GitHub Actions) |
54 | 52 |
|
55 | | -Otherwise: |
56 | | -```bash |
57 | | -ES_URL="http://<task-private-ip>:9200" |
58 | | -``` |
| 53 | +Push to `main` or manually trigger workflow: |
59 | 54 |
|
60 | | -Create the index: |
61 | | -```bash |
62 | | -curl -X PUT "$ES_URL/javazone_talks" \ |
63 | | - -u elastic:<your-password> \ |
64 | | - -H "Content-Type: application/json" \ |
65 | | - -d @../config/index-mapping.json |
66 | | -``` |
| 55 | +https://github.com/javaBin/elasticsearch-javazone/actions |
67 | 56 |
|
68 | | -Verify: |
69 | | -```bash |
70 | | -curl -u elastic:<password> "$ES_URL/javazone_talks" |
71 | | -curl -u elastic:<password> "$ES_URL/_cluster/health" |
72 | | -``` |
| 57 | +Deploys: SQS + 2 Lambdas (~2 minutes) |
73 | 58 |
|
74 | | -## Access from Other Services |
| 59 | +--- |
75 | 60 |
|
76 | | -### With Service Discovery (Recommended) |
77 | | -``` |
78 | | -ELASTICSEARCH_URL=http://elasticsearch.javazone.internal:9200 |
79 | | -``` |
| 61 | +### 3. Configure Moresleep |
80 | 62 |
|
81 | | -Use this in: |
82 | | -- es-indexer-worker terraform.tfvars |
83 | | -- libum configuration |
| 63 | +Use webhook URL from GitHub Actions output: |
84 | 64 |
|
85 | | -### Without Service Discovery |
86 | | -Use the task's private IP (changes on restart): |
87 | | -``` |
88 | | -ELASTICSEARCH_URL=http://10.0.x.x:9200 |
| 65 | +```properties |
| 66 | +WEBHOOK_ENABLED=true |
| 67 | +WEBHOOK_ENDPOINT=<url-from-output> |
| 68 | +WEBHOOK_SECRET=7faa5e7879e189dfdeab497f647a88e15abcd7be4c2209f318465e764547d258 |
89 | 69 | ``` |
90 | 70 |
|
91 | | -## Monitoring |
| 71 | +Redeploy moresleep. |
92 | 72 |
|
93 | | -View task logs in AWS ECS Console: |
94 | | -- ECS → Clusters → elasticsearch-javazone → Tasks → View logs tab |
| 73 | +--- |
95 | 74 |
|
96 | | -Check cluster health: |
97 | | -```bash |
98 | | -curl -u elastic:<password> "$ES_URL/_cluster/health" |
99 | | -``` |
100 | | - |
101 | | -Check document count: |
102 | | -```bash |
103 | | -curl -u elastic:<password> "$ES_URL/javazone_talks/_count" |
104 | | -``` |
105 | | - |
106 | | -## Data Persistence |
107 | | - |
108 | | -Data is stored on EFS and persists across task restarts. To completely reset: |
| 75 | +## ✅ Testing |
109 | 76 |
|
| 77 | +Create a talk → Check ES within 10 seconds: |
110 | 78 | ```bash |
111 | | -# Stop service |
112 | | -aws ecs update-service \ |
113 | | - --cluster elasticsearch-javazone \ |
114 | | - --service elasticsearch-javazone \ |
115 | | - --desired-count 0 |
116 | | - |
117 | | -# Delete EFS data (requires EC2 instance or Fargate task with EFS mounted) |
118 | | -# Then restart service |
119 | | -aws ecs update-service \ |
120 | | - --cluster elasticsearch-javazone \ |
121 | | - --service elasticsearch-javazone \ |
122 | | - --desired-count 1 |
| 79 | +curl -u elastic:pass "http://your-es-url:9200/javazone_talks/_search?q=test" |
123 | 80 | ``` |
124 | 81 |
|
125 | | -## Cost Estimate |
126 | | - |
127 | | -- **Fargate**: ~$25-30/month (1 vCPU, 2GB, always running) |
128 | | -- **EFS**: ~$10-15/month (5-10GB data) |
129 | | -- **SSM**: Free |
130 | | -- **Service Discovery**: Free |
131 | | - |
132 | | -**Total: ~$35-45/month** |
133 | | - |
134 | | -## Scaling |
135 | | - |
136 | | -For higher load (unlikely needed): |
137 | | -- Increase `task_cpu` and `task_memory` in terraform.tfvars |
138 | | -- Apply and restart |
139 | | - |
140 | | -For production HA: |
141 | | -- Deploy multiple tasks |
142 | | -- Use Application Load Balancer |
143 | | -- Multiple AZ deployment |
144 | | - |
145 | | -But for 10K talks, single task is sufficient. |
146 | | - |
147 | | -## Backup |
148 | | - |
149 | | -EFS data is persistent, but consider: |
150 | | -- EFS automatic backups (AWS Backup) |
151 | | -- Elasticsearch snapshot repository |
152 | | -- Periodic manual snapshots |
| 82 | +--- |
153 | 83 |
|
154 | | -## Sample Queries |
| 84 | +**Total setup time: ~10 minutes** |
| 85 | +**Monthly cost: ~$2-5** |
155 | 86 |
|
156 | | -See `config/sample-queries.sh` for common Elasticsearch queries. |
| 87 | +Perfect! 🎉 |
0 commit comments