version: "3.8"
name: ${PROJECT_NAME}

services:
    docpress:
        profiles:
            - docpress
        image: node:18
        volumes:
            - ./:/data
            - ./tmp:/tmp
            - ./tmp/nonexistent:/nonexistent
        working_dir: /data/docs
        command: sh -c "yarn install && yarn docpress:serve"
        expose:
            - 3000
        labels:
            - traefik.enable=true
            - online.testversion.code.subdomain=${PROJECT_NAME}-docpress
        user: ${UID}:${GID}

    yarnstart:
        profiles:
            - tibi
            - tibi-dev
        image: node:18
        volumes:
            - ./:/data
            - ./tmp:/tmp
            - ./tmp/nonexistent:/nonexistent
            - ./tmp/.npm:/.npm
        working_dir: /data
        command: sh -c "yarn install && API_BASE=http://tibiserver:8080/api/v1/_/${TIBI_NAMESPACE} yarn start${START_SCRIPT}"
        expose:
            - 3000
        labels:
            - traefik.enable=true
            - online.testversion.code.subdomain=${PROJECT_NAME}
            - traefik.http.routers.${PROJECT_NAME}-yarnstart.middlewares=${PROJECT_NAME}-yarnstart
            - traefik.http.middlewares.${PROJECT_NAME}-yarnstart.basicauth.usersfile=${PWD}/.basic-auth-web
        user: ${UID}:${GID}

    tibiserver:
        profiles:
            - tibi
        image: gitbase.de/cms/tibi-server
        volumes:
            - ./:/data
        environment:
            DB_DIAL: mongodb://mongo
            DB_PREFIX: ${TIBI_PREFIX}
            MAIL_HOST: maildev:25
            SECURITY_ALLOWABSOLUTEPATHS: "true"
            SECURITY_ALLOWUPPERPATHS: "true"
        depends_on:
            - mongo
        expose:
            - 8080
        labels:
            - traefik.enable=true
            - traefik.http.services.${PROJECT_NAME}-tibiserver.loadbalancer.server.port=8080
            - online.testversion.code.subdomain=${PROJECT_NAME}-tibiserver

    tibiserver-dev:
        hostname: tibiserver
        build:
            context: ./
            dockerfile: ./../../cms/tibi-server/Dockerfile.air
        profiles:
            - tibi-dev
        volumes:
            - ./:/data
            - ./../../cms/tibi-server:/tibi-server
            - ./../../../../tmp/go/pkg:/go/pkg
        working_dir: /tibi-server
        environment:
            GOCACHE: /tmp/
            DB_DIAL: mongodb://mongo
            DB_PREFIX: ${TIBI_PREFIX}
            MAIL_HOST: maildev:25
            SECURITY_ALLOWABSOLUTEPATHS: "true"
            SECURITY_ALLOWUPPERPATHS: "true"
        depends_on:
            - mongo
        user: ${UID}:${GID}
        expose:
            - 8080
        labels:
            - traefik.enable=true
            - traefik.http.services.${PROJECT_NAME}-tibiserver.loadbalancer.server.port=8080
            - online.testversion.code.subdomain=${PROJECT_NAME}-tibiserver

    tibiadmin:
        profiles:
            - tibi
        image: gitbase.de/cms/tibi-admin
        environment:
            INDEX: spa.html
            WEBROOT: /data
            API: /api:http://tibiserver:8080/api/v1
            PORT: 80
        depends_on:
            - tibiserver
        expose:
            - 80
        labels:
            - traefik.enable=true
            - online.testversion.code.subdomain=${PROJECT_NAME}-tibiadmin
            - traefik.http.routers.${PROJECT_NAME}-tibiadmin.middlewares=${PROJECT_NAME}-tibiadmin
            - traefik.http.middlewares.${PROJECT_NAME}-tibiadmin.basicauth.usersfile=${PWD}/.basic-auth-code

    tibiadmin-dev:
        profiles:
            - tibi-dev
        image: node:18
        volumes:
            - ./../../cms/tibi-admin:/data
        working_dir: /data
        command: sh -c "yarn install && API_BASE=http://tibiserver:8080/api/v1 yarn start:code-server"
        expose:
            - 3000
        labels:
            - traefik.enable=true
            - online.testversion.code.subdomain=${PROJECT_NAME}-tibiadmin-dev
            - traefik.http.routers.${PROJECT_NAME}-tibiadmin-dev.middlewares=${PROJECT_NAME}-tibiadmin-dev
            - traefik.http.middlewares.${PROJECT_NAME}-tibiadmin-dev.basicauth.usersfile=${PWD}/.basic-auth-code
        user: ${UID}:${GID}

    mongo:
        profiles:
            - tibi
            - tibi-dev
        image: gitbase.de/server/mongo:4.2
        volumes:
            - ./tmp/mongo-data:/data/db
        user: ${UID}:${GID}

    adminmongo:
        profiles:
            - tibi
            - tibi-dev
        image: gitbase.de/server/adminmongo
        environment:
            CONN_NAME: mongo
            DB_HOST: mongo
            PORT: 1234
        expose:
            - 1234
        labels:
            - traefik.enable=true
            - online.testversion.code.subdomain=${PROJECT_NAME}-adminmongo
            - traefik.http.routers.${PROJECT_NAME}-adminmongo.middlewares=${PROJECT_NAME}-adminmongo
            - traefik.http.middlewares.${PROJECT_NAME}-adminmongo.basicauth.usersfile=${PWD}/.basic-auth-code

    maildev:
        profiles:
            - tibi
            - tibi-dev
        image: maildev/maildev
        command: node bin/maildev --web 1080 --smtp 25 -v --hide-extensions=STARTTLS
        expose:
            - 1080
        labels:
            - traefik.enable=true
            - online.testversion.code.subdomain=${PROJECT_NAME}-maildev
            - traefik.http.services.${PROJECT_NAME}-maildev.loadbalancer.server.port=1080
            - traefik.http.routers.${PROJECT_NAME}-maildev.middlewares=${PROJECT_NAME}-maildev
            - traefik.http.middlewares.${PROJECT_NAME}-maildev.basicauth.usersfile=${PWD}/.basic-auth-code

    chisel:
        profiles:
            - chisel
        image: jpillora/chisel
        expose:
            - 8080
        labels:
            - traefik.enable=true
            - online.testversion.code.subdomain=${PROJECT_NAME}-chisel
        command: server --port 8080 --auth coder:coder
