version: '3.4'

x-cache-from:
  - &api-cache-from
    cache_from:
      - ${NGINX_IMAGE:-quay.io/api-platform/nginx}
      - ${PHP_IMAGE:-quay.io/api-platform/php}

services:
  php:
    build:
      context: ./api
      target: api_platform_php
      <<: *api-cache-from
    image: ${PHP_IMAGE:-quay.io/api-platform/php}
    depends_on:
      - db
    volumes:
      - ./api:/srv/api:rw,cached
      - ./api/docker/php/conf.d/api-platform.dev.ini/:/usr/local/etc/php/conf.d/api-platform.ini
      # if you develop on Linux, you may use a bind-mounted host directory instead
      # - ./api/var:/srv/api/var:rw

  api:
    build:
      context: ./api
      target: api_platform_nginx
      <<: *api-cache-from
    image: ${NGINX_IMAGE:-quay.io/api-platform/nginx}
    depends_on:
      - php
    volumes:
      - ./api/public:/srv/api/public:ro

  vulcain:
    image: dunglas/vulcain
    environment:
      - UPSTREAM=http://api
      - CERT_FILE=/cert/cert.crt
      - KEY_FILE=/cert/cert.key
    depends_on:
      - tls
      - api
    volumes:
      - cert:/cert:ro
    ports:
      - target: 443
        published: 8443
        protocol: tcp

  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_DB=api
      - POSTGRES_PASSWORD=!ChangeMe!
      - POSTGRES_USER=api-platform
    volumes:
      - db-data:/var/lib/postgresql/data:rw
      # you may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
      # - ./api/docker/db/data:/var/lib/postgresql/data:rw
    ports:
      - target: 5432
        published: 5432
        protocol: tcp

  mercure:
    image: dunglas/mercure
    environment:
      - CERT_FILE=/cert/cert.crt
      - KEY_FILE=/cert/cert.key
      - ALLOW_ANONYMOUS=1
      - CORS_ALLOWED_ORIGINS=*
      - DEMO=1
      - JWT_KEY=!ChangeMe!
      - PUBLISH_ALLOWED_ORIGINS=https://localhost:1337 # required for publishing from the demo page
    depends_on:
      - tls
    volumes:
      - cert:/cert:ro
    ports:
      - target: 443
        published: 1337
        protocol: tcp

  client:
    build:
      context: ./client
      target: api_platform_client_development
      cache_from:
        - ${CLIENT_IMAGE:-quay.io/api-platform/client}
    image: ${CLIENT_IMAGE:-quay.io/api-platform/client}
    environment:
      - API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT=http://api
      - API_PLATFORM_CLIENT_GENERATOR_OUTPUT=src
    depends_on:
      - tls
    volumes:
      - ./client:/usr/src/client:rw,cached
      - cert:/usr/src/client/node_modules/webpack-dev-server/ssl:ro
    ports:
      - target: 3000
        published: 443
        protocol: tcp

  admin:
    build:
      context: ./admin
      target: api_platform_admin_development
      cache_from:
        - ${ADMIN_IMAGE:-quay.io/api-platform/admin}
    image: ${ADMIN_IMAGE:-quay.io/api-platform/admin}
    depends_on:
      - tls
    volumes:
      - ./admin:/usr/src/admin:rw,cached
      - cert:/usr/src/admin/node_modules/webpack-dev-server/ssl:ro
    ports:
      - target: 3000
        published: 444
        protocol: tcp

  tls:
    build:
      context: ./
      dockerfile: Dockerfile.tls
    volumes:
      - cert:/cert:rw

volumes:
  db-data: {}
  cert: {}
