-
Notifications
You must be signed in to change notification settings - Fork 7
Home
Minimalist CI/CD for your Gitea
Tea Runner is an application that runs on a host and carries out simple actions whenever Gitea triggers it with a webhook. It's designed with minimalism in mind. It's much less capable than Gitlab pipelines or Github actions. But on the flip side, it's far easier to configure than Jenkins or Drone.
Out of the box, Tea Runner can:
- Copy newly committed files to a remote directory.
- Build a new Docker image on a remote host.
Maybe you run Gitea on a home network. You like the idea of automated deployments when you make changes to your repository, but setting up a full-blown CI/CD application like Jenkins or Drone seems like a lot of overhead for your needs.
Do GitOps with Tea Runner.
Commit a change to your website code and it's automatically rsync'd to your web server's root directory. Commit a change to your Dockerfile and a new image is automatically built for you.
Sound good? Keep reading.
Tea Runner is available as a Docker container. This is the quickest and easiest way to get started.
Clone the repository and use docker-compose with the supplied compose.yml file to get it running.
You can also run it as a stand-alone app.
- Make sure you have rsync and docker-community packages installed on your host.
- Clone the tea-runner repo or copy the files locally.
- Run
pip -r requirements.txt - Run
nohup tea-runner.py
Okay, it's running. Now what?
Tea Runner performs actions based on webhooks from Gitea. Here's a quick example of configuring a webhook to publish web content whenever the hello-www repository is changed.
First, create a hello-www repository in Gitea and add the sample index.html file to the repository. (Screenshot)
Next, add a webhook by accessing Settings > Webhooks. (Screenshot)
Finally, test the webhook by first clicking the edit button and then clicking Test Delivery at the bottom of the page. (Screenshot)
Gitea won't send webhooks to just anyone. Your host has to be on the allowed hosts list. And if you use TLS with self-signed certificates, you may run into problems with verification.
Two options can help you with that: ALLOWED_HOST_LIST and SKIP_TLS_VERIFY. Both require editing Gitea's app.ini file and appending a section for webhook. (Screenshot)
The directory component of the URL indicates the action. Parameters are passed to actions query strings.
For example, consider the URL http://destination.host:1706/rsync?dest=%2Fsrv%2Fwww
- destination.host is the host where Tea Runner is running.
- 1706 is the default Tea Runner port.
- rsync is the action to be performed.
- dest is a parameter sent to tell Tea Runner where to rsync the contents of the repository.
- %2Fsrv%2Fwww is the url-encoded path (/srv/www) of the destination directory.
Tea Runner is a Python Flask app. Python is pretty easy to learn. Take a look at tea_runner.py and you can probably figure it out.
There is a helper function called git_clone() that you'll want to include in any custom routes.
git_clone() will clone the repository whose name is sent with the webhook. It's best to clone into a temporary directory like the included actions do. Follow the code in /rsync and /docker/build.
Next, if you need additional binaries to get the action to work, define the path as a variable and add a check for them at the top of tea_runner.py. Look at RSYNC_BIN and DOCKER_BIN as examples.
Finally, if you've added binaries that are not included in the container build, be sure to add the Alpine packages in your Dockerfile
Even with only a couple simple actions, Tea Runner can be a time saver.