From 5167fe56df52b0cfc5c063a370a9563a0b4f6745 Mon Sep 17 00:00:00 2001 From: Pablo Hinojosa Date: Tue, 14 Mar 2023 15:11:17 +0100 Subject: [PATCH] Add docker compose Add instructions and files to run SortingHat using docker compose Signed-off-by: Pablo Hinojosa --- docker/README.md | 16 ++++++++ docker/docker-compose.yml | 86 +++++++++++++++++++++++++++++++++++++++ docker/nginx/nginx.conf | 35 ++++++++++++++++ docker/nginx/uwsgi_params | 13 ++++++ 4 files changed, 150 insertions(+) create mode 100644 docker/docker-compose.yml create mode 100644 docker/nginx/nginx.conf create mode 100644 docker/nginx/uwsgi_params diff --git a/docker/README.md b/docker/README.md index 0ff2ad08f..42bf85d31 100644 --- a/docker/README.md +++ b/docker/README.md @@ -11,6 +11,22 @@ our [website](https://chaoss.github.io/grimoirelab/). ### Quickstart +It is recommended to use [docker compose](https://docs.docker.com/compose/install/linux/) to create your SortingHat environment, but you can create it with docker commands too. + +#### Docker compose (recommended) + +To run a standalone SortingHat instance, you need git and docker compose to run the following commands: + +``` +git clone git@github.com:chaoss/grimoirelab-sortinghat.git +cd grimoirelab-sortinghat/docker +docker compose up +``` + +Then go to [localhost:8000](http://localhost:8000) and login with username and password `admin`. + +#### Docker + These commands will start a SortingHat server container in developer mode with a MySQL and Redis server containers. The service will run on an HTTP server on `localhost:8000`. You can access it with credentials `admin:admin`. diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 000000000..57a51f07d --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,86 @@ +version: '2.2' + +services: + mariadb: + image: mariadb:10.6 + ports: + - "3306:3306" + environment: + - MYSQL_ROOT_PASSWORD= + - MYSQL_ALLOW_EMPTY_PASSWORD=yes + healthcheck: + test: [ "CMD", "/usr/local/bin/healthcheck.sh", "--su=root", "--connect", "--innodb_initialized" ] + retries: 5 + volumes: + - mariadb_db:/var/lib/mysql + + + redis: + image: redis:latest + ports: + - "6379:6379" + healthcheck: + test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ] + retries: 5 + + sortinghat: + restart: on-failure:3 + image: grimoirelab/sortinghat + environment: + - SORTINGHAT_SECRET_KEY=secret + - SORTINGHAT_DB_HOST=mariadb + - SORTINGHAT_DB_PORT=3306 + - SORTINGHAT_DB_DATABASE=sortinghat_test + - SORTINGHAT_DB_USER=root + - SORTINGHAT_DB_PASSWORD= + - SORTINGHAT_REDIS_HOST=redis + - SORTINGHAT_REDIS_PASSWORD= + - SORTINGHAT_SUPERUSER_USERNAME=admin + - SORTINGHAT_SUPERUSER_PASSWORD=admin + - SORTINGHAT_ALLOWED_HOST=sortinghat,nginx,localhost,127.0.0.1,[::1] + - SORTINGHAT_CORS_ALLOWED_ORIGINS=http://localhost:8000,http://127.0.0.1:8000 + expose: + - "9314" + volumes: + - sortinghat-static:/opt/venv/lib/python3.9/site-packages/sortinghat/static/ + depends_on: + mariadb: + condition: service_healthy + redis: + condition: service_healthy + + sortinghat_worker: + image: grimoirelab/sortinghat-worker + environment: + - SORTINGHAT_SECRET_KEY=secret + - SORTINGHAT_DB_HOST=mariadb + - SORTINGHAT_DB_PORT=3306 + - SORTINGHAT_DB_DATABASE=sortinghat_test + - SORTINGHAT_DB_USER=root + - SORTINGHAT_DB_PASSWORD= + - SORTINGHAT_REDIS_HOST=redis + - SORTINGHAT_REDIS_PASSWORD= + depends_on: + mariadb: + condition: service_healthy + redis: + condition: service_healthy + + nginx: + restart: on-failure:3 + image: nginx:latest + volumes: + - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf + - ./nginx/uwsgi_params:/etc/nginx/uwsgi_params + - sortinghat-static:/sortinghat:ro + ports: + - "8000:8000" + depends_on: + - sortinghat + healthcheck: + test: "curl -s --head http://localhost:8000/identities/api/ | grep Set-Cookie || exit 1" + retries: 5 + +volumes: + sortinghat-static: + mariadb_db: diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 000000000..0b6df6e7a --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,35 @@ +upstream sortinghat { + server sortinghat:9314; +} +server { + include mime.types; + sendfile on; + listen 8000; + + server_name localhost nginx; + + location / { + return 302 /identities; + } + + location /identities { + rewrite ^/identities/(.*) /$1 break; + sub_filter + ''; + sub_filter_once on; + + include /etc/nginx/uwsgi_params; + uwsgi_pass sortinghat; + uwsgi_param Host $host; + uwsgi_param X-Real-IP $remote_addr; + uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for; + uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto; + } + + location ~ ^/identities/(css|js|fonts)/ { + rewrite ^/identities/(.*) /$1 break; + + root /sortinghat; + } +} + diff --git a/docker/nginx/uwsgi_params b/docker/nginx/uwsgi_params new file mode 100644 index 000000000..1eab45ff8 --- /dev/null +++ b/docker/nginx/uwsgi_params @@ -0,0 +1,13 @@ +uwsgi_param QUERY_STRING $query_string; +uwsgi_param REQUEST_METHOD $request_method; +uwsgi_param CONTENT_TYPE $content_type; +uwsgi_param CONTENT_LENGTH $content_length; +uwsgi_param REQUEST_URI $request_uri; +uwsgi_param PATH_INFO $document_uri; +uwsgi_param DOCUMENT_ROOT $document_root; +uwsgi_param SERVER_PROTOCOL $server_protocol; +uwsgi_param HTTPS $https if_not_empty; +uwsgi_param REMOTE_ADDR $remote_addr; +uwsgi_param REMOTE_PORT $remote_port; +uwsgi_param SERVER_PORT $server_port; +uwsgi_param SERVER_NAME $server_name;