|
| 1 | +name: cnpmcore_dev_services_es |
| 2 | + |
| 3 | +volumes: |
| 4 | + certs: |
| 5 | + driver: local |
| 6 | + esdata01: |
| 7 | + driver: local |
| 8 | + kibanadata: |
| 9 | + driver: local |
| 10 | + |
| 11 | +services: |
| 12 | + setup: |
| 13 | + image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION} |
| 14 | + volumes: |
| 15 | + - certs:/usr/share/elasticsearch/config/certs |
| 16 | + user: "0" |
| 17 | + command: > |
| 18 | + bash -c ' |
| 19 | + if [ x${ELASTIC_PASSWORD} == x ]; then |
| 20 | + echo "Set the ELASTIC_PASSWORD environment variable in the .env file"; |
| 21 | + exit 1; |
| 22 | + elif [ x${KIBANA_PASSWORD} == x ]; then |
| 23 | + echo "Set the KIBANA_PASSWORD environment variable in the .env file"; |
| 24 | + exit 1; |
| 25 | + fi; |
| 26 | + if [ ! -f config/certs/ca.zip ]; then |
| 27 | + echo "Creating CA"; |
| 28 | + bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip; |
| 29 | + unzip config/certs/ca.zip -d config/certs; |
| 30 | + fi; |
| 31 | + if [ ! -f config/certs/certs.zip ]; then |
| 32 | + echo "Creating certs"; |
| 33 | + echo -ne \ |
| 34 | + "instances:\n"\ |
| 35 | + " - name: es01\n"\ |
| 36 | + " dns:\n"\ |
| 37 | + " - es01\n"\ |
| 38 | + " - localhost\n"\ |
| 39 | + " ip:\n"\ |
| 40 | + " - 127.0.0.1\n"\ |
| 41 | + " - name: kibana\n"\ |
| 42 | + " dns:\n"\ |
| 43 | + " - kibana\n"\ |
| 44 | + " - localhost\n"\ |
| 45 | + " ip:\n"\ |
| 46 | + " - 127.0.0.1\n"\ |
| 47 | + > config/certs/instances.yml; |
| 48 | + bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key; |
| 49 | + unzip config/certs/certs.zip -d config/certs; |
| 50 | + fi; |
| 51 | + echo "Setting file permissions" |
| 52 | + chown -R root:root config/certs; |
| 53 | + find . -type d -exec chmod 750 \{\} \;; |
| 54 | + find . -type f -exec chmod 640 \{\} \;; |
| 55 | + echo "Waiting for Elasticsearch availability"; |
| 56 | + until curl -s --cacert config/certs/ca/ca.crt http://es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done; |
| 57 | + echo "Setting kibana_system password"; |
| 58 | + until curl -s -X POST --cacert config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" http://es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done; |
| 59 | + echo "All done!"; |
| 60 | + ' |
| 61 | + healthcheck: |
| 62 | + test: ["CMD-SHELL", "[ -f config/certs/es01/es01.crt ]"] |
| 63 | + interval: 1s |
| 64 | + timeout: 5s |
| 65 | + retries: 120 |
| 66 | + |
| 67 | + es01: |
| 68 | + depends_on: |
| 69 | + setup: |
| 70 | + condition: service_healthy |
| 71 | + image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}${STACK_VERSION_ARM64} |
| 72 | + platform: ${STACK_PLATFORM} |
| 73 | + labels: |
| 74 | + co.elastic.logs/module: elasticsearch |
| 75 | + volumes: |
| 76 | + - certs:/usr/share/elasticsearch/config/certs |
| 77 | + - esdata01:/usr/share/elasticsearch/data |
| 78 | + ports: |
| 79 | + - ${ES_PORT}:9200 |
| 80 | + environment: |
| 81 | + - node.name=es01 |
| 82 | + - cluster.name=${CLUSTER_NAME} |
| 83 | + - discovery.type=single-node |
| 84 | + - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} |
| 85 | + - bootstrap.memory_lock=true |
| 86 | + - xpack.security.enabled=true |
| 87 | + - xpack.security.http.ssl.enabled=false |
| 88 | + - xpack.security.http.ssl.key=certs/es01/es01.key |
| 89 | + - xpack.security.http.ssl.certificate=certs/es01/es01.crt |
| 90 | + - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt |
| 91 | + - xpack.security.transport.ssl.enabled=false |
| 92 | + - xpack.security.transport.ssl.key=certs/es01/es01.key |
| 93 | + - xpack.security.transport.ssl.certificate=certs/es01/es01.crt |
| 94 | + - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt |
| 95 | + - xpack.security.transport.ssl.verification_mode=certificate |
| 96 | + - xpack.license.self_generated.type=${LICENSE} |
| 97 | + mem_limit: ${ES_MEM_LIMIT} |
| 98 | + ulimits: |
| 99 | + memlock: |
| 100 | + soft: -1 |
| 101 | + hard: -1 |
| 102 | + healthcheck: |
| 103 | + test: |
| 104 | + [ |
| 105 | + "CMD-SHELL", |
| 106 | + "curl -s --cacert config/certs/ca/ca.crt http://localhost:9200 | grep -q 'missing authentication credentials'", |
| 107 | + ] |
| 108 | + interval: 10s |
| 109 | + timeout: 10s |
| 110 | + retries: 120 |
| 111 | + |
| 112 | + kibana: |
| 113 | + depends_on: |
| 114 | + es01: |
| 115 | + condition: service_healthy |
| 116 | + image: docker.elastic.co/kibana/kibana:${STACK_VERSION} |
| 117 | + labels: |
| 118 | + co.elastic.logs/module: kibana |
| 119 | + volumes: |
| 120 | + - certs:/usr/share/kibana/config/certs |
| 121 | + - kibanadata:/usr/share/kibana/data |
| 122 | + ports: |
| 123 | + - ${KIBANA_PORT}:5601 |
| 124 | + environment: |
| 125 | + - SERVERNAME=kibana |
| 126 | + - ELASTICSEARCH_HOSTS=http://es01:9200 |
| 127 | + - ELASTICSEARCH_USERNAME=kibana_system |
| 128 | + - ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD} |
| 129 | + - ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt |
| 130 | + - XPACK_SECURITY_ENCRYPTIONKEY=${ENCRYPTION_KEY} |
| 131 | + - XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=${ENCRYPTION_KEY} |
| 132 | + - XPACK_REPORTING_ENCRYPTIONKEY=${ENCRYPTION_KEY} |
| 133 | + mem_limit: ${KB_MEM_LIMIT} |
| 134 | + healthcheck: |
| 135 | + test: |
| 136 | + [ |
| 137 | + "CMD-SHELL", |
| 138 | + "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'", |
| 139 | + ] |
| 140 | + interval: 10s |
| 141 | + timeout: 10s |
| 142 | + retries: 120 |
0 commit comments