You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by tu...@apache.org on 2020/10/23 12:22:38 UTC
[kibble] branch master updated: Add dev docker compose (#50)
This is an automated email from the ASF dual-hosted git repository.
turbaszek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble.git
The following commit(s) were added to refs/heads/master by this push:
new 7092e86 Add dev docker compose (#50)
7092e86 is described below
commit 7092e8685982f701d26e9b737659647c6cb1c606
Author: Tomek Urbaszek <tu...@gmail.com>
AuthorDate: Fri Oct 23 14:22:30 2020 +0200
Add dev docker compose (#50)
---
CONTRIBUTING.md | 25 +++++++++++++++++--
Dockerfile.dev | 31 ++++++++++++++++++++++++
docker-compose-dev.yaml | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
nginx-dev.conf | 34 ++++++++++++++++++++++++++
setup/requirements.txt | 14 ++++++-----
setup/setup.py | 35 ++++++++++++++++-----------
6 files changed, 181 insertions(+), 22 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2c3351a..b3ef0dd 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -15,8 +15,29 @@ We also have:
## Development installation
-This project requires Python in higher version than 3.4.
-More information will come soon!
+The easiest option to spin up a development environment is to use our development docker-compose.
+The development image has mounted all Kibble sources so all your local code changes will be automatically
+reflected in the running app.
+
+First you need to configure the Elasticsearch node:
+```
+docker-compose -f docker-compose-dev.yaml up setup
+```
+Once you see the
+```
+setup_1 | All done, Kibble should...work now :)
+```
+Now you can can launch Apache Kibble ui:
+```
+docker-compose -f docker-compose-dev.yaml up ui
+```
+The ui should be available under `http://0.0.0.0:8000` or `http://localhost:8000`. To log in you can use
+the dummy admin account `admin@kibble` and password `kibbleAdmin`.
+
+You can also start only the API server:
+```
+docker-compose -f docker-compose-dev.yaml up kibble
+```
## Code Quality
diff --git a/Dockerfile.dev b/Dockerfile.dev
new file mode 100644
index 0000000..ab76414
--- /dev/null
+++ b/Dockerfile.dev
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+FROM python:3.6
+
+USER root
+RUN apt-get update
+RUN apt-get install -y gcc unzip
+
+COPY ./api /kibble/api/
+COPY ./setup /kibble/setup/
+COPY ./ui /kibble/ui/
+
+RUN pip install --upgrade pip
+RUN pip install -r /kibble/setup/requirements.txt
+
+WORKDIR /kibble
diff --git a/docker-compose-dev.yaml b/docker-compose-dev.yaml
new file mode 100644
index 0000000..bb7f1d2
--- /dev/null
+++ b/docker-compose-dev.yaml
@@ -0,0 +1,64 @@
+version: '3'
+
+services:
+ # Helper service to setup the Apache Kibble es node
+ setup:
+ image: &img apache/kibble
+ build:
+ context: .
+ dockerfile: Dockerfile.dev
+ command: bash -c "python setup/setup.py -e elasticsearch -a -k"
+ volumes:
+ - ./setup/:/kibble/setup/
+ depends_on:
+ - elasticsearch
+
+ # Apache Kibble API server
+ kibble:
+ image: *img
+ command: bash -c "cd api && gunicorn --reload -w 1 -b 0.0.0.0:8001 handler:application"
+ expose:
+ - 8001
+ ports:
+ - 8001:8001
+ volumes:
+ - ./api/:/kibble/api/
+ - ./setup/:/kibble/setup/
+ - ./ui/:/kibble/ui/
+ depends_on:
+ - elasticsearch
+
+ # Apache Kibble web ui server
+ ui:
+ image: nginx:latest
+ volumes:
+ - ./nginx-dev.conf:/etc/nginx/nginx.conf
+ - ./ui/:/kibble/ui/
+ ports:
+ - 8000:8000
+ depends_on:
+ - kibble
+
+ # Elasticsearch node required as a database for Apache Kibble
+ elasticsearch:
+ image: elasticsearch:7.9.2
+ ports:
+ - "9200:9200"
+ - "9300:9300"
+ environment:
+ node.name: es01
+ discovery.seed_hosts: es02
+ cluster.initial_master_nodes: es01
+ cluster.name: traefik-tutorial-cluster
+ bootstrap.memory_lock: "true"
+ ES_JAVA_OPTS: -Xms256m -Xmx256m
+ volumes:
+ - "kibble-es-data:/usr/share/elasticsearch/data"
+ ulimits:
+ memlock:
+ soft: -1
+ hard: -1
+
+volumes:
+ # named volumes can be managed easier using docker-compose
+ kibble-es-data:
diff --git a/nginx-dev.conf b/nginx-dev.conf
new file mode 100644
index 0000000..22270d3
--- /dev/null
+++ b/nginx-dev.conf
@@ -0,0 +1,34 @@
+events {}
+http {
+ server {
+ listen 8000;
+
+ server_name kibble;
+
+ access_log /var/log/nginx/kibble_access.log;
+ error_log /var/log/nginx/kibble_error.log;
+
+ proxy_set_header Host $http_host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-Port $server_port;
+ proxy_set_header X-Forwarded-Proto $scheme;
+
+ root /kibble/ui;
+ index index.html;
+
+ location / {
+ try_files $uri $uri/ =404;
+ }
+
+ location ~ /css {
+ add_header Content-Type text/css;
+ }
+
+ # Reverse proxy to Apache Kibble API
+ location /api {
+ proxy_pass http://kibble:8001;
+ rewrite ^/api(.*)/$ $1 break;
+ }
+ }
+}
diff --git a/setup/requirements.txt b/setup/requirements.txt
index 24b3bca..6a2d1f3 100644
--- a/setup/requirements.txt
+++ b/setup/requirements.txt
@@ -1,6 +1,8 @@
-certifi
-pyyaml
-bcrypt
-elasticsearch
-pre-commit
-python-dateutil
+bcrypt==3.2.0
+certifi==2020.6.20
+elasticsearch==7.9.1
+gunicorn==20.0.4
+pre-commit==2.7.1
+python-dateutil==2.8.1
+PyYAML==5.3.1
+tenacity==6.2.0
diff --git a/setup/setup.py b/setup/setup.py
index 19b2089..689a297 100644
--- a/setup/setup.py
+++ b/setup/setup.py
@@ -23,6 +23,7 @@ import argparse
import logging
from getpass import getpass
+import tenacity
import yaml
import bcrypt
import json
@@ -312,20 +313,26 @@ def main():
admin_pass = get_user_input("Enter a password for the administrator account:", secure=True)
# Create Elasticsearch index
- try:
- create_es_index(
- hostname=args.hostname,
- port=int(args.port),
- dbname=args.dbname,
- shards=int(args.shards),
- replicas=int(args.replicas),
- admin_name=admin_name,
- admin_pass=admin_pass,
- skiponexist=args.skiponexist,
- )
- except Exception as e:
- print("Index creation failed: %s" % e)
- sys.exit(1)
+ # Retry in case ES is not yet up
+ print(f"Elasticsearch: {args.hostname}:{args.port}")
+ for attempt in tenacity.Retrying(
+ retry=tenacity.retry_if_exception_type(exception_types=Exception),
+ wait=tenacity.wait_fixed(10),
+ stop=tenacity.stop_after_attempt(10),
+ reraise=True
+ ):
+ with attempt:
+ print("Trying to create ES index...")
+ create_es_index(
+ hostname=args.hostname,
+ port=int(args.port),
+ dbname=args.dbname,
+ shards=int(args.shards),
+ replicas=int(args.replicas),
+ admin_name=admin_name,
+ admin_pass=admin_pass,
+ skiponexist=args.skiponexist,
+ )
print()
# Create Kibble configuration file