Skip to content

Commit eaa039a

Browse files
committed
feat: proxy unknown requests to default GitHub ACTIONS_RESULTS_URL & revive v1 support
1 parent ebcf828 commit eaa039a

File tree

25 files changed

+284
-1002
lines changed

25 files changed

+284
-1002
lines changed

.env

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
API_BASE_URL=http://localhost:3000
22
DEBUG=true
3-
CA_KEY_PATH=./certs/key.pem
4-
CA_CERT_PATH=./certs/cert.pem
53

64
# filesystem
75
STORAGE_DRIVER=filesystem

.github/workflows/ci-cd.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,10 @@ jobs:
5050
- name: pnpm install
5151
uses: falcondev-it/.github/actions/pnpm-install@master
5252

53-
- run: touch mock.key
54-
- run: touch mock.crt
55-
5653
- run: pnpm run test:run
5754
env:
5855
VITEST_DB_DRIVER: ${{ matrix.db-driver }}
5956
VITEST_STORAGE_DRIVER: ${{ matrix.storage-driver }}
60-
DISABLE_PROXY: true
61-
CA_CERT_PATH: mock.crt
62-
CA_KEY_PATH: mock.key
6357

6458
deploy:
6559
if: github.event.ref == 'refs/heads/dev'

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ data/
1111
.idea
1212
.DS_Store
1313
tests/temp/
14-
certs/*
15-
!certs/.gitkeep
14+
actions-runner/

README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,16 @@ This is a drop-in replacement for the official GitHub hosted cache server. It is
1212
```yaml
1313
services:
1414
cache-server:
15-
image: ghcr.io/falcondev-oss/github-actions-cache-server:latest
15+
image: ghcr.io/falcondev-oss/github-actions-cache-server
1616
ports:
1717
- '3000:3000'
18-
- '8000:8000'
1918
environment:
2019
API_BASE_URL: http://localhost:3000
21-
CA_KEY_PATH: /run/secrets/ca_key
22-
CA_CERT_PATH: /run/secrets/ca_cert
2320
volumes:
2421
- cache-data:/app/.data
25-
secrets:
26-
- ca_key
27-
- ca_cert
2822

2923
volumes:
3024
cache-data:
31-
32-
secrets:
33-
ca_key:
34-
file: ./key.pem
35-
ca_cert:
36-
file: ./cert.pem
3725
```
3826
3927
## Documentation

certs/.gitkeep

Whitespace-only changes.

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

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Getting Started
3-
description: Deploy the GitHub Actions Cache Server using Docker and use it with self-hosted runners
3+
description: Deploy the Cache Server with Docker and self-hosted runners
44
---
55

6-
The cache server comes as a Docker image and can be deployed using Docker Compose or Kubernetes.
6+
The cache server is available as a Docker image and can be deployed via Docker Compose or Kubernetes.
77

88
## 1. Deploying the Cache Server
99

@@ -13,25 +13,13 @@ services:
1313
image: ghcr.io/falcondev-oss/github-actions-cache-server:latest
1414
ports:
1515
- '3000:3000'
16-
- '8000:8000'
1716
environment:
1817
API_BASE_URL: http://localhost:3000
19-
CA_KEY_PATH: /run/secrets/ca_key
20-
CA_CERT_PATH: /run/secrets/ca_cert
2118
volumes:
2219
- cache-data:/app/.data
23-
secrets:
24-
- ca_key
25-
- ca_cert
2620

2721
volumes:
2822
cache-data:
29-
30-
secrets:
31-
ca_key:
32-
file: ./key.pem
33-
ca_cert:
34-
file: ./cert.pem
3523
```
3624
3725
### Environment Variables
@@ -42,14 +30,6 @@ secrets:
4230

4331
The base URL of your cache server. This needs to be accessible by your runners as it is used for making API requests and downloading cached files.
4432

45-
#### `CA_KEY_PATH`
46-
47-
Path to the CA key. This is used for proxying HTTPS requests which is needed for intercepting cache requests.
48-
49-
#### `CA_CERT_PATH`
50-
51-
Path to the CA certificate. This is used for proxying HTTPS requests which is needed for intercepting cache requests.
52-
5333
#### `STORAGE_DRIVER`
5434

5535
- Default: `filesystem`
@@ -78,7 +58,7 @@ variant: subtle
7858
---
7959
::
8060

81-
#### `CACHE_CLEANUP_OLDER_THAN_DAYS`
61+
#### `CLEANUP_OLDER_THAN_DAYS`
8262

8363
- Default: `90`
8464

@@ -96,11 +76,6 @@ The cron schedule for running the cache cleanup job.
9676

9777
The cron schedule for running the upload cleanup job. This job will delete any dangling (failed or incomplete) uploads.
9878

99-
#### `PROXY_PORT`
100-
101-
- Default: `8000`
102-
103-
The port the proxy server should listen on.
10479

10580
#### `NITRO_PORT`
10681

@@ -116,30 +91,48 @@ The directory to use for temporary files.
11691

11792
## 2. Setup with Self-Hosted Runners
11893

119-
### Generate CA Key and Certificate
94+
Set the `ACTIONS_RESULTS_URL` on your runner to the API URL (with a trailing slash).
12095

121-
```bash
122-
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 3650 -nodes
123-
```
96+
::u-alert
97+
---
98+
icon: 'tabler:alert-triangle'
99+
class: ring-amber-400
100+
color: amber
101+
description: Ensure ACTIONS_RESULTS_URL ends with a trailing slash.
102+
variant: subtle
103+
---
104+
::
124105

125-
This will create a `key.pem` and `cert.pem` file in the current directory. These files need to be mounted into the cache server container.
106+
### Runner Configuration
126107

127-
### Update the Dockerfile of your runner image
108+
For Docker:
128109

129110
```dockerfile [Dockerfile]
130-
# Add the CA certificate to trusted certificates
131-
RUN sudo apt-get install -y ca-certificates
132-
RUN echo "<YOUR GENERATED CERTIFICATE>" | sudo tee /usr/local/share/ca-certificates/cache-server-ca.crt
133-
RUN sudo update-ca-certificates
111+
FROM ghcr.io/actions/actions-runner:latest
112+
# Modify runner binary to retain custom ACTIONS_RESULTS_URL
113+
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
114+
```
115+
116+
For Bare Metal, similar commands apply:
117+
118+
::code-group
134119

135-
# Configure NodeJS to use the CA certificate
136-
ENV NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/cache-server-ca.crt
120+
```bash [Linux]
121+
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
122+
```
123+
124+
```bash [MacOS]
125+
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
126+
```
137127

138-
# Configure proxy
139-
ENV http_proxy=http://<your cache server>:<PROXY_PORT>
140-
ENV https_proxy=http://<your cache server>:<PROXY_PORT>
128+
```bash [Windows]
129+
[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
141130
```
142131

132+
::
133+
134+
This patch prevents the runner from overwriting your custom ACTIONS_RESULTS_URL.
135+
143136
## 3. Using the Cache Server
144137

145138
There is no need to change any of your workflows! 🔥
Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
---
22
title: How it works
3-
description: ''
3+
description: How the cache server integrates with GitHub Actions
44
---
55

6-
The cache server acts as a proxy for the actions runner. We forward all cache related requests to our cache server implementation and passthrough any non-cache related requests to the original server.
6+
## 1. Reverse-Engineering
7+
8+
We replicate the official cache API by examining runner requests and the actions/cache source. See GitHub docs on cache keys.
9+
10+
## 2. Configuring the Runner
11+
12+
The runner overrides ACTIONS_RESULTS_URL with its internal endpoint. We patched the binary by replacing "ACTIONS_RESULTS_URL" with "ACTIONS_RESULTS_ORL" (keeping the same length) to allow a custom cache URL.
13+
14+
```c#
15+
var systemConnection = ExecutionContext.Global.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
16+
Environment["ACTIONS_RUNTIME_URL"] = systemConnection.Url.AbsoluteUri;
17+
Environment["ACTIONS_RUNTIME_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
18+
if (systemConnection.Data.TryGetValue("CacheServerUrl", out var cacheUrl) && !string.IsNullOrEmpty(cacheUrl))
19+
{
20+
Environment["ACTIONS_CACHE_URL"] = cacheUrl;
21+
}
22+
if (systemConnection.Data.TryGetValue("PipelinesServiceUrl", out var pipelinesServiceUrl) && !string.IsNullOrEmpty(pipelinesServiceUrl))
23+
{
24+
Environment["ACTIONS_RUNTIME_URL"] = pipelinesServiceUrl;
25+
}
26+
if (systemConnection.Data.TryGetValue("GenerateIdTokenUrl", out var generateIdTokenUrl) && !string.IsNullOrEmpty(generateIdTokenUrl))
27+
{
28+
Environment["ACTIONS_ID_TOKEN_REQUEST_URL"] = generateIdTokenUrl;
29+
Environment["ACTIONS_ID_TOKEN_REQUEST_TOKEN"] = systemConnection.Authorization.Parameters[EndpointAuthorizationParameters.AccessToken];
30+
}
31+
if (systemConnection.Data.TryGetValue("ResultsServiceUrl", out var resultsUrl) && !string.IsNullOrEmpty(resultsUrl))
32+
{
33+
Environment["ACTIONS_RESULTS_URL"] = resultsUrl;
34+
}
35+
36+
if (ExecutionContext.Global.Variables.GetBoolean("actions_uses_cache_service_v2") ?? false)
37+
{
38+
Environment["ACTIONS_CACHE_SERVICE_V2"] = bool.TrueString;
39+
}
40+
```

docs/content/index.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ title: GitHub Actions Cache Server
22
description: Easily deploy your own GitHub actions cache without needing to change any workflow files!
33
navigation: false
44
hero:
5-
title: Self-Hosted Cache Server<br>for GitHub Actions
5+
title: Self-Hosted Cache Server for GitHub Actions
66
description: Easily deploy your own GitHub actions cache without needing to change any workflow files!
7-
orientation: vertical
7+
orientation: horizontal
88
links:
99
- label: Get started
1010
icon: i-heroicons-arrow-right-20-solid
@@ -18,25 +18,13 @@ hero:
1818
image: ghcr.io/falcondev-oss/github-actions-cache-server:latest
1919
ports:
2020
- '3000:3000'
21-
- '8000:8000'
2221
environment:
2322
API_BASE_URL: http://localhost:3000
24-
CA_KEY_PATH: /run/secrets/ca_key
25-
CA_CERT_PATH: /run/secrets/ca_cert
2623
volumes:
2724
- cache-data:/app/.data
28-
secrets:
29-
- ca_key
30-
- ca_cert
3125
3226
volumes:
3327
cache-data:
34-
35-
secrets:
36-
ca_key:
37-
file: ./key.pem
38-
ca_cert:
39-
file: ./cert.pem
4028
```
4129
features:
4230
items:

install/kubernetes/github-actions-cache-server/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.2.0
18+
version: 0.3.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to

install/kubernetes/github-actions-cache-server/templates/deployment.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ spec:
4646
- name: cache
4747
containerPort: 3000
4848
protocol: TCP
49-
- name: proxy
50-
containerPort: 8000
51-
protocol: TCP
5249
livenessProbe:
5350
{{- toYaml .Values.livenessProbe | nindent 12 }}
5451
readinessProbe:
@@ -65,8 +62,6 @@ spec:
6562
env:
6663
- name: PORT
6764
value: "3000"
68-
- name: PROXY_PORT
69-
value: "8000"
7065
- name: API_BASE_URL
7166
value: {{ default $internalApiBaseUrl .Values.apiBaseUrl }}
7267
{{- with .Values.env }}

install/kubernetes/github-actions-cache-server/templates/service.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,5 @@ spec:
1111
targetPort: cache
1212
protocol: TCP
1313
name: cache
14-
- port: {{ .Values.service.proxyPort }}
15-
targetPort: proxy
16-
protocol: TCP
17-
name: proxy
1814
selector:
1915
{{- include "github-actions-cache-server.selectorLabels" . | nindent 4 }}

install/kubernetes/github-actions-cache-server/values.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ securityContext:
4545
service:
4646
type: ClusterIP
4747
port: 80
48-
proxyPort: 8000
4948

5049
ingress:
5150
enabled: false

lib/env.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ const envSchema = z.object({
1313
STORAGE_DRIVER: z.string().toLowerCase().default('filesystem'),
1414
DB_DRIVER: z.string().toLowerCase().default('sqlite'),
1515
DEBUG: booleanSchema.default('false'),
16-
PROXY_PORT: portSchema.default(8000),
1716
NITRO_PORT: portSchema.default(3000),
18-
CA_KEY_PATH: z.string(),
19-
CA_CERT_PATH: z.string(),
2017
TEMP_DIR: z.string().default(tmpdir()),
21-
DISABLE_PROXY: booleanSchema.default('false'),
2218
})
2319

2420
const parsedEnv = envSchema.safeParse(process.env)

lib/proxy.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"execa": "^9.5.2",
3636
"h3": "npm:[email protected]",
3737
"kysely": "^0.27.5",
38-
"mockttp": "^3.16.0",
3938
"mysql2": "^3.12.0",
4039
"nitropack": "npm:[email protected]",
4140
"pg": "^8.13.1",

0 commit comments

Comments
 (0)