Browse Source

[Nanobox] Enable ElasticSearch support by default (#6977)

Admins can still disable the feature by adding `ES_ENABLED=false` to their environment, if they prefer not to use it. Be sure to set the variable before you deploy!
Daniel Hunsaker 8 months ago
parent
commit
3886bfb5eb
2 changed files with 34 additions and 3 deletions
  1. 3
    3
      .env.nanobox
  2. 31
    0
      boxfile.yml

+ 3
- 3
.env.nanobox View File

@@ -14,9 +14,9 @@ DB_PORT=5432
14 14
 DATABASE_URL=postgresql://$DATA_DB_USER:$DATA_DB_PASS@$DATA_DB_HOST/gonano
15 15
 
16 16
 # Optional ElasticSearch configuration
17
-# ES_ENABLED=true
18
-# ES_HOST=localhost
19
-# ES_PORT=9200
17
+ES_ENABLED=true
18
+ES_HOST=$DATA_ELASTIC_HOST
19
+ES_PORT=9200
20 20
 
21 21
 # Optimizations
22 22
 LD_PRELOAD=/data/lib/libjemalloc.so

+ 31
- 0
boxfile.yml View File

@@ -61,6 +61,11 @@ deploy.config:
61 61
   before_live:
62 62
     web.web:
63 63
       - bundle exec rake db:migrate:setup
64
+      - |-
65
+          if [[ "${ES_ENABLED}" != "false" ]]
66
+          then
67
+            bundle exec rake chewy:deploy
68
+          fi
64 69
 
65 70
 
66 71
 web.web:
@@ -208,6 +213,32 @@ data.db:
208 213
         done
209 214
 
210 215
 
216
+data.elastic:
217
+  image: nanobox/elasticsearch:5
218
+
219
+  cron:
220
+    - id: backup
221
+      schedule: '0 3 * * *'
222
+      command: |
223
+        id=$(cat /proc/sys/kernel/random/uuid)
224
+        curl -X PUT -H "Content-Type: application/json" "127.0.0.1:9200/_snapshot/${id}" -d "{\"type\": \"fs\",\"settings\": {\"location\": \"/var/tmp/${id}\",\"compress\": true}}"
225
+        curl -X PUT -H "Content-Type: application/json" "127.0.0.1:9200/_snapshot/${id}/backup?wait_for_completion=true&pretty"
226
+        tar -cz -C "/var/tmp/${id}" . |
227
+        curl -k -H "X-AUTH-TOKEN: ${WAREHOUSE_DATA_HOARDER_TOKEN}" https://${WAREHOUSE_DATA_HOARDER_HOST}:7410/blobs/backup-${HOSTNAME}-$(date -u +%Y-%m-%d.%H-%M-%S).tgz -X POST -T - >&2
228
+        curl -X DELETE -H "Content-Type: application/json" "127.0.0.1:9200/_snapshot/${id}"
229
+        rm -rf "/var/tmp/${id}"
230
+        curl -k -s -H "X-AUTH-TOKEN: ${WAREHOUSE_DATA_HOARDER_TOKEN}" https://${WAREHOUSE_DATA_HOARDER_HOST}:7410/blobs/ |
231
+        sed 's/,/\n/g' |
232
+        grep ${HOSTNAME} |
233
+        sort |
234
+        head -n-${BACKUP_COUNT:-1} |
235
+        sed 's/.*: \?"\(.*\)".*/\1/' |
236
+        while read file
237
+        do
238
+          curl -k -H "X-AUTH-TOKEN: ${WAREHOUSE_DATA_HOARDER_TOKEN}" https://${WAREHOUSE_DATA_HOARDER_HOST}:7410/blobs/${file} -X DELETE
239
+        done
240
+
241
+
211 242
 data.redis:
212 243
   image: nanobox/redis:4.0
213 244