services:
  # forgejo
  forgejo:
    image: codeberg.org/forgejo/forgejo:15
    container_name: forgejo
    profiles:
      - forgejo
    restart: on-failure:7
    depends_on:
      - database_forgejo
      - caddy
    ports:
      - "22:2222"
    env_file:
      - ./env/forgejo.env
    volumes:
      - forgejo_data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    networks:
      - caddy-dev
      - forgejo-internal
#    user: ${PUID:-1000}:${PGID:-1000} 
    security_opt:
      - no-new-privileges:true
  
  # Database forgejo
  database_forgejo:
    image: mariadb:latest
    container_name: database_forgejo
    profiles:
      - forgejo
    depends_on:
      - caddy
    restart: on-failure:7
    volumes:
      - forgejo_db:/var/lib/mysql:rw
    env_file:
      - ./env/forgejo_db.env
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - forgejo-internal
    security_opt:
      - no-new-privileges:true

  # forgejo-runner
  docker-in-docker:
    image: code.forgejo.org/oci/docker:dind
    container_name: 'docker_dind'
    hostname: docker
    networks:
      - forgejo-internal
    profiles:
      - forgejo-runner
    privileged: true
    environment:
      DOCKER_TLS_CERTDIR: /certs
      DOCKER_HOST: docker-in-docker
    volumes:
      - forgejo_certs:/certs

  forgejo_runner:
    image: data.forgejo.org/forgejo/runner:12
    networks:
      - forgejo-internal
    profiles:
      - forgejo-runner
    depends_on:
      docker-in-docker:
        condition: service_started
    container_name: 'forgejo_runner'
    env_file:
      - ./env/forgejo_runner.env
#    user: ${PUID:-1000}:${PGID:-1000} 
    volumes:
#      - ./config/forgejo_runner/config.yaml:/config.yaml:ro
      - forgejo_runner:/data
      - forgejo_certs:/certs
    restart: on-failure:7

#    command: '/bin/sh -c "while : ; do sleep 1 ; done ;"'
    command: '/bin/sh -c "sleep 5; forgejo-runner -c /data/config.yml daemon"'

volumes:
  forgejo_data:
    name: forgejo_data
  forgejo_db:
    name: forgejo_db
  forgejo_certs:
    name: forgejo_certs
  forgejo_runner:
    name: forgejo_runner

networks:
  caddy-dev:
    driver: bridge
    name: caddy-dev
  forgejo-internal:
    driver: bridge
    name: forgejo-internal
