Skip to content

Commit 53008e9

Browse files
feat!: github cache service v2 support (#95)
1 parent 9923a2a commit 53008e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7703
-6631
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
URL_ACCESS_TOKEN=test_token
21
API_BASE_URL=http://localhost:3000
32
DEBUG=true
43

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ ENV BUILD_HASH=${BUILD_HASH}
55

66
WORKDIR /app
77

8-
RUN npm install -g pnpm@latest-9
8+
RUN npm install -g pnpm@latest-10
99

1010
COPY package.json pnpm-lock.yaml .npmrc ./
11-
COPY patches patches
1211

1312
RUN --mount=type=cache,target=/root/.local/share/pnpm/store pnpm fetch --prod
1413

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ services:
1818
ports:
1919
- '3000:3000'
2020
environment:
21-
URL_ACCESS_TOKEN: random_token
2221
API_BASE_URL: http://localhost:3000
2322
volumes:
2423
- cache-data:/app/.data

docs/content/1.getting-started/1.index.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ services:
1616
ports:
1717
- '3000:3000'
1818
environment:
19-
URL_ACCESS_TOKEN: random_token
2019
API_BASE_URL: http://localhost:3000
2120
volumes:
2221
- cache-data:/app/.data
@@ -27,10 +26,6 @@ volumes:
2726
2827
### Environment Variables
2928
30-
#### `URL_ACCESS_TOKEN`
31-
32-
This token is used to authenticate runtime requests to the cache server. It should be a long random string. It is part of the URL used to access the cache server because we cannot use cookies or headers for authentication.
33-
3429
#### `API_BASE_URL`
3530

3631
- Example: `http://localhost:3000`
@@ -83,23 +78,23 @@ To leverage the GitHub Actions Cache Server with your self-hosted runners, you'l
8378

8479
### Configuring Environment Variables on Self-Hosted Runners
8580

86-
**`ACTIONS_CACHE_URL`**: This tells your self-hosted runner where to send cache requests. Set this environment variable to the `API_BASE_URL` of your cache server with the `URL_ACCESS_TOKEN` as first path parameter, making sure to include a trailing slash.
81+
**`ACTIONS_RESULTS_URL`**: This tells your self-hosted runner where to send cache requests. Set this environment variable to the `API_BASE_URL` of your cache server, making sure to include a trailing slash.
8782

88-
For example, if your cache server's `API_BASE_URL` is `http://localhost:3000` and your `URL_ACCESS_TOKEN` is `random_token`, you would set `ACTIONS_CACHE_URL` to `http://localhost:3000/random_token/`.
83+
For example, if your cache server's `API_BASE_URL` is `http://localhost:3000`, you would set `ACTIONS_RESULTS_URL` to `http://localhost:3000/`.
8984

9085
::u-alert
9186
---
9287
icon: 'tabler:alert-triangle'
9388
class: ring-amber-400
9489
color: amber
95-
description: Make sure to add a trailing slash to the ACTIONS_CACHE_URL environment variable.
90+
description: Make sure to add a trailing slash to the ACTIONS_RESULTS_URL environment variable.
9691
variant: subtle
9792
---
9893
::
9994

10095
### Getting the Actions Runner to Use the Cache Server
10196

102-
The default self-hosted runner overwrites the `ACTIONS_CACHE_URL` environment variable with the GitHub-hosted cache server URL. To get the runner to use your self-hosted cache server, you'll need to modify the runner binary:
97+
The default self-hosted runner overwrites the `ACTIONS_RESULTS_URL` environment variable with the GitHub-hosted cache server URL. To get the runner to use your self-hosted cache server, you'll need to modify the runner binary:
10398

10499
#### Docker
105100

@@ -109,28 +104,28 @@ Just add the following lines to your Dockerfile:
109104
FROM ghcr.io/actions/actions-runner:latest
110105
111106
# modify actions runner binaries to allow custom cache server implementation
112-
RUN sed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /home/runner/bin/Runner.Worker.dll
107+
RUN sed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x52\x00\x45\x00\x53\x00\x55\x00\x4C\x00\x54\x00\x53\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x52\x00\x45\x00\x53\x00\x55\x00\x4C\x00\x54\x00\x53\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /home/runner/bin/Runner.Worker.dll
113108
```
114109

115110
#### Bare Metal
116111

117112
::code-group
118113

119114
```bash [Linux]
120-
sed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /path_to_your_runner/bin/Runner.Worker.dll
115+
sed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x52\x00\x45\x00\x53\x00\x55\x00\x4C\x00\x54\x00\x53\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x52\x00\x45\x00\x53\x00\x55\x00\x4C\x00\x54\x00\x53\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /path_to_your_runner/bin/Runner.Worker.dll
121116
```
122117

123118
```bash [MacOS]
124-
gsed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x43\x00\x41\x00\x43\x00\x48\x00\x45\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /path_to_your_runner/bin/Runner.Worker.dll
119+
gsed -i 's/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x52\x00\x45\x00\x53\x00\x55\x00\x4C\x00\x54\x00\x53\x00\x5F\x00\x55\x00\x52\x00\x4C\x00/\x41\x00\x43\x00\x54\x00\x49\x00\x4F\x00\x4E\x00\x53\x00\x5F\x00\x52\x00\x45\x00\x53\x00\x55\x00\x4C\x00\x54\x00\x53\x00\x5F\x00\x4F\x00\x52\x00\x4C\x00/g' /path_to_your_runner/bin/Runner.Worker.dll
125120
```
126121

127122
```bash [Windows]
128-
[byte[]] -split (((Get-Content -Path ./bin/Runner.Worker.dll -Encoding Byte) | ForEach-Object ToString X2) -join '' -Replace '41004300540049004F004E0053005F00430041004300480045005F00550052004C00','41004300540049004F004E0053005F00430041004300480045005F004F0052004C00' -Replace '..', '0x$& ') | Set-Content -Path /path_to_your_runner/bin/Runner.Worker.dll -Encoding Byte
123+
[byte[]] -split (((Get-Content -Path ./bin/Runner.Worker.dll -Encoding Byte) | ForEach-Object ToString X2) -join '' -Replace '41004300540049004F004E0053005F0052004500530055004C00540053005F00550052004C00','41004300540049004F004E0053005F0052004500530055004C00540053005F004F0052004C00' -Replace '..', '0x$& ') | Set-Content -Path /path_to_your_runner/bin/Runner.Worker.dll -Encoding Byte
129124
```
130125

131126
::
132127

133-
This will replace the strings `ACTIONS_CACHE_URL` with `ACTIONS_CACHE_ORL` in the runner binary. This will prevent the runner from overwriting the `ACTIONS_CACHE_URL` environment variable and allow it to use your self-hosted cache server.
128+
This will replace the strings `ACTIONS_RESULTS_URL` with `ACTIONS_RESULTS_ORL` in the runner binary. This will prevent the runner from overwriting the `ACTIONS_RESULTS_URL` environment variable and allow it to use your self-hosted cache server.
134129

135130
Doing it this way is a bit of a hack, but it's easier than compiling your own runner binary from source and works great.
136131

docs/content/1.getting-started/4.how-it-works.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ GitHub also has very good [documentation](https://docs.github.com/en/actions/usi
1111

1212
## 2. Getting the actions runner to use our cache server
1313

14-
The whole idea of creating a self-hosted cache server originated from the discovery that the official `actions/cache` action uses an environment variable `ACTIONS_CACHE_URL` to determine where to send cache requests. This means that we can simply set this environment variable to the base URL of our cache server and the runner will start using it ...right?
14+
The whole idea of creating a self-hosted cache server originated from the discovery that the official `actions/cache` action uses an environment variable `ACTIONS_RESULTS_URL` to determine where to send cache requests. This means that we can simply set this environment variable to the base URL of our cache server and the runner will start using it ...right?
1515

16-
Well, not exactly. The `actions/cache` action uses the `ACTIONS_CACHE_URL` environment variable to determine the base URL of the cache server but we cannot overrid this environment variable in any way.
16+
Well, not exactly. The `actions/cache` action uses the `ACTIONS_RESULTS_URL` environment variable to determine the base URL of the cache server but we cannot overrid this environment variable in any way.
1717

18-
The default actions runner always overrides the `ACTIONS_CACHE_URL` environment variable with an internal URL that points to the official GitHub cache server. This is the code that does it:
18+
The default actions runner always overrides the `ACTIONS_RESULTS_URL` environment variable with an internal URL that points to the official GitHub cache server. This is the code that does it:
1919

2020
```c#
2121
var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
@@ -25,6 +25,10 @@ if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !st
2525
{
2626
Environment["ACTIONS_CACHE_URL"] = cacheUrl;
2727
}
28+
if (systemConnection.Data.TryGetValue("PipelinesServiceUrl", out var pipelinesServiceUrl) && !string.IsNullOrEmpty(pipelinesServiceUrl))
29+
{
30+
Environment["ACTIONS_RUNTIME_URL"] = pipelinesServiceUrl;
31+
}
2832
if (systemConnection.Data.TryGetValue("GenerateIdTokenUrl", out var generateIdTokenUrl) && !string.IsNullOrEmpty(generateIdTokenUrl))
2933
{
3034
Environment["ACTIONS_ID_TOKEN_REQUEST_URL"] = generateIdTokenUrl;
@@ -34,8 +38,13 @@ if (systemConnection.Data.TryGetValue("ResultsServiceUrl", out var resultsUrl) &
3438
{
3539
Environment["ACTIONS_RESULTS_URL"] = resultsUrl;
3640
}
41+
42+
if (ExecutionContext.Global.Variables.GetBoolean("actions_uses_cache_service_v2") ?? false)
43+
{
44+
Environment["ACTIONS_CACHE_SERVICE_V2"] = bool.TrueString;
45+
}
3746
```
3847

39-
The line `Environment["ACTIONS_CACHE_URL"] = cacheUrl;` is the one that overrides the `ACTIONS_CACHE_URL` environment variable with the internal URL.
48+
The line `Environment["ACTIONS_RESULTS_URL"] = resultsUrl;` is the one that overrides the `ACTIONS_RESULTS_URL` environment variable with the internal URL.
4049

41-
To allow overriding the `ACTIONS_CACHE_URL` environment variable, we need to modify the runner binary. This is a bit tricky because the runner is a compiled binary and we cannot simply modify the source code and recompile it. We need to modify the binary itself. So we did just that. We replaced the string `ACTIONS_CACHE_URL` with `ACTIONS_CACHE_ORL` (being careful to keep the same length) in the runner binary. This way, the runner will not override the `ACTIONS_CACHE_URL` environment variable and we can set it to our cache server's base URL.
50+
To allow overriding the `ACTIONS_RESULTS_URL` environment variable, we need to modify the runner binary. This is a bit tricky because the runner is a compiled binary and we cannot simply modify the source code and recompile it. We need to modify the binary itself. So we did just that. We replaced the string `ACTIONS_RESULTS_URL` with `ACTIONS_RESULTS_ORL` (being careful to keep the same length) in the runner binary. This way, the runner will not override the `ACTIONS_RESULTS_URL` environment variable and we can set it to our cache server's base URL.

docs/content/2.storage-drivers/gcs.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ services:
3030
ports:
3131
- '3000:3000'
3232
environment:
33-
URL_ACCESS_TOKEN: random_token
3433
API_BASE_URL: http://localhost:3000
3534

3635
STORAGE_DRIVER: gcs

docs/content/2.storage-drivers/s3.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ services:
2020
ports:
2121
- '3000:3000'
2222
environment:
23-
URL_ACCESS_TOKEN: random_token
2423
API_BASE_URL: http://localhost:3000
2524

2625
STORAGE_DRIVER: s3
@@ -57,7 +56,6 @@ services:
5756
ports:
5857
- '3000:3000'
5958
environment:
60-
URL_ACCESS_TOKEN: random_token
6159
API_BASE_URL: http://localhost:3000
6260
6361
STORAGE_DRIVER: s3

docs/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
"typecheck": "nuxt typecheck"
1313
},
1414
"dependencies": {
15-
"@iconify-json/ph": "^1.2.1",
16-
"@iconify-json/simple-icons": "^1.2.12",
15+
"@iconify-json/ph": "^1.2.2",
16+
"@iconify-json/simple-icons": "^1.2.24",
1717
"@nuxt/content": "^2.13.4",
18-
"@nuxt/fonts": "^0.10.2",
19-
"@nuxt/ui-pro": "^1.5.0",
20-
"nuxt": "^3.14.1592",
18+
"@nuxt/fonts": "^0.10.3",
19+
"@nuxt/ui-pro": "^1.7.0",
20+
"nuxt": "^3.15.4",
2121
"ufo": "^1.5.4",
22-
"vite-plugin-wasm": "^3.3.0"
22+
"vite-plugin-wasm": "^3.4.1"
2323
},
2424
"devDependencies": {
25+
"@iconify-json/tabler": "^1.2.16",
2526
"@nuxthq/studio": "^2.2.1",
26-
"vue-tsc": "^2.1.10"
27+
"vue-tsc": "^2.2.0"
2728
}
2829
}

0 commit comments

Comments
 (0)