Geonovum / ogc-api-testbed

OGC API Testbed Template - Stable
https://apitestbed.geonovum.nl
GNU General Public License v3.0
4 stars 4 forks source link

Reduce changes to be made for new web service docker-compose.yml #32

Closed justb4 closed 3 years ago

justb4 commented 3 years ago

When creating a new service like pygeoapi with a new name from a duplicated directory, quite some changes have to be made in the copy of the docker-compose.yml file. Using Docker variables may reduce this work significantly.

Proposed Solution

Using a local Bash env.sh (more flexible than Docker env files) and using symblic variables can greatly reduce efforts and errors. In fact already tested ok:

version: '3.3'

services:

  pygeoapi:

    image: ${DOCKER_IMAGE}

    container_name: ${SERVICE_NAME}

    expose:
      - "80"

    #    ports:
    #     - "5000:80"

    environment:
      SCRIPT_NAME: "${SCRIPT_NAME}"

    volumes:
      # Map data and config into pygeoapi container
      - ./local.config.yml:/pygeoapi/local.config.yml
      - ./data:/pygeoapi/data

    labels:
      # Enable Traefik routing on overlay service network
      - "traefik.enable=true"
      - "traefik.docker.network=service-network"

      # Define SSL/https router
      - "traefik.http.routers.${SERVICE_NAME}_https.rule=Host(`${TRAEFIK_SSL_DOMAIN}`) && PathPrefix(`/${SERVICE_NAME}`)"
      - "traefik.http.routers.${SERVICE_NAME}_https.entrypoints=https"
      - "traefik.http.routers.${SERVICE_NAME}_https.tls=${TRAEFIK_USE_TLS}"
      - "traefik.http.routers.${SERVICE_NAME}_https.tls.certresolver=${TRAEFIK_SSL_CERT_RESOLVER}"
      - "traefik.http.routers.${SERVICE_NAME}_https.tls.options=my_default@file"
      - "traefik.http.routers.${SERVICE_NAME}_https.middlewares=secure-headers@file"

      # Define local http router
      - "traefik.http.routers.${SERVICE_NAME}_http.rule=Host(`localhost`) && PathPrefix(`/${SERVICE_NAME}`)"
      - "traefik.http.routers.${SERVICE_NAME}_http.entrypoints=http"

networks:
  default:
    external:
      name: service-network

and env.sh (sourced by start.sh and stop.sh:

#!/bin/bash

source ../env.sh

export DOCKER_IMAGE_NAME="geopython/pygeoapi"
export DOCKER_IMAGE_VERSION="latest"
export DOCKER_IMAGE="${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}"
export SERVICE_NAME="pygeoapi"
export SCRIPT_NAME="/${SERVICE_NAME}"

Now the docker-compose.yml can even remain untouched for a new pygeoapi endpoint!

justb4 commented 3 years ago

Done.