zerops:
  - setup: gitea
    build:
      base: ubuntu@24.04
      deployFiles: app.ini
    run:
      base: ubuntu@24.04
      ports:
        - port: 3000
          httpSupport: true
        - port: 2222
      envVariables:
        GITEA_VERSION: 1.26.1
        GITEA_WORK_DIR: /mnt/volume/gitea
        GITEA_DOMAIN: git.matejpavlicek.cz
        GITEA_ROOT_URL: https://git.matejpavlicek.cz
        DB_HOST: db
        DB_PORT: 5432
        DB_NAME: giteadb
        DB_USER: gitea
      envReplace:
        delimiter: "%%"
        target:
          - app.ini
      prepareCommands:
        - sudo apt-get update
        - sudo apt-get install -y --no-install-recommends git ca-certificates gettext-base wget gpg
        - wget -q -O /tmp/gitea https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64
        - wget -q -O /tmp/gitea.asc https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64.asc
        - gpg --keyserver hkps://keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
        - gpg --verify /tmp/gitea.asc /tmp/gitea
        - sudo install -m 755 /tmp/gitea /usr/local/bin/gitea
        - sudo groupadd --system git
        - sudo useradd --system --gid git --shell /bin/bash --home-dir /home/git --create-home git
        - sudo mkdir -p /etc/gitea
        - sudo chown root:git /etc/gitea
        - sudo chmod 770 /etc/gitea
      initCommands:
        - until mountpoint -q /mnt/volume; do sleep 1; done
        - sudo mkdir -p /mnt/volume/gitea/{custom,data,indexers,public,log}
        - sudo chown -R git:git /mnt/volume/gitea
        - sudo chmod -R 750 /mnt/volume/gitea
        - sudo install -m 660 -o root -g git /var/www/app.ini /etc/gitea/app.ini
      start: sudo -u git -E /usr/local/bin/gitea web --config /etc/gitea/app.ini
