From 50b7121f720ab8519e6e686ae7eabaa6f2e49198 Mon Sep 17 00:00:00 2001 From: "yuliya.ivaniukovich" Date: Tue, 14 Apr 2020 14:03:31 +0300 Subject: [PATCH 1/2] Move docker configs to `.docker` folder similarly to `.github` workflows --- {docker => .docker}/.env | 5 +-- {docker => .docker}/api-gateway/Dockerfile | 0 .../api-gateway/conf.d/default.conf | 4 +- .../api-gateway/conf.d/dev.conf | 0 .../docker-compose.override.yml | 2 +- {docker => .docker}/docker-compose.yml | 38 +++++++++++-------- .../localstorage-db}/Dockerfile | 0 .../localstorage-db}/createdb.sql | 0 README.md | 6 +-- docker/rabbitmq/Dockerfile | 2 - 10 files changed, 30 insertions(+), 27 deletions(-) rename {docker => .docker}/.env (75%) rename {docker => .docker}/api-gateway/Dockerfile (100%) rename {docker => .docker}/api-gateway/conf.d/default.conf (82%) rename {docker => .docker}/api-gateway/conf.d/dev.conf (100%) rename {docker => .docker}/docker-compose.override.yml (87%) rename {docker => .docker}/docker-compose.yml (63%) rename {docker/database => .docker/localstorage-db}/Dockerfile (100%) rename {docker/database => .docker/localstorage-db}/createdb.sql (100%) delete mode 100644 docker/rabbitmq/Dockerfile diff --git a/docker/.env b/.docker/.env similarity index 75% rename from docker/.env rename to .docker/.env index 63a578c4..933ca31e 100644 --- a/docker/.env +++ b/.docker/.env @@ -6,7 +6,6 @@ PROFILE=default # Local storage service environment variables LOCAL_STORAGE_SERVICE_DATABASE_USER=admin LOCAL_STORAGE_SERVICE_DATABASE_PASSWORD=admin -LOCAL_STORAGE_SERVICE_DISK_MIN_SPACE_THRESHOLD=5GB -RABBITMQ_DEFAULT_USER=admin -RABBITMQ_DEFAULT_PASSWORD=admin +AMQP_SERVER_USER=admin +AMQP_SERVER_PASSWORD=admin diff --git a/docker/api-gateway/Dockerfile b/.docker/api-gateway/Dockerfile similarity index 100% rename from docker/api-gateway/Dockerfile rename to .docker/api-gateway/Dockerfile diff --git a/docker/api-gateway/conf.d/default.conf b/.docker/api-gateway/conf.d/default.conf similarity index 82% rename from docker/api-gateway/conf.d/default.conf rename to .docker/api-gateway/conf.d/default.conf index 0698a38b..1a74c674 100644 --- a/docker/api-gateway/conf.d/default.conf +++ b/.docker/api-gateway/conf.d/default.conf @@ -6,13 +6,13 @@ server { client_body_timeout 30s; location /api/files { - proxy_pass http://local-storage-service:8080/api/files; + proxy_pass http://file-storage:8080/api/files; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } location /api/status/file-storage { - proxy_pass http://local-storage-service:8080/api/status; + proxy_pass http://file-storage:8080/api/status; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; } diff --git a/docker/api-gateway/conf.d/dev.conf b/.docker/api-gateway/conf.d/dev.conf similarity index 100% rename from docker/api-gateway/conf.d/dev.conf rename to .docker/api-gateway/conf.d/dev.conf diff --git a/docker/docker-compose.override.yml b/.docker/docker-compose.override.yml similarity index 87% rename from docker/docker-compose.override.yml rename to .docker/docker-compose.override.yml index a5d1dd89..3aacd474 100644 --- a/docker/docker-compose.override.yml +++ b/.docker/docker-compose.override.yml @@ -9,5 +9,5 @@ services: ports: - 80:80 depends_on: - - local-storage-service + - file-storage - job-service diff --git a/docker/docker-compose.yml b/.docker/docker-compose.yml similarity index 63% rename from docker/docker-compose.yml rename to .docker/docker-compose.yml index b43d830a..a1ff014b 100644 --- a/docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -1,54 +1,60 @@ version: '3.4' services: - local-storage-service-database: - build: ./database - restart: always + # File Storage + local-storage-database: + build: ./localstorage-db environment: POSTGRES_USER: ${LOCAL_STORAGE_SERVICE_DATABASE_USER} POSTGRES_PASSWORD: ${LOCAL_STORAGE_SERVICE_DATABASE_PASSWORD} POSTGRES_DB: verapdfdb volumes: - type: volume - source: filestorage_database_data + source: localstorage_database_data target: /var/lib/postgresql/data - local-storage-service: + restart: always + file-storage: build: ../local-storage-service/server expose: - 8080 depends_on: - - local-storage-service-database + - local-storage-database environment: LOCALSTORAGE_DATABASE_USERNAME: ${LOCAL_STORAGE_SERVICE_DATABASE_USER} LOCALSTORAGE_DATABASE_PASSWORD: ${LOCAL_STORAGE_SERVICE_DATABASE_PASSWORD} - LOCALSTORAGE_DATABASE_DB: verapdfdb # the same as in local-storage-service-database - LOCALSTORAGE_DATABASE_HOST: local-storage-service-database + LOCALSTORAGE_DATABASE_DB: verapdfdb # the same as in file-storage-database + LOCALSTORAGE_DATABASE_HOST: local-storage-database LOCALSTORAGE_DATABASE_PORT: 5432 - LOCALSTORAGE_DISK_MIN_SPACE_THRESHOLD: ${LOCAL_STORAGE_SERVICE_DISK_MIN_SPACE_THRESHOLD} + LOCALSTORAGE_DISK_MIN_SPACE_THRESHOLD: ${LOCAL_STORAGE_SERVICE_DISK_MIN_SPACE_THRESHOLD:-5GB} LOCALSTORAGE_MAX_FILE_SIZE: 100MB LOCALSTORAGE_MAX_REQUEST_SIZE: 101MB volumes: - type: volume - source: filestorage_server_files + source: localstorage_server_files target: /opt/verapdf/localstorageservice/files restart: always + + # Job Service job-service: build: ../job-service/server expose: - 8080 restart: always - rabbitmq: - build: ./rabbitmq + # Validation tasks queue + queue: + image: rabbitmq:3.8.3 + expose: + - 5672 restart: always environment: - RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER} - RABBITMQ_DEFAULT_PASSWORD: ${RABBITMQ_DEFAULT_PASSWORD} + RABBITMQ_DEFAULT_USER: ${AMQP_SERVER_USER} + RABBITMQ_DEFAULT_PASSWORD: ${AMQP_SERVER_PASSWORD} volumes: - type: volume source: rabbitmq_database_data target: /var/lib/rabbitmq/ volumes: - filestorage_database_data: - filestorage_server_files: + localstorage_database_data: + localstorage_server_files: rabbitmq_database_data: diff --git a/docker/database/Dockerfile b/.docker/localstorage-db/Dockerfile similarity index 100% rename from docker/database/Dockerfile rename to .docker/localstorage-db/Dockerfile diff --git a/docker/database/createdb.sql b/.docker/localstorage-db/createdb.sql similarity index 100% rename from docker/database/createdb.sql rename to .docker/localstorage-db/createdb.sql diff --git a/README.md b/README.md index 4b7943d5..12b322b0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ mvn clean install **Run service stack** ``` -cd ./docker +cd .docker docker-compose up -d ``` @@ -26,7 +26,7 @@ To check service availability you can request service status endpoints described **Stop service stack** ``` -cd ./docker +cd .docker docker-compose down ``` @@ -34,7 +34,7 @@ docker-compose down When working on new features it is useful to be able to launch individual services in your IDE directly. To use your local services you can start the stack with `PROFILE=dev` environment variable: ``` -cd ./docker +cd .docker env PROFILE=dev docker-compose up -d ``` This will launch the nginx proxy with alternative configuration pointing to your services instead of those from diff --git a/docker/rabbitmq/Dockerfile b/docker/rabbitmq/Dockerfile deleted file mode 100644 index 2388eaae..00000000 --- a/docker/rabbitmq/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM rabbitmq:3.8.3 -EXPOSE 5672 From 7f84f7513482157e0141b480db79ebe7501f185b Mon Sep 17 00:00:00 2001 From: "yuliya.ivaniukovich" Date: Tue, 14 Apr 2020 14:04:38 +0300 Subject: [PATCH 2/2] Add script to build project sources using maven docker container --- .bin/build-all.sh | 18 ++++++++++++++++++ .bin/init.sh | 3 +++ README.md | 8 ++++++++ 3 files changed, 29 insertions(+) create mode 100644 .bin/build-all.sh create mode 100644 .bin/init.sh diff --git a/.bin/build-all.sh b/.bin/build-all.sh new file mode 100644 index 00000000..3c3698ab --- /dev/null +++ b/.bin/build-all.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Workaround for running from Git Bash on Windows: +export MSYS_NO_PATHCONV=1 + +script_path=$(realpath "$0") +script_dir=$(dirname "$script_path") +project_root=$(dirname "$script_dir") + +work_dir="/usr/src/verapdf-webapp-server" + +# Build all project sources +docker run -it \ + --rm --name build-verapdf-webapp-server \ + -v maven-repo:/root/.m2 \ + -v "$project_root":$work_dir \ + -w $work_dir \ + maven:3.6-jdk-11 mvn clean package diff --git a/.bin/init.sh b/.bin/init.sh new file mode 100644 index 00000000..82db2cb3 --- /dev/null +++ b/.bin/init.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Create a volume to reuse downloaded maven dependencies +docker volume create --name maven-repo diff --git a/README.md b/README.md index 12b322b0..72ff9177 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,18 @@ JDK 11, Maven, Docker **Build sources** +You can use your local Maven installation to build project sources: ``` mvn clean install ``` +Alternatively you can use a docker maven image. +For that you need first initialize the volume to re-use maven repo between runs: +``` +.bin/init.sh +``` +After that you can use `.bin/build-all.sh` script to run actual building. + ## Running in Docker **Run service stack**