From 76173530dcacc33725590a7c6d8862fac5466dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dybiec?= Date: Wed, 17 Apr 2019 17:48:49 +0200 Subject: Change docker compose dir --- compose/app/Dockerfile | 5 + compose/app/app.py | 29 +++++ compose/app/requirements.txt | 2 + compose/es/Dockerfile | 5 + compose/es/docker-compose.yml | 13 ++ compose/es/kibana.yml | 5 + compose/monitoring/prometheus/prometheus.yml | 40 ++++++ compose/nginx/Dockerfile | 4 + compose/nginx/conf.d/dybiec.info.conf | 168 ++++++++++++++++++++++++++ compose/nginx/nginx.conf | 31 +++++ compose/nginx/static-html/index.html | 1 + composer/app/Dockerfile | 5 - composer/app/app.py | 29 ----- composer/app/requirements.txt | 2 - composer/es/Dockerfile | 5 - composer/es/docker-compose.yml | 13 -- composer/es/kibana.yml | 5 - composer/monitoring/prometheus/prometheus.yml | 40 ------ composer/nginx/Dockerfile | 4 - composer/nginx/conf.d/dybiec.info.conf | 168 -------------------------- composer/nginx/nginx.conf | 31 ----- composer/nginx/static-html/index.html | 1 - docker.yml | 6 +- 23 files changed, 306 insertions(+), 306 deletions(-) create mode 100644 compose/app/Dockerfile create mode 100644 compose/app/app.py create mode 100644 compose/app/requirements.txt create mode 100644 compose/es/Dockerfile create mode 100644 compose/es/docker-compose.yml create mode 100644 compose/es/kibana.yml create mode 100644 compose/monitoring/prometheus/prometheus.yml create mode 100644 compose/nginx/Dockerfile create mode 100644 compose/nginx/conf.d/dybiec.info.conf create mode 100644 compose/nginx/nginx.conf create mode 100644 compose/nginx/static-html/index.html delete mode 100644 composer/app/Dockerfile delete mode 100644 composer/app/app.py delete mode 100644 composer/app/requirements.txt delete mode 100644 composer/es/Dockerfile delete mode 100644 composer/es/docker-compose.yml delete mode 100644 composer/es/kibana.yml delete mode 100644 composer/monitoring/prometheus/prometheus.yml delete mode 100644 composer/nginx/Dockerfile delete mode 100644 composer/nginx/conf.d/dybiec.info.conf delete mode 100644 composer/nginx/nginx.conf delete mode 100644 composer/nginx/static-html/index.html diff --git a/compose/app/Dockerfile b/compose/app/Dockerfile new file mode 100644 index 0000000..8e67d74 --- /dev/null +++ b/compose/app/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +RUN pip install -r requirements.txt +CMD ["python", "app.py"] diff --git a/compose/app/app.py b/compose/app/app.py new file mode 100644 index 0000000..9bf5d90 --- /dev/null +++ b/compose/app/app.py @@ -0,0 +1,29 @@ +import time + +import redis +from flask import Flask + + +app = Flask(__name__) +cache = redis.Redis(host='redis', port=6379) + + +def get_hit_count(): + retries = 5 + while True: + try: + return cache.incr('hits') + except redis.exceptions.ConnectionError as exc: + if retries == 0: + raise exc + retries -= 1 + time.sleep(0.5) + + +@app.route('/') +def hello(): + count = get_hit_count() + return 'Hello from this site! I have been seen {} times.\n'.format(count) + +if __name__ == "__main__": + app.run(host="0.0.0.0", debug=True) diff --git a/compose/app/requirements.txt b/compose/app/requirements.txt new file mode 100644 index 0000000..1a5dc97 --- /dev/null +++ b/compose/app/requirements.txt @@ -0,0 +1,2 @@ +flask +redis diff --git a/compose/es/Dockerfile b/compose/es/Dockerfile new file mode 100644 index 0000000..8e67d74 --- /dev/null +++ b/compose/es/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.4-alpine +ADD . /code +WORKDIR /code +RUN pip install -r requirements.txt +CMD ["python", "app.py"] diff --git a/compose/es/docker-compose.yml b/compose/es/docker-compose.yml new file mode 100644 index 0000000..3edf4c0 --- /dev/null +++ b/compose/es/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3' +services: + elasticsearch: + image: "docker.elastic.co/elasticsearch/elasticsearch:6.3.1" + environment: + - "discovery.type=single-node" + #ports: + # - "9200:9200" + # - "9300:9300" + kibana: + image: "docker.elastic.co/kibana/kibana:6.3.1" + ports: + - "5601:5601" diff --git a/compose/es/kibana.yml b/compose/es/kibana.yml new file mode 100644 index 0000000..59691ca --- /dev/null +++ b/compose/es/kibana.yml @@ -0,0 +1,5 @@ +server.name: kibana +server.host: "0" +elasticsearch.url: http://elasticsearch:9200 +xpack.monitoring.ui.container.elasticsearch.enabled: true +xpack.monitoring.enabled: true diff --git a/compose/monitoring/prometheus/prometheus.yml b/compose/monitoring/prometheus/prometheus.yml new file mode 100644 index 0000000..2903091 --- /dev/null +++ b/compose/monitoring/prometheus/prometheus.yml @@ -0,0 +1,40 @@ +# my global config +global: + scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + # scrape_timeout is set to the global default (10s). + + # Attach these labels to any time series or alerts when communicating with + # external systems (federation, remote storage, Alertmanager). + external_labels: + monitor: 'codelab-monitor' + +# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. +rule_files: + # - "first.rules" + # - "second.rules" + +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + # The job name is added as a label `job=` to any timeseries scraped from this config. + - job_name: 'prometheus' + + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + + static_configs: + - targets: ['localhost:9090'] + + - job_name: 'docker' + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + + static_configs: + - targets: ['dockerhost:9323'] + - job_name: 'cadvisor' + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + + static_configs: + - targets: ['cadvisor:8080'] diff --git a/compose/nginx/Dockerfile b/compose/nginx/Dockerfile new file mode 100644 index 0000000..fcca1df --- /dev/null +++ b/compose/nginx/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:1.15.8-alpine +COPY static-html /usr/share/nginx/html +COPY conf.d /etc/nginx/conf.d +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/compose/nginx/conf.d/dybiec.info.conf b/compose/nginx/conf.d/dybiec.info.conf new file mode 100644 index 0000000..90cd471 --- /dev/null +++ b/compose/nginx/conf.d/dybiec.info.conf @@ -0,0 +1,168 @@ +server { + listen 80; + listen 443 ssl; + server_name .dybiec.info; + + ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; + + location / { + root /usr/share/nginx/html; + index index.html; + } + +} +server { + listen 80; + listen 443 ssl; + server_name cnt.dybiec.info; + + ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; + + location / { + proxy_pass http://localhost:5004; + } +} +server { + listen 80; + listen 443 ssl; + server_name registry.dybiec.info; + + ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; + + location / { + proxy_pass http://localhost:5000; + proxy_set_header Host $http_host; # required for docker client's sake + proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + client_max_body_size 0; + } +} +server { + listen 80; + server_name git.dybiec.info; + return 301 https://$server_name$request_uri; +} +server { + listen 443 ssl; + server_name git.dybiec.info; + + ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; + + location / { + proxy_pass http://localhost:5001; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_http_version 1.1; + } + gzip_proxied any; + gzip_types + text/css + text/javascript + text/xml + text/plain + application/javascript + application/x-javascript + application/json; + +} +server { + listen 80; + server_name grafana.dybiec.info; + return 301 https://$server_name$request_uri; +} +server { + listen 443 ssl; + server_name grafana.dybiec.info; + + ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; + + location / { + proxy_pass http://localhost:5002; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_http_version 1.1; + } + gzip_proxied any; + gzip_types + text/css + text/javascript + text/xml + text/plain + application/javascript + application/x-javascript + application/json; + +} +server { + listen 80; + server_name prometheus.dybiec.info; + return 301 https://$server_name$request_uri; +} +server { + listen 443 ssl; + server_name prometheus.dybiec.info; + + ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; + + location / { + proxy_pass http://localhost:5003; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_http_version 1.1; + } + gzip_proxied any; + gzip_types + text/css + text/javascript + text/xml + text/plain + application/javascript + application/x-javascript + application/json; + +} +server { + listen 80; + server_name octoprint.dybiec.info; + return 301 https://$server_name$request_uri; +} +server { + listen 443 ssl; + server_name octoprint.dybiec.info; + + ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; + + location / { + proxy_pass http://192.168.255.6/; + proxy_redirect off; + proxy_http_version 1.1; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + + client_max_body_size 0; + } + gzip_proxied any; + gzip_types + text/css + text/javascript + text/xml + text/plain + application/javascript + application/x-javascript + application/json; + +} diff --git a/compose/nginx/nginx.conf b/compose/nginx/nginx.conf new file mode 100644 index 0000000..aa6cbd7 --- /dev/null +++ b/compose/nginx/nginx.conf @@ -0,0 +1,31 @@ +user nginx; +worker_processes 1; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + + keepalive_timeout 65; + + gzip on; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/compose/nginx/static-html/index.html b/compose/nginx/static-html/index.html new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/compose/nginx/static-html/index.html @@ -0,0 +1 @@ +hello diff --git a/composer/app/Dockerfile b/composer/app/Dockerfile deleted file mode 100644 index 8e67d74..0000000 --- a/composer/app/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM python:3.4-alpine -ADD . /code -WORKDIR /code -RUN pip install -r requirements.txt -CMD ["python", "app.py"] diff --git a/composer/app/app.py b/composer/app/app.py deleted file mode 100644 index 9bf5d90..0000000 --- a/composer/app/app.py +++ /dev/null @@ -1,29 +0,0 @@ -import time - -import redis -from flask import Flask - - -app = Flask(__name__) -cache = redis.Redis(host='redis', port=6379) - - -def get_hit_count(): - retries = 5 - while True: - try: - return cache.incr('hits') - except redis.exceptions.ConnectionError as exc: - if retries == 0: - raise exc - retries -= 1 - time.sleep(0.5) - - -@app.route('/') -def hello(): - count = get_hit_count() - return 'Hello from this site! I have been seen {} times.\n'.format(count) - -if __name__ == "__main__": - app.run(host="0.0.0.0", debug=True) diff --git a/composer/app/requirements.txt b/composer/app/requirements.txt deleted file mode 100644 index 1a5dc97..0000000 --- a/composer/app/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -flask -redis diff --git a/composer/es/Dockerfile b/composer/es/Dockerfile deleted file mode 100644 index 8e67d74..0000000 --- a/composer/es/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM python:3.4-alpine -ADD . /code -WORKDIR /code -RUN pip install -r requirements.txt -CMD ["python", "app.py"] diff --git a/composer/es/docker-compose.yml b/composer/es/docker-compose.yml deleted file mode 100644 index 3edf4c0..0000000 --- a/composer/es/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '3' -services: - elasticsearch: - image: "docker.elastic.co/elasticsearch/elasticsearch:6.3.1" - environment: - - "discovery.type=single-node" - #ports: - # - "9200:9200" - # - "9300:9300" - kibana: - image: "docker.elastic.co/kibana/kibana:6.3.1" - ports: - - "5601:5601" diff --git a/composer/es/kibana.yml b/composer/es/kibana.yml deleted file mode 100644 index 59691ca..0000000 --- a/composer/es/kibana.yml +++ /dev/null @@ -1,5 +0,0 @@ -server.name: kibana -server.host: "0" -elasticsearch.url: http://elasticsearch:9200 -xpack.monitoring.ui.container.elasticsearch.enabled: true -xpack.monitoring.enabled: true diff --git a/composer/monitoring/prometheus/prometheus.yml b/composer/monitoring/prometheus/prometheus.yml deleted file mode 100644 index 2903091..0000000 --- a/composer/monitoring/prometheus/prometheus.yml +++ /dev/null @@ -1,40 +0,0 @@ -# my global config -global: - scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. - evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. - # scrape_timeout is set to the global default (10s). - - # Attach these labels to any time series or alerts when communicating with - # external systems (federation, remote storage, Alertmanager). - external_labels: - monitor: 'codelab-monitor' - -# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. -rule_files: - # - "first.rules" - # - "second.rules" - -# A scrape configuration containing exactly one endpoint to scrape: -# Here it's Prometheus itself. -scrape_configs: - # The job name is added as a label `job=` to any timeseries scraped from this config. - - job_name: 'prometheus' - - # metrics_path defaults to '/metrics' - # scheme defaults to 'http'. - - static_configs: - - targets: ['localhost:9090'] - - - job_name: 'docker' - # metrics_path defaults to '/metrics' - # scheme defaults to 'http'. - - static_configs: - - targets: ['dockerhost:9323'] - - job_name: 'cadvisor' - # metrics_path defaults to '/metrics' - # scheme defaults to 'http'. - - static_configs: - - targets: ['cadvisor:8080'] diff --git a/composer/nginx/Dockerfile b/composer/nginx/Dockerfile deleted file mode 100644 index fcca1df..0000000 --- a/composer/nginx/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM nginx:1.15.8-alpine -COPY static-html /usr/share/nginx/html -COPY conf.d /etc/nginx/conf.d -COPY nginx.conf /etc/nginx/nginx.conf diff --git a/composer/nginx/conf.d/dybiec.info.conf b/composer/nginx/conf.d/dybiec.info.conf deleted file mode 100644 index 90cd471..0000000 --- a/composer/nginx/conf.d/dybiec.info.conf +++ /dev/null @@ -1,168 +0,0 @@ -server { - listen 80; - listen 443 ssl; - server_name .dybiec.info; - - ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; - - location / { - root /usr/share/nginx/html; - index index.html; - } - -} -server { - listen 80; - listen 443 ssl; - server_name cnt.dybiec.info; - - ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; - - location / { - proxy_pass http://localhost:5004; - } -} -server { - listen 80; - listen 443 ssl; - server_name registry.dybiec.info; - - ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; - - location / { - proxy_pass http://localhost:5000; - proxy_set_header Host $http_host; # required for docker client's sake - proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - client_max_body_size 0; - } -} -server { - listen 80; - server_name git.dybiec.info; - return 301 https://$server_name$request_uri; -} -server { - listen 443 ssl; - server_name git.dybiec.info; - - ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; - - location / { - proxy_pass http://localhost:5001; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_http_version 1.1; - } - gzip_proxied any; - gzip_types - text/css - text/javascript - text/xml - text/plain - application/javascript - application/x-javascript - application/json; - -} -server { - listen 80; - server_name grafana.dybiec.info; - return 301 https://$server_name$request_uri; -} -server { - listen 443 ssl; - server_name grafana.dybiec.info; - - ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; - - location / { - proxy_pass http://localhost:5002; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_http_version 1.1; - } - gzip_proxied any; - gzip_types - text/css - text/javascript - text/xml - text/plain - application/javascript - application/x-javascript - application/json; - -} -server { - listen 80; - server_name prometheus.dybiec.info; - return 301 https://$server_name$request_uri; -} -server { - listen 443 ssl; - server_name prometheus.dybiec.info; - - ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; - - location / { - proxy_pass http://localhost:5003; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_redirect off; - proxy_http_version 1.1; - } - gzip_proxied any; - gzip_types - text/css - text/javascript - text/xml - text/plain - application/javascript - application/x-javascript - application/json; - -} -server { - listen 80; - server_name octoprint.dybiec.info; - return 301 https://$server_name$request_uri; -} -server { - listen 443 ssl; - server_name octoprint.dybiec.info; - - ssl_certificate /etc/letsencrypt/live/dybiec.info/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/dybiec.info/privkey.pem; - - location / { - proxy_pass http://192.168.255.6/; - proxy_redirect off; - proxy_http_version 1.1; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - - client_max_body_size 0; - } - gzip_proxied any; - gzip_types - text/css - text/javascript - text/xml - text/plain - application/javascript - application/x-javascript - application/json; - -} diff --git a/composer/nginx/nginx.conf b/composer/nginx/nginx.conf deleted file mode 100644 index aa6cbd7..0000000 --- a/composer/nginx/nginx.conf +++ /dev/null @@ -1,31 +0,0 @@ -user nginx; -worker_processes 1; - -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - tcp_nopush on; - - keepalive_timeout 65; - - gzip on; - - include /etc/nginx/conf.d/*.conf; -} diff --git a/composer/nginx/static-html/index.html b/composer/nginx/static-html/index.html deleted file mode 100644 index ce01362..0000000 --- a/composer/nginx/static-html/index.html +++ /dev/null @@ -1 +0,0 @@ -hello diff --git a/docker.yml b/docker.yml index 7ae8f9f..cd86979 100644 --- a/docker.yml +++ b/docker.yml @@ -3,12 +3,12 @@ hosts: tamriel remote_user: ansible_worker vars: - docker_compose_dir: "~/composer" + docker_compose_dir: "~/compose" tasks: - name: Synchronize docker-compose files synchronize: - src: composer/ - dest: composer + src: compose/ + dest: "{{docker_compose_dir}}" - name: Counter app docker_service: project_name: app -- cgit v1.2.3