Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share common docker-compose.yml configuration between various environments (production, development, maintenance) #66

Open
Raruto opened this issue Sep 7, 2022 · 0 comments · May be fixed by #79
Labels
refactoring Anything which could result in a API change

Comments

@Raruto
Copy link
Collaborator

Raruto commented Sep 7, 2022

By default, docker compose reads two files, a docker-compose.yml and an optional docker-compose.override.yml file.

By convention:

  • the docker-compose.yml contains your base configuration.
  • the docker-compose.override.yml contains configuration overrides for existing services or entirely new services.

A common use case for multiple files is changing a development Compose app for a production-like environment (which may be production, staging or CI). To support these differences, you can split your Compose configuration into a few different files

More info:


For example, here's how we could simplify the docker-compose-dev.yaml file:

docker compose \
  --file ../g3w-suite-docker/docker-compose.yml \
  --file ../g3w-suite-docker/docker-compose-dev.yml \
  ...
# ../g3w-suite-docker/docker-compose-dev.yml

version: "3"
services:

  postgis:
    restart: "no" # disable autorestart
    volumes:
      - g3wsuite-pg-data:/var/lib/postgresql
    networks:
      internal:
        aliases:
          - ${WEBGIS_PUBLIC_HOSTNAME}

  g3w-suite:
    environment:
      - BITBUCKET_TOKEN
      - G3WSUITE_QDJANGO_SERVER_URL
      - G3WSUITE_DEBUG
    ports:
      - "8000:8000"
    restart: "no" # disable autorestart
    volumes:
      - ./scripts:/scripts
    entrypoint: /scripts/docker-entrypoint-dev.sh

  nginx:
    deploy:
      replicas: 0  # disable nginx service

  certbot:
    deploy:
      replicas: 0  # disable certbot service

volumes:
  shared-volume:
  g3wsuite-pg-data:

networks:
  internal:
# ../g3w-suite-docker/docker-compose.yml

version: "3"
services:

  postgis:
    image: g3wsuite/postgis:11.0-2.5
    ports:
      - "5439:5432"
    environment:
      - POSTGRES_DBNAME=${G3WSUITE_POSTGRES_DBNAME},data_testing,data_production
      - POSTGRES_USER=${G3WSUITE_POSTGRES_USER_LOCAL}
      - POSTGRES_PASS=${G3WSUITE_POSTGRES_PASS}
      - ALLOW_IP_RANGE=0.0.0.0/0
    restart: on-failure
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
    volumes:
      - ${WEBGIS_DOCKER_SHARED_VOLUME}:/var/lib/postgresql
    healthcheck:
      interval: 60s
      timeout: 30s
      retries: 3
      test: "pg_isready"
    networks:
      internal:

  g3w-suite:
    image: g3wsuite/g3w-suite:dev
    environment:
      - G3WSUITE_TILECACHE_PATH
      - G3WSUITE_POSTGRES_DBNAME
      - G3WSUITE_POSTGRES_USER
      - G3WSUITE_POSTGRES_USER_LOCAL
      - G3WSUITE_POSTGRES_PASS
      - G3WSUITE_POSTGRES_HOST
      - G3WSUITE_POSTGRES_PORT
      - G3WSUITE_ORS_API_ENDPOINT
      - G3WSUITE_ORS_API_KEY
      - TILESTACHE_CACHE_BUFFER_SIZE
      - TILESTACHE_CACHE_TOKEN
      - G3WSUITE_GUNICORN_NUM_WORKERS
      - G3WSUITE_GUNICORN_MAX_REQUESTS
      - G3WSUITE_GUNICORN_TIMEOUT
      - FRONTEND
      - PGSERVICEFILE
      - QGIS_SERVER_LOG_FILE
      - QGIS_SERVER_LOG_LEVEL
    expose:
      - "8000"
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
    depends_on:
      - postgis
    volumes:
      - ${WEBGIS_DOCKER_SHARED_VOLUME}:/shared-volume
      - ${WEBGIS_DOCKER_SHARED_VOLUME}/node_modules:/code/node_modules
      - ./config/g3w-suite/overrides/templates:/code/templates:ro
      - ./config/g3w-suite/settings_docker.py:/code/g3w-admin/base/settings/local_settings.py
      - ./secrets/pg_service.conf:${PGSERVICEFILE}
    networks:
      internal:

  nginx:
    image: nginx
    ports:
      - "8080:8080"
      - "443:443"
    expose:
      - "8080"
    volumes:
      - ${WEBGIS_DOCKER_SHARED_VOLUME}:/shared-volume
      - ${WEBGIS_DOCKER_SHARED_VOLUME}/var/www/.well-known:/var/www/.well-known
      - ${WEBGIS_DOCKER_SHARED_VOLUME}/certs/letsencrypt:/etc/letsencrypt:ro
      - ./config/g3w-suite/overrides/static:/shared-volume/static/overrides:ro
      - ./config/nginx:/etc/nginx/conf.d:ro
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"
    restart: always
    networks:
      internal:

  # Letsencrypt certs
  certbot:
    image: certbot/certbot
    volumes:
      - ${WEBGIS_DOCKER_SHARED_VOLUME}/var/www/certbot:/var/www/certbot
      - ${WEBGIS_DOCKER_SHARED_VOLUME}/certs/letsencrypt:/etc/letsencrypt

volumes:
  shared-volume:
  g3wsuite-pg-data:

networks:
  internal:

NB Similarly for the following files there is no particular reason why they are separated:

@Raruto Raruto changed the title Share docker-compose.yml configuration between various environments (production, development, maintenance) Share default docker-compose.yml configuration between various environments (production, development, maintenance) Sep 7, 2022
@Raruto Raruto changed the title Share default docker-compose.yml configuration between various environments (production, development, maintenance) Share common docker-compose.yml configuration between various environments (production, development, maintenance) Sep 7, 2022
@Raruto Raruto added the refactoring Anything which could result in a API change label Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Anything which could result in a API change
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant