You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

act-runner.en-us.md 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. ---
  2. date: "2023-04-27T15:00:00+08:00"
  3. title: "Act Runner"
  4. slug: "act-runner"
  5. sidebar_position: 20
  6. draft: false
  7. toc: false
  8. menu:
  9. sidebar:
  10. parent: "actions"
  11. name: "Act Runner"
  12. sidebar_position: 20
  13. identifier: "actions-runner"
  14. ---
  15. # Act Runner
  16. This page will introduce the [act runner](https://gitea.com/gitea/act_runner) in detail, which is the runner of Gitea Actions.
  17. ## Requirements
  18. It is recommended to run jobs in a docker container, so you need to install docker first.
  19. And make sure that the docker daemon is running.
  20. Other OCI container engines which are compatible with Docker's API should also work, but are untested.
  21. However, if you are sure that you want to run jobs directly on the host only, then docker is not required.
  22. ## Installation
  23. There are multiple ways to install the act runner.
  24. ### Download the binary
  25. You can download the binary from the [release page](https://gitea.com/gitea/act_runner/releases).
  26. However, if you want to use the latest nightly build, you can download it from the [download page](https://dl.gitea.com/act_runner/).
  27. When you download the binary, please make sure that you have downloaded the correct one for your platform.
  28. You can check it by running the following command:
  29. ```bash
  30. chmod +x act_runner
  31. ./act_runner --version
  32. ```
  33. If you see the version information, it means that you have downloaded the correct binary.
  34. ### Use the docker image
  35. You can use the docker image from the [docker hub](https://hub.docker.com/r/gitea/act_runner/tags).
  36. Just like the binary, you can use the latest nightly build by using the `nightly` tag, while the `latest` tag is the latest stable release.
  37. ```bash
  38. docker pull gitea/act_runner:latest # for the latest stable release
  39. docker pull gitea/act_runner:nightly # for the latest nightly build
  40. ```
  41. ## Configuration
  42. Configuration is done via a configuration file. It is optional, and the default configuration will be used when no configuration file is specified.
  43. You can generate a configuration file by running the following command:
  44. ```bash
  45. ./act_runner generate-config
  46. ```
  47. The default configuration is safe to use without any modification, so you can just use it directly.
  48. ```bash
  49. ./act_runner generate-config > config.yaml
  50. ./act_runner --config config.yaml [command]
  51. ```
  52. You could also generate config file with docker:
  53. ```bash
  54. docker run --entrypoint="" --rm -it gitea/act_runner:latest act_runner generate-config > config.yaml
  55. ```
  56. When you are using the docker image, you can specify the configuration file by using the `CONFIG_FILE` environment variable. Make sure that the file is mounted into the container as a volume:
  57. ```bash
  58. docker run -v $PWD/config.yaml:/config.yaml -e CONFIG_FILE=/config.yaml ...
  59. ```
  60. You may notice the commands above are both incomplete, because it is not the time to run the act runner yet.
  61. Before running the act runner, we need to register it to your Gitea instance first.
  62. ## Registration
  63. Registration is required before running the act runner, because the runner needs to know where to get jobs from.
  64. And it is also important to Gitea instance to identify the runner.
  65. ### Runner levels
  66. You can register a runner in different levels, it can be:
  67. - Instance level: The runner will run jobs for all repositories in the instance.
  68. - Organization level: The runner will run jobs for all repositories in the organization.
  69. - Repository level: The runner will run jobs for the repository it belongs to.
  70. Note that the repository may still use instance-level or organization-level runners even if it has its own repository-level runners. A future release may provide an option to allow more control over this.
  71. ### Obtain a registration token
  72. The level of the runner determines where to obtain the registration token.
  73. - Instance level: The admin settings page, like `<your_gitea.com>/admin/actions/runners`.
  74. - Organization level: The organization settings page, like `<your_gitea.com>/<org>/settings/actions/runners`.
  75. - Repository level: The repository settings page, like `<your_gitea.com>/<owner>/<repo>/settings/actions/runners`.
  76. If you cannot see the settings page, please make sure that you have the right permissions and that Actions have been enabled.
  77. The format of the registration token is a random string `D0gvfu2iHfUjNqCYVljVyRV14fISpJxxxxxxxxxx`.
  78. A registration token can also be obtained from the gitea [command-line interface](administration/command-line.md#actions-generate-runner-token):
  79. ```
  80. gitea --config /etc/gitea/app.ini actions generate-runner-token
  81. ```
  82. Tokens are valid for registering multiple runners, until they are revoked and replaced by a new token using the token reset link in the web interface.
  83. ### Register the runner
  84. The act runner can be registered by running the following command:
  85. ```bash
  86. ./act_runner register
  87. ```
  88. Alternatively, you can use the `--config` option to specify the configuration file mentioned in the previous section.
  89. ```bash
  90. ./act_runner --config config.yaml register
  91. ```
  92. You will be asked to input the registration information step by step. Includes:
  93. - The Gitea instance URL, like `https://gitea.com/` or `http://192.168.8.8:3000/`.
  94. - The registration token.
  95. - The runner name, which is optional. If you leave it blank, the hostname will be used.
  96. - The runner labels, which is optional. If you leave it blank, the default labels will be used.
  97. You may be confused about the runner labels, which will be explained later.
  98. If you want to register the runner in a non-interactive way, you can use arguments to do it.
  99. ```bash
  100. ./act_runner register --no-interactive --instance <instance_url> --token <registration_token> --name <runner_name> --labels <runner_labels>
  101. ```
  102. When you have registered the runner, you can find a new file named `.runner` in the current directory.
  103. This file stores the registration information.
  104. Please do not edit it manually.
  105. If this file is missing or corrupted, you can simply remove it and register again.
  106. If you want to store the registration information in another place, you can specify it in the configuration file,
  107. and don't forget to specify the `--config` option.
  108. ### Register the runner with docker
  109. If you are using the docker image, behaviour will be slightly different. Registration and running are combined into one step in this case, so you need to specify the registration information when running the act runner.
  110. ```bash
  111. docker run \
  112. -v $PWD/config.yaml:/config.yaml \
  113. -v $PWD/data:/data \
  114. -v /var/run/docker.sock:/var/run/docker.sock \
  115. -e CONFIG_FILE=/config.yaml \
  116. -e GITEA_INSTANCE_URL=<instance_url> \
  117. -e GITEA_RUNNER_REGISTRATION_TOKEN=<registration_token> \
  118. -e GITEA_RUNNER_NAME=<runner_name> \
  119. -e GITEA_RUNNER_LABELS=<runner_labels> \
  120. --name my_runner \
  121. -d gitea/act_runner:nightly
  122. ```
  123. You may notice that we have mounted the `/var/run/docker.sock` into the container.
  124. It is because the act runner will run jobs in docker containers, so it needs to communicate with the docker daemon.
  125. As mentioned, you can remove it if you want to run jobs in the host directly.
  126. To be clear, the "host" actually means the container which is running the act runner now, instead of the host machine.
  127. ### Set up the runner using docker compose
  128. You could also set up the runner using the following `docker-compose.yml`:
  129. ```yml
  130. version: "3.8"
  131. services:
  132. runner:
  133. image: gitea/act_runner:nightly
  134. environment:
  135. CONFIG_FILE: /config.yaml
  136. GITEA_INSTANCE_URL: "${INSTANCE_URL}"
  137. GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}"
  138. GITEA_RUNNER_NAME: "${RUNNER_NAME}"
  139. GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"
  140. volumes:
  141. - ./config.yaml:/config.yaml
  142. - ./data:/data
  143. - /var/run/docker.sock:/var/run/docker.sock
  144. ```
  145. ### Configuring cache when starting a Runner using docker image
  146. If you do not intend to use `actions/cache` in workflow, you can ignore this section.
  147. If you use `actions/cache` without any additional configuration, it will return the following error:
  148. > Failed to restore: getCacheEntry failed: connect ETIMEDOUT IP:PORT
  149. The error occurs because the runner container and job container are on different networks, so the job container cannot access the runner container.
  150. Therefore, it is essential to configure the cache action to ensure its proper functioning. Follow these steps:
  151. - 1.Obtain the LAN IP address of the host machine where the runner container is running.
  152. - 2.Find an available port number on the host machine where the runner container is running.
  153. - 3.Configure the following settings in the configuration file:
  154. ```yaml
  155. cache:
  156. enabled: true
  157. dir: ""
  158. # Use the LAN IP obtained in step 1
  159. host: "192.168.8.17"
  160. # Use the port number obtained in step 2
  161. port: 8088
  162. ```
  163. - 4.When starting the container, map the cache port to the host machine:
  164. ```bash
  165. docker run \
  166. --name gitea-docker-runner \
  167. -p 8088:8088 \
  168. -d gitea/act_runner:nightly
  169. ```
  170. ### Labels
  171. The labels of a runner are used to determine which jobs the runner can run, and how to run them.
  172. The default labels are `ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster`.
  173. It is a comma-separated list, and each item is a label.
  174. Let's take `ubuntu-22.04:docker://node:16-bullseye` as an example.
  175. It means that the runner can run jobs with `runs-on: ubuntu-22.04`, and the job will be run in a docker container with the image `node:16-bullseye`.
  176. If the default image is insufficient for your needs, and you have enough disk space to use a better and bigger one, you can change it to `ubuntu-22.04:docker://<the image you like>`.
  177. You can find more useful images on [act images](https://github.com/nektos/act/blob/master/IMAGES.md).
  178. If you want to run jobs in the host directly, you can change it to `ubuntu-22.04:host` or just `ubuntu-22.04`, the `:host` is optional.
  179. However, we suggest you to use a special name like `linux_amd64:host` or `windows:host` to avoid misusing it.
  180. Starting with Gitea 1.21, you can change labels by modifying `container.labels` in the runner configuration file (if you don't have a configuration file, please refer to [configuration tutorials](#configuration)).
  181. The runner will use these new labels as soon as you restart it, i.e., by calling `./act_runner daemon --config config.yaml`.
  182. ## Running
  183. After you have registered the runner, you can run it by running the following command:
  184. ```bash
  185. ./act_runner daemon
  186. # or
  187. ./act_runner daemon --config config.yaml
  188. ```
  189. The runner will fetch jobs from the Gitea instance and run them automatically.
  190. Since act runner is still in development, it is recommended to check the latest version and upgrade it regularly.
  191. ## Systemd service
  192. It is also possible to run act-runner as a [systemd](https://en.wikipedia.org/wiki/Systemd) service. Create an unprivileged `act_runner` user on your system, and the following file in `/etc/systemd/system/act_runner.service`. The paths in `ExecStart` and `WorkingDirectory` may need to be adjusted depending on where you installed the `act_runner` binary, its configuration file, and the home directory of the `act_runner` user.
  193. ```ini
  194. [Unit]
  195. Description=Gitea Actions runner
  196. Documentation=https://gitea.com/gitea/act_runner
  197. After=docker.service
  198. [Service]
  199. ExecStart=/usr/local/bin/act_runner daemon --config /etc/act_runner/config.yaml
  200. ExecReload=/bin/kill -s HUP $MAINPID
  201. WorkingDirectory=/var/lib/act_runner
  202. TimeoutSec=0
  203. RestartSec=10
  204. Restart=always
  205. User=act_runner
  206. [Install]
  207. WantedBy=multi-user.target
  208. ```
  209. Then:
  210. ```bash
  211. # load the new systemd unit file
  212. sudo systemctl daemon-reload
  213. # start the service and enable it at boot
  214. sudo systemctl enable act_runner --now
  215. ```
  216. If using Docker, the `act_runner` user should also be added to the `docker` group before starting the service. Keep in mind that this effectively gives `act_runner` root access to the system [[1]](https://docs.docker.com/engine/security/#docker-daemon-attack-surface).
  217. ## Configuration variable
  218. You can create configuration variables on the user, organization and repository level.
  219. The level of the variable depends on where you created it.
  220. ### Naming conventions
  221. The following rules apply to variable names:
  222. - Variable names can only contain alphanumeric characters (`[a-z]`, `[A-Z]`, `[0-9]`) or underscores (`_`). Spaces are not allowed.
  223. - Variable names must not start with the `GITHUB_` and `GITEA_` prefix.
  224. - Variable names must not start with a number.
  225. - Variable names are case-insensitive.
  226. - Variable names must be unique at the level they are created at.
  227. - Variable names must not be `CI`.
  228. ### Using variable
  229. After creating configuration variables, they will be automatically filled in the `vars` context.
  230. They can be accessed through expressions like `{{ vars.VARIABLE_NAME }}` in the workflow.
  231. ### Precedence
  232. If a variable with the same name exists at multiple levels, the variable at the lowest level takes precedence:
  233. A repository variable will always be chosen over an organization/user variable.