services:
  backend:
    container_name: sls-backend
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ${REPO_BASEDIR}:/app
      # - ${REPO_BASEDIR}/../genericsuite-be:/genericsuite-be
      # - ${REPO_BASEDIR}/../genericsuite-be-ai:/genericsuite-be-ai
      - ${SCRIPTS_DIR}/..:/var/scripts
      - ${HOME}/.aws:/root/.aws
    environment:
      - STAGE=${STAGE}
      - APP_DIR=${APP_DIR}
      - APP_MAIN_FILE=${APP_MAIN_FILE}
      - APP_HANDLER=${APP_HANDLER}
      - LOCAL_GE_BE_AI_REPO=${LOCAL_GE_BE_AI_REPO}
      - LOCAL_GE_BE_REPO=${LOCAL_GE_BE_REPO}
    entrypoint: /var/scripts/secure_local_server/docker_entrypoint.sh

  nginx:
    container_name: sls-nginx
    image: nginx:latest
    ports:
      # - "443:443"
      # - "5001:443"
      - "${BACKEND_LOCAL_PORT}:443"
      # - "80:80"
      # - "5002:80"
      - "${BACKEND_DEBUG_LOCAL_PORT}:80"
    expose:
      # - 5001
      - "${BACKEND_LOCAL_PORT}"
      # - 5002
      - "${BACKEND_DEBUG_LOCAL_PORT}"
    environment:
      - APP_NAME_LOWERCASE=${APP_NAME_LOWERCASE}
      - BACKEND_LOCAL_PORT=${BACKEND_LOCAL_PORT}
      - BACKEND_DEBUG_LOCAL_PORT=${BACKEND_DEBUG_LOCAL_PORT}
      - REPO_BASEDIR=${REPO_BASEDIR}
      - SCRIPTS_DIR=${SCRIPTS_DIR}
    volumes:
      # The following volume directory does not work in Podman, becasue it throws:
      #   sts-nginx | info: /etc/nginx/conf.d/default.conf is not a file or does not exist
      # The "/etc/nginx/conf.d" directory is read-only in the image, so it cannot be mounted as a volume
      # - ${TMP_WORKING_DIR}/conf.d/:/etc/nginx/conf.d/:Z
      
      # To be compatible with both Podman and Docker, a named volume is used
      - sls_nginx-confd-vol:/etc/nginx/conf.d:Z

      - ${REPO_BASEDIR}/app.${APP_NAME_LOWERCASE}.local.key:/etc/nginx/ssl/app.${APP_NAME_LOWERCASE}.local.key
      - ${REPO_BASEDIR}/app.${APP_NAME_LOWERCASE}.local.crt:/etc/nginx/ssl/app.${APP_NAME_LOWERCASE}.local.crt
      - ${REPO_BASEDIR}/app.${APP_NAME_LOWERCASE}.local.chain.crt:/etc/nginx/ssl/app.${APP_NAME_LOWERCASE}.local.chain.crt
      - ${REPO_BASEDIR}/ca.crt:/etc/nginx/ssl/ca.crt
    depends_on:
      - backend

volumes:
  sls_nginx-confd-vol:
    external: true
