Forgejo as a Woodpecker CI service

When running tests in Woodpecker CI, it is useful to run a detached (in the background, AKA a service) MySQL server, as explained in the Woodpecker CI documentation. For that to work, the initial user is provided as an environment variable and created when the server starts.

Forgejo does not automatically create a user and it needs to be done via the command line, as shown in the following .woodpecker.yml:

    detach: true
    ports: ["80"]
      - GITEA__security__INSTALL_LOCK=true
      - GITEA__server__HTTP_PORT=80
      - GITEA__server__ROOT_URL=http://forgejo/
      - /usr/bin/entrypoint &
      - sleep 5
      - su git -c 'gitea admin user create --admin --username root --password admin1234 --email'
      - wait

    image: 'golang:1.19-bullseye'
      - sleep 10
      - curl http://forgejo/api/v1/version

The detach keyword runs the forgejo step in the background (that is what detach: true is for) and moves to the version step immediately. It takes a few seconds for the Forgejo server to come up: this is the reason for the sleep 10. When Forgejo is run from the command line like so:

docker run --name forgejo -e GITEA__security__INSTALL_LOCK=true -d

it runs the /usr/bin/entrypoint script which starts the server, waiting for incoming requests. But when run from Woodpecker CI, the list of commands is run instead and the Forgejo server does not start implicitly. It needs to be started explicitly, in the background, by calling /usr/bin/entrypoint. After a sleep 5 it is ready to create a new user which is done with admin user create .... It must then wait on the Forgejo server, otherwise it will terminate immediately instead of waiting for the pipeline to finish.

The result of the pipeline above will be the Forgejo version displayed like this: