先上官网链接Gitea-Actions快速入门、Act Runner。
为了避免出现不兼容等问题,我们先升级下gitea到最新稳定版本。
搭建gitea-runner
1services:2 runner:3 image: gitea/act_runner:0.2.114 environment:5 CONFIG_FILE: /config.yaml # 配置文件位置6 GITEA_INSTANCE_URL: "${INSTANCE_URL}" # gitea实例的地址7 GITEA_RUNNER_REGISTRATION_TOKEN: "${REGISTRATION_TOKEN}" # 注册token8 GITEA_RUNNER_NAME: "${RUNNER_NAME}"9 GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"10 volumes:11 - ./config.yaml:/config.yaml12 - ./data:/data13 - /var/run/docker.sock:/var/run/docker.sock
获取注册令牌
Runner级别决定了从哪里获取注册令牌。
- 实例级别:管理员设置页面,例如 <your_gitea.com>/admin/actions/runners。
- 组织级别:组织设置页面,例如 <your_gitea.com>/
/settings/actions/runners。 - 存储库级别:存储库设置页面,例如 <your_gitea.com>/
/ /settings/actions/runners。
获取注册令牌的地址方式如下,使用管理员账号登录gitea后访问上面的地址<your_gitea.com>/admin/actions/runners
就可以看到了。
创建runner
添加容器的配置文件:
注意这个配置文档中可以启用cache功能。
1# Example configuration file, it's safe to copy this as the default config file without any modification.2
3log:4 # The level of logging, can be trace, debug, info, warn, error, fatal5 level: info6
7runner:8 # Where to store the registration result.9 file: .runner10 # Execute how many tasks concurrently at the same time.11 capacity: 112 # Extra environment variables to run jobs.13 envs:14 A_TEST_ENV_NAME_1: a_test_env_value_115 A_TEST_ENV_NAME_2: a_test_env_value_240 collapsed lines
16 # Extra environment variables to run jobs from a file.17 # It will be ignored if it's empty or the file doesn't exist.18 env_file: .env19 # The timeout for a job to be finished.20 # Please note that the Gitea instance also has a timeout (3h by default) for the job.21 # So the job could be stopped by the Gitea instance if it's timeout is shorter than this.22 timeout: 3h23 # Whether skip verifying the TLS certificate of the Gitea instance.24 insecure: false25 # The timeout for fetching the job from the Gitea instance.26 fetch_timeout: 5s27 # The interval for fetching the job from the Gitea instance.28 fetch_interval: 2s29
30cache:31 # Enable cache server to use actions/cache.32 enabled: true33 # The directory to store the cache data.34 # If it's empty, the cache data will be stored in $HOME/.cache/actcache.35 dir: ""36 # The host of the cache server.37 # It's not for the address to listen, but the address to connect from job containers.38 # So 0.0.0.0 is a bad choice, leave it empty to detect automatically.39 host: 0.0.0.040 # The port of the cache server.41 # 0 means to use a random available port.42 port: 808843
44container:45 # Specifies the network to which the container will connect.46 # Could be host, bridge or the name of a custom network.47 # If it's empty, act_runner will create a network automatically.48 network: ""49 # Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).50 privileged: false51 # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway).52 options:53 # The parent directory of a job's working directory.54 # If it's empty, /workspace will be used.55 workdir_parent:
修改官方的docker-compose.yml文件:
1services:2 runner:3 image: gitea/act_runner:0.2.114 environment:5 CONFIG_FILE: /config.yaml6 GITEA_INSTANCE_URL: https://gitea.cirry.cn # gitea实例的地址7 GITEA_RUNNER_REGISTRATION_TOKEN: n9avKdN11dTb6qiO9oHx5WHKg9yQ8igXopeKA9vz # 注册token8 # GITEA_RUNNER_NAME: "${RUNNER_NAME}"9 # GITEA_RUNNER_LABELS: "${RUNNER_LABELS}"10 ports:11 - "8088:8088"12 volumes:13 - ./config.yaml:/config.yaml14 - ./data:/data15 - /var/run/docker.sock:/var/run/docker.sock
修改上面两行高亮的参数后启动act_runner,启动完成后刷新获取注册token的runner页面,可以看到已经有一个runner创建成功了。
使用Actions
首先你需要在你的仓库设置中打开actions功能,参考这里:使用Actions。