From 2186422003e8e29f8fa6553c81104c143dc9be68 Mon Sep 17 00:00:00 2001 From: David Humphrey Date: Fri, 12 Feb 2021 19:31:34 -0500 Subject: [PATCH] Move docker-compose files to root, add npm script, docs --- {src/api/config => config}/filebeat.yml | 0 ....yaml => docker-compose-api-production.yml | 5 +- docker-compose-api.yml | 41 ++++++++++++ docs/docker.md | 65 +++++++++++++++++++ package.json | 2 + 5 files changed, 111 insertions(+), 2 deletions(-) rename {src/api/config => config}/filebeat.yml (100%) rename src/api/docker-compose.yaml => docker-compose-api-production.yml (98%) create mode 100644 docker-compose-api.yml create mode 100644 docs/docker.md diff --git a/src/api/config/filebeat.yml b/config/filebeat.yml similarity index 100% rename from src/api/config/filebeat.yml rename to config/filebeat.yml diff --git a/src/api/docker-compose.yaml b/docker-compose-api-production.yml similarity index 98% rename from src/api/docker-compose.yaml rename to docker-compose-api-production.yml index 3819bcbff4..507c5dd539 100644 --- a/src/api/docker-compose.yaml +++ b/docker-compose-api-production.yml @@ -1,12 +1,12 @@ version: '3' services: + # API Gateway traefik: image: traefik:v2.4 container_name: 'traefik' restart: unless-stopped command: - - '--log.level=DEBUG' - '--api.insecure=true' - '--providers.docker=true' - '--providers.docker.exposedbydefault=true' @@ -142,9 +142,10 @@ services: container_name: 'image' restart: unless-stopped build: - context: ./image + context: ./src/api/image dockerfile: Dockerfile environment: + - NODE_ENV=production - IMAGE_PORT=4444 - SERVICE_NAME=image - ELASTICSEARCH_HOSTS=http://elasticsearch:9200 diff --git a/docker-compose-api.yml b/docker-compose-api.yml new file mode 100644 index 0000000000..f72c3f94f3 --- /dev/null +++ b/docker-compose-api.yml @@ -0,0 +1,41 @@ +version: '3' + +services: + # API Gateway + traefik: + image: traefik:v2.4 + container_name: 'traefik' + restart: unless-stopped + command: + - '--log.level=DEBUG' + - '--api.insecure=true' + - '--providers.docker=true' + - '--providers.docker.exposedbydefault=true' + - '--entrypoints.web.address=:80' + ports: + - '80:80' + - '8080:8080' + volumes: + - /var/run/docker.sock:/var/run/docker.sock + + # Micro Services + image-dev: + container_name: 'image' + restart: unless-stopped + build: + context: ./src/api/image + dockerfile: Dockerfile + environment: + - IMAGE_PORT=4444 + - SERVICE_NAME=image + depends_on: + traefik: + condition: service_started + ports: + - '4444' + labels: + # Traefik routing + - 'traefik.http.routers.image.rule=Host(`image.docker.localhost`)' + # Enable gzip compression + - 'traefik.http.routers.image.middlewares=test-compress' + - 'traefik.http.middlewares.test-compress.compress=true' diff --git a/docs/docker.md b/docs/docker.md new file mode 100644 index 0000000000..d9b609a0e1 --- /dev/null +++ b/docs/docker.md @@ -0,0 +1,65 @@ +# Docker and Telescope + +## Introduction + +Telescope uses Docker to deploy all the different parts of our app. If you haven't +worked with Docker before, it's worth taking a few minutes to [learn how it works](https://docs.docker.com/get-started/). + +You'll see Docker used in a few places + +## Setup + +See the [environment setup doc](environment-setup.md) for info specific to your platform. + +Once installed, Docker uses the following commands: + +- [`docker`](https://docs.docker.com/engine/reference/commandline/cli/) +- [`docker-compose`](https://docs.docker.com/compose/reference/) + +## Running Telescope via Docker + +We have a number of docker-compose files that control all the apps that we ship: + +- `docker-compose.yml` - the development version of our "classic" Telescope app (front-end and back-end) +- `docker-compose-production.yml` - the production version of our "classic" Telescope app (front-end and back-end) + +We also have files for our new Microservices Back-end: + +- `docker-compose-api.yml` - the development version +- `docker-compose-api-production.yml` - the production version + +The docker-compose files define a set of separate servers and services that can +be run together with a single command. + +``` +# run our development version of the entire Telescope app, building any containers as necessary +docker-compose -f docker-compose.yml up --build + +# stop the running containers +docker-compose -f docker-compose.yml down +``` + +If you want to run a specific app or apps, you can name them: + +``` +# run our development version of the entire Telescope app, building any containers as necessary +docker-compose -f docker-compose.yml up --build login redis telescope +``` + +### Running the Microservices + +For your convenience, you can use the following `npm` scripts: + +``` +# start the microservices containers and gateway in development +npm run api:start + +# stop the containers +npm run api:stop +``` + +The services will now be available via the defined routes: + +| Service | URL | +| ------------------------ | ------------------------------------ | +| Background Image Service | http://image.docker.localhost/image/ | diff --git a/package.json b/package.json index e7c57609f5..7873d89f68 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,8 @@ "html-elements": "./tools/html-elements.js" }, "scripts": { + "api:start": "docker-compose -f docker-compose-api.yml up --build -d", + "api:stop": "docker-compose -f docker-compose-api.yml down", "install:image-service": "cd src/api/image && npm install", "install:autodeployment": "cd tools/autodeployment && npm install", "install:next": "cd src/frontend/next && npm install",