From a63ccf0c9702bd90460eb9a356482ee91dad7831 Mon Sep 17 00:00:00 2001 From: Theouche Date: Tue, 10 Sep 2024 15:12:43 +0200 Subject: [PATCH 1/3] dockerfile adrien --- docker-compose.yml | 165 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index aa21870..33a4a7e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,63 @@ services: + setup: + image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION} + container_name: setup + user: "0" + volumes: + - certs:/usr/share/elasticsearch/config/certs + command: > + bash -c ' + if [ x${ELASTIC_PASSWORD} == x ]; then + echo "Set the ELASTIC_PASSWORD environment variable in the .env file"; + exit 1; + elif [ x${KIBANA_PASSWORD} == x ]; then + echo "Set the KIBANA_PASSWORD environment variable in the .env file"; + exit 1; + fi; + if [ ! -f config/certs/ca.zip ]; then + echo "Creating CA"; + bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip; + unzip config/certs/ca.zip -d config/certs; + fi; + if [ ! -f config/certs/certs.zip ]; then + echo "Creating certs"; + echo -ne \ + "instances:\n"\ + " - name: es01\n"\ + " dns:\n"\ + " - es01\n"\ + " - localhost\n"\ + " ip:\n"\ + " - 127.0.0.1\n"\ + " - name: kibana\n"\ + " dns:\n"\ + " - kibana\n"\ + " - localhost\n"\ + " ip:\n"\ + " - 127.0.0.1\n"\ + > config/certs/instances.yml; + + 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; + unzip config/certs/certs.zip -d config/certs; + fi; + + echo "Setting file permissions" + chown -R root:root config/certs; + find . -type d -exec chmod 750 \{\} \;; + find . -type f -exec chmod 640 \{\} \;; + + echo "Waiting for Elasticsearch availability"; + until curl -s --cacert config/certs/ca/ca.crt https://es01:9200 | grep -q "missing authentication credentials"; do sleep 30; done; + echo "Setting kibana_system password"; + until curl -s -X POST --cacert config/certs/ca/ca.crt -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" https://es01:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done; + echo "All done!"; + ' + healthcheck: + test: ["CMD-SHELL", "[ -f config/certs/es01/es01.crt ]"] + interval: 1s + timeout: 5s + retries: 120 + backend: build: context: . @@ -53,6 +112,104 @@ services: timeout: 5s retries: 5 + es01: + image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION} + container_name: es01 + depends_on: + setup: + condition: service_healthy + volumes: + - certs:/usr/share/elasticsearch/config/certs:ro + - pong_es_data_01:/usr/share/elasticsearch/data + labels: + co.elastic.logs/module: elasticsearch + ports: + - 9200:9200 + environment: + - node.name=es01 + - cluster.name=${CLUSTER_NAME} + - discovery.type=single-node + - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} + - bootstrap.memory_lock=true + - xpack.security.enabled=true + - xpack.security.http.ssl.enabled=true + - xpack.security.http.ssl.key=certs/es01/es01.key + - xpack.security.http.ssl.certificate=certs/es01/es01.crt + - xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt + - xpack.security.transport.ssl.enabled=true + - xpack.security.transport.ssl.key=certs/es01/es01.key + - xpack.security.transport.ssl.certificate=certs/es01/es01.crt + - xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt + - xpack.security.transport.ssl.verification_mode=certificate + - xpack.license.self_generated.type=${LICENSE} + healthcheck: + test: + [ + "CMD-SHELL", + "curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'", + ] + interval: 10s + timeout: 10s + retries: 120 + + kibana: + image: docker.elastic.co/kibana/kibana:${STACK_VERSION} + container_name: kibana + labels: + co.elastic.logs/module: kibana + depends_on: + es01: + condition: service_healthy + volumes: + - certs:/usr/share/kibana/config/certs:ro + - pong_kibana:/usr/share/kibana/data + ports: + - 5601:5601 + environment: + - SERVERNAME=kibana + - ELASTICSEARCH_HOSTS=https://es01:9200 + - ELASTICSEARCH_USERNAME=${KIBANA_USERNAME} + - ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD} + - ELASTICSEARCH_SSL_CERTIFICATEAUTHORITIES=config/certs/ca/ca.crt + - XPACK_SECURITY_ENCRYPTIONKEY=${ENCRYPTION_KEY} + - XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=${ENCRYPTION_KEY} + - XPACK_REPORTING_ENCRYPTIONKEY=${ENCRYPTION_KEY} + healthcheck: + test: + [ + "CMD-SHELL", + "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'" + ] + interval: 10s + timeout: 10s + retries: 120 + + logstash01: + image: docker.elastic.co/logstash/logstash:${STACK_VERSION} + container_name: logstash01 + labels: + co.elastic.logs/module: logstash + user: root + depends_on: + es01: + condition: service_healthy + kibana: + condition: service_healthy + volumes: + - certs:/usr/share/logstash/certs + - pong_logstash_data01:/usr/share/logstash/data + - ./config/logstash.conf:/usr/share/logstash/pipeline/logstash.conf:ro + - pong_django_logs:/usr/share/logstash/logs + ports: + - "5044:5044/udp" + command: logstash -f /usr/share/logstash/pipeline/logstash.conf + environment: + - NODE_NAME="logstash" + - ELASTIC_HOSTS=https://es01:9200 + - ELASTIC_USER=${ELASTIC_USERNAME} + - ELASTIC_PASSWORD=${ELASTIC_PASSWORD} + - xpack.monitoring.enabled=false + volumes: pong: driver: local @@ -68,6 +225,14 @@ volumes: o: bind pong_pg_data: driver: local + pong_es_data_01: + driver: local + pong_kibana: + driver: local + pong_logstash_data01: + driver: local + certs: + driver: local networks: app-network: From f0db53eab8c9c06178896a734740dc4f235d9359 Mon Sep 17 00:00:00 2001 From: Theouche Date: Tue, 10 Sep 2024 15:13:35 +0200 Subject: [PATCH 2/3] should work --- pong/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pong/settings.py b/pong/settings.py index 446ec08..b44ccdf 100644 --- a/pong/settings.py +++ b/pong/settings.py @@ -136,7 +136,7 @@ CHANNEL_LAYERS = { }, } -'''LOGGING = { +LOGGING = { 'version': 1, # The version of the logging configuration schema 'disable_existing_loggers': False, # Allows existing loggers to keep logging 'formatters': { # Defines how log messages will be formatted @@ -169,4 +169,4 @@ CHANNEL_LAYERS = { 'propagate': True, # If True, messages will be passed to the parent loggers as well }, }, -}''' +} From 4165b6985e1ae276c43cafcf9a2ac8c5580b646f Mon Sep 17 00:00:00 2001 From: Theouche Date: Tue, 10 Sep 2024 15:15:00 +0200 Subject: [PATCH 3/3] remis a jour --- .gitignore | 6 ------ logs/django.log | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 logs/django.log diff --git a/.gitignore b/.gitignore index acddfd3..5500a2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,3 @@ venv/ __pycache__/ -data/ .env -makefile -docker-compose.old.yml -docker-compose.yml -logs/django.log -pong/settings.py \ No newline at end of file diff --git a/logs/django.log b/logs/django.log new file mode 100644 index 0000000..39a3693 --- /dev/null +++ b/logs/django.log @@ -0,0 +1,8 @@ +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""} +{"message": "Not Found: /favicon.ico", "taskName": null, "status_code": 404, "request": ""}