version: '3.2'

services:
 
  #migration need to be handle manually for production 

  composer-deps-prod:
    build: backend
    command: composer install
    volumes:
      # Re-use local composer cache via host-volume
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      
  # Start container to init dev environment and kill after
  init-environment-prod:
    build: backend
    command: php init --env=Production --overwrite=All
    volumes:
      # Re-use local composer cache via host-volume
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      # Mount source-code for development
      - ./:/app 
    depends_on:
      - "composer-deps-prod"
       
  backend-prod:
    build: backend
    ports:
      - 27080:80
    volumes:
      # Re-use local composer cache via host-volume
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      # Mount source-code for development
      - ./:/app
    working_dir: /app 
    depends_on:
      - "init-environment-prod"

  frontend-prod:
    build: frontend
    ports:
      - 28080:80
    volumes:
      # Re-use local composer cache via host-volume
      - ~/.composer-docker/cache:/root/.composer/cache:delegated
      # Mount source-code for development
      - ./:/app
    depends_on:
      - "init-environment-prod"
