version: '3.4'

x-cache-from:
  - &api-cache-from
    cache_from:
      - ${NGINX_IMAGE:-docker.pkg.github.com/api-platform/api-platform/nginx}
      - ${PHP_IMAGE:-docker.pkg.github.com/api-platform/api-platform/php}

services:
  php:
    build:
      context: ./api
      target: api_platform_php
      <<: *api-cache-from
    image: ${PHP_IMAGE:-docker.pkg.github.com/api-platform/api-platform/php}
    healthcheck:
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s
    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:-docker.pkg.github.com/api-platform/api-platform/nginx}
    depends_on:
      - php
    volumes:
      - ./api/public:/srv/api/public:ro

  vulcain:
    image: dunglas/vulcain
    environment:
      - CERT_FILE=/certs/localhost.crt
      - KEY_FILE=/certs/localhost.key
      - UPSTREAM=http://api
    depends_on:
      - api
      - dev-tls
    volumes:
      - dev-certs:/certs: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:
      - ALLOW_ANONYMOUS=1
      - CERT_FILE=/certs/localhost.crt
      - CORS_ALLOWED_ORIGINS=*
      - DEMO=1
      - JWT_KEY=!ChangeMe!
      - KEY_FILE=/certs/localhost.key
      - PUBLISH_ALLOWED_ORIGINS=https://localhost:1337 # required for publishing from the demo page
    depends_on:
      - dev-tls
    volumes:
      - dev-certs:/certs:ro
    ports:
      - target: 443
        published: 1337
        protocol: tcp

  client:
    build:
      context: ./client
      target: api_platform_client_development
      cache_from:
        - ${CLIENT_IMAGE:-docker.pkg.github.com/api-platform/api-platform/client}
    image: ${CLIENT_IMAGE:-docker.pkg.github.com/api-platform/api-platform/client}
    environment:
      - API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT=http://api
      - API_PLATFORM_CLIENT_GENERATOR_OUTPUT=src
    depends_on:
      - dev-tls
    volumes:
      - ./client:/usr/src/client:rw,cached
      - dev-certs:/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:-docker.pkg.github.com/api-platform/api-platform/admin}
    image: ${ADMIN_IMAGE:-docker.pkg.github.com/api-platform/api-platform/admin}
    depends_on:
      - dev-tls
    volumes:
      - ./admin:/usr/src/admin:rw,cached
      - dev-certs:/usr/src/admin/node_modules/webpack-dev-server/ssl:ro
    ports:
      - target: 3000
        published: 444
        protocol: tcp

  dev-tls:
    build:
      context: ./docker/dev-tls
    volumes:
      - dev-certs:/certs:rw
    ports:
      - target: 80
        published: 80
        protocol: tcp

volumes:
  db-data: {}
  dev-certs: {}
