version: '3'

services:
  server:
    build:
      context: .
      dockerfile: ./Dockerfile-production
      target: server
      args:
        - node_env=${NODE_ENV:-production}
        - server_protocol=${SERVER_PROTOCOL}
        - server_host=${SERVER_HOST}
        - server_port=${SERVER_PORT}
        - client_protocol=${CLIENT_PROTOCOL}
        - client_host=${CLIENT_HOST}
        - client_port=${CLIENT_PORT}
        - public_client_protocol=${PUBLIC_CLIENT_PROTOCOL}
        - public_client_host=${PUBLIC_CLIENT_HOST}
        - public_client_port=${PUBLIC_CLIENT_PORT}
        - use_colab_email=${USE_COLAB_EMAIL:-false}
        - flax_site_url=${FLAX_SITE_URL:-https://site.kotahidev.cloud68.co/}
        - USE_COLAB_BIOPHYSICS_IMPORT=${USE_COLAB_BIOPHYSICS_IMPORT:-false}

    ports:
      - ${SERVER_PORT:-3000}:${SERVER_PORT:-3000}
    environment:
      - NODE_ENV=${NODE_ENV:-production}
      - POSTGRES_HOST=${POSTGRES_HOST}
      - POSTGRES_PORT=${POSTGRES_PORT}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PUBSWEET_SECRET=${PUBSWEET_SECRET}
      - CLIENT_PROTOCOL=${CLIENT_PROTOCOL}
      - CLIENT_HOST=${CLIENT_HOST}
      - CLIENT_PORT=${CLIENT_PORT}
      - PUBLIC_CLIENT_HOST=${PUBLIC_CLIENT_HOST:-0.0.0.0}
      - SERVER_PROTOCOL=${SERVER_PROTOCOL}
      - SERVER_HOST=${SERVER_HOST}
      - SERVER_PORT=${SERVER_PORT}
      - ORCID_CLIENT_ID=${ORCID_CLIENT_ID}
      - ORCID_CLIENT_SECRET=${ORCID_CLIENT_SECRET}
      - USE_SANDBOXED_ORCID=${USE_SANDBOXED_ORCID:-false}
      - USE_COLAB_EMAIL=${USE_COLAB_EMAIL:-false}
      - KOTAHI_API_TOKENS=${KOTAHI_API_TOKENS:-}
      - JOURNAL_NAME=${JOURNAL_NAME:-}
      - JOURNAL_ABBREVIATED_NAME=${JOURNAL_ABBREVIATED_NAME:-}
      - JOURNAL_HOMEPAGE=${JOURNAL_HOMEPAGE:-}
      - GOOGLE_SPREADSHEET_CLIENT_EMAIL=${GOOGLE_SPREADSHEET_CLIENT_EMAIL:-}
      - GOOGLE_SPREADSHEET_PRIVATE_KEY=${GOOGLE_SPREADSHEET_PRIVATE_KEY:-}
      - GOOGLE_SPREADSHEET_ID=${GOOGLE_SPREADSHEET_ID:-}
      - HYPOTHESIS_API_KEY=${HYPOTHESIS_API_KEY:-}
      - HYPOTHESIS_GROUP=${HYPOTHESIS_GROUP:-}
      - HYPOTHESIS_ALLOW_TAGGING=${HYPOTHESIS_ALLOW_TAGGING}
      - HYPOTHESIS_REVERSE_FIELD_ORDER=${HYPOTHESIS_REVERSE_FIELD_ORDER}
      - CROSSREF_LOGIN=${CROSSREF_LOGIN:-}
      - CROSSREF_PASSWORD=${CROSSREF_PASSWORD:-}
      - CROSSREF_REGISTRANT=${CROSSREF_REGISTRANT:-}
      - CROSSREF_DEPOSITOR_NAME=${CROSSREF_DEPOSITOR_NAME:-}
      - CROSSREF_DEPOSITOR_EMAIL=${CROSSREF_DEPOSITOR_EMAIL:-}
      - CROSSREF_PUBLICATION_TYPE=${CROSSREF_PUBLICATION_TYPE:-article}
      - CROSSREF_USE_SANDBOX=${CROSSREF_USE_SANDBOX:-false}
      - DOI_PREFIX=${DOI_PREFIX:-}
      - PUBLISHED_ARTICLE_LOCATION_PREFIX=${PUBLISHED_ARTICLE_LOCATION_PREFIX:-}
      - PUBLICATION_LICENSE_URL=${PUBLICATION_LICENSE_URL:-}
      - MANUSCRIPTS_TABLE_COLUMNS=${MANUSCRIPTS_TABLE_COLUMNS}
      - DISPLAY_SHORTID_AS_IDENTIFIER=${DISPLAY_SHORTID_AS_IDENTIFIER:-false}
      - GMAIL_NOTIFICATION_EMAIL_AUTH=${GMAIL_NOTIFICATION_EMAIL_AUTH:-}
      - GMAIL_NOTIFICATION_EMAIL_SENDER=${GMAIL_NOTIFICATION_EMAIL_SENDER:-}
      - GMAIL_NOTIFICATION_PASSWORD=${GMAIL_NOTIFICATION_PASSWORD:-}
      - PUBLISHING_WEBHOOK_URL=${PUBLISHING_WEBHOOK_URL:-}
      - PUBLISHING_WEBHOOK_TOKEN=${PUBLISHING_WEBHOOK_TOKEN:-}
      - PUBLISHING_WEBHOOK_REF=${PUBLISHING_WEBHOOK_REF:-}
      - REVIEW_SHARED=${REVIEW_SHARED:-false}
      - REVIEW_HIDE=${REVIEW_HIDE:-false}
      - NOTIFICATION_EMAIL_AUTOMATED=${NOTIFICATION_EMAIL_AUTOMATED:-false}
      - NOTIFICATION_EMAIL_CC_ENABLED=${NOTIFICATION_EMAIL_CC_ENABLED:-false}
      - SERVICE_PAGEDJS_CLIENT_ID=${SERVICE_PAGEDJS_CLIENT_ID}
      - SERVICE_PAGEDJS_SECRET=${SERVICE_PAGEDJS_SECRET}
      - SERVICE_PAGEDJS_PROTOCOL=${SERVICE_PAGEDJS_PROTOCOL}
      - SERVICE_PAGEDJS_HOST=${SERVICE_PAGEDJS_HOST}
      - SERVICE_PAGEDJS_PORT=${SERVICE_PAGEDJS_PORT}
      - SERVICE_ANYSTYLE_CLIENT_ID=${SERVICE_ANYSTYLE_CLIENT_ID}
      - SERVICE_ANYSTYLE_SECRET=${SERVICE_ANYSTYLE_SECRET}
      - SERVICE_ANYSTYLE_PROTOCOL=${SERVICE_ANYSTYLE_PROTOCOL}
      - SERVICE_ANYSTYLE_HOST=${SERVICE_ANYSTYLE_HOST}
      - SERVICE_ANYSTYLE_PORT=${SERVICE_ANYSTYLE_PORT}
      - S3_PROTOCOL=${S3_PROTOCOL:-http}
      - S3_HOST=${S3_HOST:-localhost}
      - S3_PORT=${S3_PORT:-}
      - S3_ACCESS_KEY_ID=${S3_ACCESS_KEY_ID:-nonRootUser}
      - S3_SECRET_ACCESS_KEY=${S3_SECRET_ACCESS_KEY:-nonRootPassword}
      - S3_BUCKET=${S3_BUCKET:-uploads}
      - AUTO_IMPORT_HOUR_UTC=${AUTO_IMPORT_HOUR_UTC:-}
      - DISABLE_EVENT_NOTIFICATIONS=${DISABLE_EVENT_NOTIFICATIONS:-}
      - ARCHIVE_PERIOD_DAYS=${ARCHIVE_PERIOD_DAYS:-}
      - ALLOW_MANUAL_IMPORT=${ALLOW_MANUAL_IMPORT:-}
      - SEMANTIC_SCHOLAR_IMPORTS_RECENCY_PERIOD_DAYS=${SEMANTIC_SCHOLAR_IMPORTS_RECENCY_PERIOD_DAYS:-}
      - TEAM_TIMEZONE=${TEAM_TIMEZONE}
      - SERVICE_XSWEET_CLIENT_ID=59a3392b-0c4f-4318-bbe2-f86eff6d3de4
      - SERVICE_XSWEET_SECRET=asldkjLKJLaslkdf897kjhKUJH
      - SERVICE_XSWEET_PROTOCOL=${SERVICE_XSWEET_PROTOCOL:-http}
      - SERVICE_XSWEET_HOST=${SERVICE_XSWEET_HOST:-xsweet}
      - SERVICE_XSWEET_PORT=${SERVICE_XSWEET_PORT:-3004}
      - FLAX_EXPRESS_PORT=${FLAX_EXPRESS_PORT}
      - FLAX_EXPRESS_HOST=${FLAX_EXPRESS_HOST:-kotahi-flax-site}
      - FLAX_EXPRESS_PROTOCOL=${FLAX_EXPRESS_PROTOCOL:-http}
      - FLAX_CLIENT_ID=${FLAX_CLIENT_ID}
      - FLAX_CLIENT_SECRET=${FLAX_CLIENT_SECRET}
      - FLAX_CLIENT_API_URL=${FLAX_CLIENT_API_URL}
      - FLAX_SITE_URL=${FLAX_SITE_URL}
      - USE_APERTURE_EMAIL=${USE_APERTURE_EMAIL}
      - INSTANCE_GROUPS=${INSTANCE_GROUPS:-kotahi:aperture}
      - USE_COLAB_BIOPHYSICS_IMPORT=${USE_COLAB_BIOPHYSICS_IMPORT:-false}

    volumes:
      - ./uploads:/home/node/app/uploads
      - ./config:/home/node/app/config

  xsweet:
    depends_on:
      - db-xsweet
    image: cokoapps/xsweet:2.1.2
    ports:
      - ${SERVICE_XSWEET_PORT:-3004}:${SERVICE_XSWEET_PORT:-3004}
    environment:
      - PUBSWEET_SECRET=xsweet_dev_secret
      - POSTGRES_USER=xsweet_user_dev
      - POSTGRES_PASSWORD=xsweet_user_password
      - POSTGRES_HOST=db-xsweet
      - POSTGRES_DB=xsweet_dev
      - POSTGRES_PORT=5432
      - SERVER_PORT=${SERVICE_XSWEET_PORT:-3004}
      - NODE_ENV=development
    entrypoint:
      [
        'sh',
        'scripts/wait-for-it',
        'db-xsweet:5432',
        '--',
        'sh',
        'scripts/setupDevServer.sh',
      ]
    command: ['node', 'server/startServer.js']

  db-xsweet:
    image: postgres:14.4-alpine
    environment:
      - POSTGRES_USER=xsweet_user_dev
      - POSTGRES_DB=xsweet_dev
      - POSTGRES_PASSWORD=xsweet_user_password
    volumes:
      - ./scripts/init-pgboss.sql:/docker-entrypoint-initdb.d/init-pgboss.sql

  kotahi-flax-site:
    image: cokoapps/kotahi-flax:0.2.27
    depends_on:
      - server
    ports:
      - ${FLAX_EXPRESS_PORT:-8082}:${FLAX_EXPRESS_PORT:-3000}
      - ${FLAX_SITE_PORT:-8081}:80

    environment:
      - FLAX_EXPRESS_PORT=${FLAX_EXPRESS_PORT:-3000}
      - FLAX_CLIENT_ID=${FLAX_CLIENT_ID}
      - FLAX_CLIENT_SECRET=${FLAX_CLIENT_SECRET}
      - FLAX_CLIENT_API_URL=${FLAX_CLIENT_API_URL}
