Last active 1 month ago

forgejo actions guide!

Revision dd00e81b2b9fc037922a22e353e7b9b79fca090c

forgejo-actions-guide.txt Raw
1============================================================
2 STEP-BY-STEP GUIDE: REGISTER & CONFIGURE FORGEJO RUNNER
3============================================================
4
5This guide walks you through the entire process: obtaining a registration
6token, registering the runner, generating a configuration file, and
7launching the runner with Docker Compose. All placeholders are clearly
8marked so you can replace them with your own values.
9
10----------------------------------------------------------------
11STEP 1: OBTAIN A REGISTRATION TOKEN FROM FORGEJO
12----------------------------------------------------------------
13
141. Open your Forgejo instance in a browser (e.g., http://YOUR_FORGEJO_URL).
152. Log in as an administrator.
163. Navigate to: Site Administration → Actions → Runners.
174. Click the "Create Runner" button.
185. Copy the generated token. It will look like a long alphanumeric string.
19
20 Example placeholder: YOUR_REGISTRATION_TOKEN
21
22----------------------------------------------------------------
23STEP 2: REGISTER THE RUNNER (CREATE .runner FILE)
24----------------------------------------------------------------
25
26Create a working directory and register the runner using the Docker image.
27
28mkdir -p ~/forgejo-runner
29cd ~/forgejo-runner
30
31mkdir -p data cache
32
33Run the registration command, replacing the placeholders:
34
35docker run -it --rm \
36 -v $(pwd)/data:/data \
37 -w /data \
38 --user root \
39 data.forgejo.org/forgejo/runner:4.0.0 \
40 forgejo-runner register \
41 --no-interactive \
42 --token YOUR_REGISTRATION_TOKEN \
43 --name YOUR_RUNNER_NAME \
44 --instance http://YOUR_FORGEJO_URL \
45 --labels YOUR_LABEL
46
47Placeholder explanations:
48 YOUR_REGISTRATION_TOKEN – the token you copied from Forgejo
49 YOUR_RUNNER_NAME – a name you choose (e.g., "websites")
50 YOUR_FORGEJO_URL – the URL of your Forgejo instance (e.g., "192.168.2.76:3000")
51 YOUR_LABEL – one or more labels (e.g., "websites" or "ubuntu-latest,self-hosted")
52
53After success, a file data/.runner is created. This stores the runner's
54permanent credentials.
55
56Verify:
57ls -la data/.runner
58
59----------------------------------------------------------------
60STEP 3: GENERATE AND CONFIGURE config.yaml
61----------------------------------------------------------------
62
63If you don't already have a config.yaml, generate the default one:
64
65docker run --rm \
66 -v $(pwd)/data:/data \
67 -w /data \
68 data.forgejo.org/forgejo/runner:4.0.0 \
69 forgejo-runner generate-config > data/config.yaml
70
71Now open data/config.yaml and customize it. Below is a complete example
72based on a typical setup. Replace all placeholders (marked with YOUR_*)
73with your actual values.
74
75----------------------------------------------------------------
76EXAMPLE config.yaml (customizable)
77----------------------------------------------------------------
78
79# --------------------------- REQUIRED ---------------------------
80# The URL of your Forgejo instance
81instance: http://YOUR_FORGEJO_URL
82
83# The runner token (can be the registration token or the token from .runner)
84token: "YOUR_RUNNER_TOKEN"
85
86# --------------------------- LOGGING ---------------------------
87log:
88 level: info # options: trace, debug, info, warn, error, fatal
89
90# --------------------------- RUNNER SETTINGS ---------------------------
91runner:
92 file: .runner # path to registration file (relative to /data)
93 capacity: 1 # number of concurrent tasks
94 timeout: 30m # max job duration (customize as needed)
95 shutdown_timeout: 30m # graceful shutdown timeout
96 insecure: true # set to true if using HTTP (skip TLS verification)
97 fetch_timeout: 30s
98 fetch_interval: 60s
99 report_interval: 10s
100
101 # Labels determine which jobs this runner picks up.
102 # Format: "label:executor". Executor can be "host" (run on host) or "docker://image".
103 # The label(s) must match the `runs-on` value in your workflows.
104 labels:
105 - "YOUR_LABEL:host" # e.g., "websites:host"
106
107# --------------------------- CACHE ---------------------------
108cache:
109 enabled: true
110 dir: "" # leave empty to use default $HOME/.cache/actcache
111
112# --------------------------- CONTAINER EXECUTOR OPTIONS ----------------
113container:
114 # Set privileged to true if your workflows need Docker-in-Docker.
115 # If you use a separate docker-in-docker service, you can keep it false.
116 privileged: false
117 # Allow mounting any volume (useful for host directories)
118 valid_volumes:
119 - '**'
120 docker_host: "" # auto-detect; you can override with environment variable DOCKER_HOST
121 force_pull: false
122
123# --------------------------- HOST EXECUTOR OPTIONS --------------------
124host:
125 workdir_parent: "" # parent directory for job workspaces (default ~/.cache/act/)
126
127---
128
129Save the file. The most important fields to adjust are:
130- instance
131- token (or remove after registration)
132- runner.labels (must match your workflow's `runs-on`)
133- container.privileged (set to true if you run docker commands inside jobs)
134
135----------------------------------------------------------------
136STEP 4: CREATE DOCKER-COMPOSE.YML
137----------------------------------------------------------------
138
139Create a docker-compose.yml file in the same directory (~/forgejo-runner)
140with the following content. Replace YOUR_LABEL and any host paths.
141
142---
143version: '3.8'
144
145services:
146 docker-in-docker:
147 image: docker:dind
148 container_name: docker_dind
149 privileged: true
150 command: ['dockerd', '-H', 'tcp://0.0.0.0:2375', '--tls=false']
151 restart: unless-stopped
152
153 runner:
154 image: data.forgejo.org/forgejo/runner:4.0.0
155 container_name: runner
156 depends_on:
157 docker-in-docker:
158 condition: service_started
159 environment:
160 DOCKER_HOST: tcp://docker-in-docker:2375
161 user: 0:0 # run as root to avoid permission issues
162 volumes:
163 - ./data:/data # config and .runner
164 - ./cache:/cache # optional cache directory
165 # Mount any host directories your workflows need to access:
166 # - /host/path:/container/path
167 # Example mounts (uncomment and adjust):
168 # - /var/www/YOUR_PROJECT:/var/www/YOUR_PROJECT
169 # - /home/user/shared:/shared
170 restart: unless-stopped
171 command: /bin/sh -c "
172 apk update && apk add --no-cache nodejs npm &&
173 sleep 5 &&
174 forgejo-runner daemon --config /data/config.yaml
175 "
176---
177
178Note: The command installs Node.js and npm – required for actions like
179actions/checkout. If you prefer a custom image with Node.js pre-installed,
180you can build one, but this method works fine.
181
182----------------------------------------------------------------
183STEP 5: START THE RUNNER
184----------------------------------------------------------------
185
186Launch all services in detached mode:
187
188docker compose up -d
189
190Check the logs to confirm everything is running:
191
192docker compose logs -f runner
193
194Expected output:
195 "runner: YOUR_RUNNER_NAME, with version: v4.0.0, with labels: [YOUR_LABEL], declared successfully"
196 "[poller 0] launched"
197
198If you see errors, review the logs and verify your config.
199
200----------------------------------------------------------------
201STEP 6: TEST WITH A SAMPLE WORKFLOW
202----------------------------------------------------------------
203
204Create a test workflow in any repository on your Forgejo instance.
205Place the file at: .forgejo/workflows/test.yml
206
207---
208on: [push]
209jobs:
210 test:
211 runs-on: YOUR_LABEL # must match the label you registered
212 steps:
213 - name: Hello
214 run: echo "Runner is alive!"
215 - name: Check Node.js
216 run: node --version
217 - name: Check Docker
218 run: docker info
219---
220
221Commit and push the file. The runner should pick up the job automatically.
222
223Watch the logs to see the job progress:
224
225docker compose logs -f runner
226
227----------------------------------------------------------------
228TROUBLESHOOTING COMMON ISSUES
229----------------------------------------------------------------
230
231| Symptom | Solution |
232|------------------------------------|--------------------------------------------------------------------------|
233| "permission denied" on .runner | Use --user root in registration or set user: 0:0 in docker-compose. |
234| "cannot find node" | Ensure Node.js is installed (the command above adds it). |
235| Runner stays idle | Check that the label in your workflow exactly matches the runner's label.|
236| "invalid token" | Generate a new token in Forgejo admin and re-register. |
237| Docker errors in jobs | Verify DOCKER_HOST=tcp://docker-in-docker:2375 is set. |
238
239----------------------------------------------------------------
240QUICK REFERENCE – PLACEHOLDERS USED IN THIS GUIDE
241----------------------------------------------------------------
242
243| Placeholder | Description |
244|----------------------------|---------------------------------------------------------------------------|
245| YOUR_FORGEJO_URL | The IP/hostname and port of your Forgejo instance (e.g., 192.168.2.76:3000) |
246| YOUR_REGISTRATION_TOKEN | The one-time token from Forgejo admin → Actions → Runners → Create Runner |
247| YOUR_RUNNER_NAME | A friendly name for the runner (appears in admin UI) |
248| YOUR_LABEL | Label used in workflows (e.g., "websites" or "ubuntu-latest") |
249| YOUR_RUNNER_TOKEN | The permanent token (usually the same as registration, or taken from .runner) |
250
251----------------------------------------------------------------
252END OF GUIDE
253----------------------------------------------------------------