### CRIMSON --- A simple PHP framework.
### Copyright © 2024 Freya Murphy <contact@freyacat.org>
###
### This file is part of CRIMSON.
###
### CRIMSON is free software; you can redistribute it and/or modify it
### under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 3 of the License, or (at
### your option) any later version.
###
### CRIMSON is distributed in the hope that it will be useful, but
### WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with CRIMSON. If not, see <http://www.gnu.org/licenses/>.

services:
  # `docker-compose-base.yml`
  # This compose file creates the `web`, `php`, and `init` containers.
  # This is the barebones stack required to run crimson.
  #
  # This service stack is ALWAYS enabled.

  web:
    # Crimson runs a nginx proxy to facilitate requets to PHP and requests
    # to the API (if enabled). Since it needs PHP to be running to send
    # requests, `php` is an added dependency.
    #
    # HTTP_PORT and HTTP_BIND sets what the external listen address will be for
    # the entire crimson stack.
    build: ${CRIMSON_ROOT}/build/nginx
    restart: unless-stopped
    env_file: DOCKER_ENV_FILES
    ports:
      - ${HTTP_BIND}:${HTTP_PORT}:8080
    volumes:
      - ${PROJECT_SOURCE}:/opt/site:ro
      - ${CRIMSON_ROOT}/src:/opt/crimson:ro
    depends_on:
      php:
        condition: service_started

  php:
    # There exists some crimson functionaly that MAY be used which requires a
    # stamp.php file to be auto generated. This is done in `init`, this `init`
    # is an added dependency.
    build: ${CRIMSON_ROOT}/build/php
    restart: unless-stopped
    env_file: DOCKER_ENV_FILES
    volumes:
      - ${PROJECT_SOURCE}:/opt/site:ro
      - ${CRIMSON_ROOT}/src:/opt/crimson:ro
      - ${PROJECT_DATA}/crimson:/var/run/crimson
    depends_on:
      init:
        condition: service_completed_successfully

  init:
    # Initalizes required files for php. Currently init only generates stamp.php.
    # This file hols all file stamps for all public assets, which is used in
    # crimsons `asset_stamp` controller function.
    build: ${CRIMSON_ROOT}/build/init
    restart: no
    env_file: DOCKER_ENV_FILES
    volumes:
      - ${PROJECT_SOURCE}:/opt/site
      - ${PROJECT_DATA}/crimson:/var/run/crimson