Skip to content

Commit 48a4385

Browse files
committed
Switch seaweedfs to HTTPS / TLS
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 977aec9 commit 48a4385

File tree

1 file changed

+47
-27
lines changed

1 file changed

+47
-27
lines changed

docs/tasks/local-github-cache.md

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,43 @@
22

33
The cache for GitHub Actions can speed up CI/CD pipelines. Hosted runners are placed close to the cache which means the latency is very low. Self-hosted runners can also make good use of this cache. Just like caching container images on the host in [a registry mirror](/tasks/registry-mirror/), you can also get a speed boost over the hosted cache by running your own cache directly on the host.
44

5-
To improve cache speeds with Actuated runners you can run a self-hosted S3 server and switch out the official [actions/cache@v3](https://github.com/actions/cache) with [tespkg/actions-cache@v1](https://github.com/tespkg/actions-cache). The tespkg/actions-cache@v1 can target S3 instead of the proprietary GitHub cache.
5+
To improve cache speeds with Actuated runners you can run a self-hosted S3 server and switch out the official [actions/cache@v3](https://github.com/actions/cache) with [tespkg/actions-cache@v1](https://github.com/tespkg/actions-cache). The tespkg/actions-cache@v1 can target S3 instead of GitHub's proprietary, hosted cache.
66

77
You can run the cache on every actuated server for the speed of communicating over a loopback network, or you can run it on a single dedicated server that's placed in the same region as the actuated servers, which will still be very quick.
88

9-
> Note that if you have multiple actuated hosts consider running a single dedicated server for the cache. Subsequent jobs can be scheduled to different hosts so there is no guarantee the cache is populated when running a cache on every actuated server.
9+
> Note: This guide sets up an S3 cache on each actuated server, so you may still get a cache miss from time to time. If you have more than one actuated server, you may wish to deploy a VM or a dedicated host in the same private network to host the S3 cache. Reach out if you'd like any help with this.
1010
11-
## Set up an S3 cache
11+
## Install an S3-compatible server
1212

13-
There are a couple of options to run a self-hosted S3 server, most notably [Seaweedfs](https://github.com/seaweedfs/seaweedfs) and [Minio](https://min.io/).
13+
There are a few popular options when it comes to self-hosting S3, including [Seaweedfs](https://github.com/seaweedfs/seaweedfs) (Apache-2.0) and [Minio](https://min.io/) (AGPLv3).
1414

15-
This guide will cover the setup of Seaweedfs but any S3 compatible service will work in a very similar way.
15+
This guide will cover the setup of Seaweedfs but any S3 compatible service will work in a very similar way: install the service, set its storage location, and bind it only the IP address of the actuated microVM bridge.
1616

1717
### Install Seaweedfs
1818

1919
Seaweedfs is distributed as a static Go binary, so it can be installed with [arkade](https://github.com/alexellis/arkade), or from the [GitHub releases page](https://github.com/seaweedfs/seaweedfs/releases).
2020

21+
Port 443 will be used to expose the S3 server's API to the actuated microVMs, and the built-in TLS certificate will be used from `/var/lib/actuated/certs/server.crt` and `/var/lib/actuated/certs/server.key` to serve traffic over TLS, to ensure encryption.
22+
23+
Just like cloud-based S3, an access key and secret key will be required. You can provide those or generate them using the provided `openssl` commands. These then need to be added as secrets for the workflows via the repository settings or the organisation's settings.
24+
25+
If you don't already have arkade, you can install it via `curl -sLS https://get.arkade.dev | sudo sh`.
26+
27+
Next, download the binary and move it to `/usr/local/bin`:
28+
2129
```sh
2230
arkade get seaweedfs
2331
sudo mv ~/.arkade/bin/seaweedfs /usr/local/bin
2432
```
2533

2634
Define a secret key and access key to be used from the CI jobs in the `/etc/seaweedfs/s3.conf` file.
2735

28-
Generate a secret key: `openssl rand -hex 16 > secret_key`
29-
3036
```bash
31-
export ACCESS_KEY="" # Replace with your access key
32-
export SECRET_KEY="$(cat ~/secret_key)"
37+
openssl rand -hex 16 > ~/seaweed_access_key
38+
openssl rand -hex 16 > ~/seaweed_secret_key
39+
40+
export ACCESS_KEY="$(cat ~/seaweed_access_key)"
41+
export SECRET_KEY="$(cat ~/seaweed_secret_key)"
3342

3443
cat >> /tmp/s3.conf <<EOF
3544
{
@@ -54,11 +63,11 @@ cat >> /tmp/s3.conf <<EOF
5463
}
5564
EOF
5665

57-
mkdir -p /etc/seaweedfs
66+
sudo mkdir -p /etc/seaweedfs
5867
sudo mv /tmp/s3.conf /etc/seaweedfs/s3.conf
5968
```
6069

61-
Install and start Seaweedfs with a systemd unit file:
70+
Create a systemd unit file to start Seaweedfs:
6271

6372
```bash
6473
(
@@ -69,30 +78,37 @@ After=network.target
6978
7079
[Service]
7180
User=root
72-
ExecStart=/usr/local/bin/seaweedfs server -ip=192.168.128.1 -volume.max=0 -volume.fileSizeLimitMB=2048 -dir=/home/runner-cache -s3 -s3.config=/etc/seaweedfs/s3.conf
81+
ExecStart=/usr/local/bin/seaweedfs server -ip=192.168.128.1 -volume.max=0 -volume.fileSizeLimitMB=2048 -dir=/var/run/s3/cache -s3 -s3.config=/etc/seaweedfs/s3.conf -s3.key.file=/var/lib/actuated/certs/server.key -s3.cert.file=/var/lib/actuated/certs/server.crt -s3.port.https 443
7382
Restart=on-failure
7483
7584
[Install]
7685
WantedBy=multi-user.target
7786
EOF
7887

79-
mkdir -p /home/runner-cache
88+
sudo mkdir -p /var/run/s3/cache
8089
sudo mv /tmp/seaweedfs.service /etc/systemd/system/seaweedfs.service
8190
sudo systemctl daemon-reload
82-
sudo systemctl enable seaweedfs --now
91+
sudo systemctl enable seaweedfs
92+
sudo systemctl restart seaweedfs --now
8393
)
8494
```
8595

96+
The `/var/run/s3/cache` folder will be used for storing files created by the S3 server.
97+
8698
We have set `-volume.max=0 -volume.fileSizeLimitMB=2048` to minimize the amount of space used and to allow large zip files of up to 2GB, but you can change this to suit your needs. See `seaweedfs server --help` for more options.
8799

88-
The `ip` only needs to be set to `192.168.128.1` if you are running the cache directly on the agent host. If you set up the cache to be accessible by multiple Actuated runner hosts use the appropriate interface IP address.
100+
The `-ip` flag binds the S3 API server to the actuated bridge IP address. This IP address is accessible to microVMs, but hidden from the Internet. As mentioned above, TLS is enabled via a certificate and key provided by actuated, then the S3 server is exposed on port 443. You can change the port if you wish.
89101

90-
Check the status with:
102+
Check the status of the service with:
91103

92104
```bash
93105
sudo journalctl -u seaweedfs -f
94106
```
95107

108+
If you see an error such as `listen tcp 192.168.128.1: bind: cannot assign requested address`. This will disappear when actuated is started.
109+
110+
It may also take a couple of minutes for the service to settle and be ready to accept connections.
111+
96112
## Use the self-hosted cache
97113

98114
To start using the local cache you will need to replace `actions/cache@v3` with `tespkg/actions-cache@v1` and add `tespkg/actions-cache` specific properties in addition to the `actions/cache` properties in your cache steps.
@@ -113,14 +129,13 @@ jobs:
113129
- name: Setup Golang
114130
uses: actions/setup-go@v3
115131
with:
116-
go-version: ~1.21
132+
go-version: ~1.22
117133
cache: false
118134
- name: Setup Golang caches
119135
uses: tespkg/actions-cache@v1
120136
with:
121137
endpoint: "192.168.128.1"
122-
port: 8333
123-
insecure: true
138+
port: 443
124139
accessKey: ${{ secrets.ACTIONS_CACHE_ACCESS_KEY }}
125140
secretKey: ${{ secrets.ACTIONS_CACHE_SECRET_KEY }}
126141
bucket: actuated-runners
@@ -139,10 +154,9 @@ jobs:
139154
`tespkg/actions-cache` specific properties:
140155

141156
* `use-fallback` - option means that if Seaweedfs is not installed on the host, or is inaccessible, the action will fall back to using the GitHub cache.
142-
* `bucket` - the name of the bucket to use in Seaweedfs
157+
* `bucket` - the name of the bucket to use in Seaweedfs, this could be the same for every job, different per repository or per workflow.
143158
* `region` - the bucket region - use `local` when running your own S3 cache locally.
144-
* `accessKey` and `secretKey` - the credentials to use to access the bucket - we'd recommend using an organisation-level secret for this.
145-
* `insecure` - use http instead of https. You may want to create a self-signed certificate for the S3 service and set `insecure: false` to ensure that the connection is encrypted. If you're running builds within private repositories, tampering is unlikely.
159+
* `accessKey` and `secretKey` - the credentials to use to access the bucket, it's easier to define these secrets at the organisation level than on each repository
146160

147161
Checkout the list of `actions/cache` [examples](https://github.com/actions/cache/blob/main/examples.md) to configure caching for different languages and frameworks. Remember to replace `actions/cache@v3` with `tespkg/actions-cache@v1` and add the additional properties mentioned above.
148162

@@ -163,8 +177,7 @@ jobs:
163177
- uses: tespkg/actions-cache@v1
164178
with:
165179
endpoint: "192.168.128.1"
166-
port: 8333
167-
insecure: true
180+
port: 443
168181
accessKey: ${{ secrets.ACTIONS_CACHE_ACCESS_KEY }}
169182
secretKey: ${{ secrets.ACTIONS_CACHE_SECRET_KEY }}
170183
bucket: actuated-runners
@@ -204,8 +217,7 @@ jobs:
204217
- uses: tespkg/actions-cache@v1
205218
with:
206219
endpoint: "192.168.128.1"
207-
port: 8333
208-
insecure: true
220+
port: 443
209221
accessKey: ${{ secrets.ACTIONS_CACHE_ACCESS_KEY }}
210222
secretKey: ${{ secrets.ACTIONS_CACHE_SECRET_KEY }}
211223
bucket: actuated-runners
@@ -225,7 +237,15 @@ jobs:
225237
pnpm install --frozen-lockfile --prefer-offline
226238
```
227239

240+
## Wrapping up
241+
242+
One of the most contentious issues for self-hosted GitHub Actions runners is the speed a reliability of depending on the hosted caches. This is not a problem when using hosted runners, but when running outside of Azure's backbone, the latency is often a problem.
243+
244+
In a short period of time, we solved any potential latency or reliability by setting up our own S3 server using fast local storage. The default cache action was swapped for one with a compatible syntax, and we were able to cache the git checkout, *node_modules*, Go cache, and other common dependencies.
245+
246+
If you'd like a hand with this, feel free to reach out to the team.
247+
228248
## Further reading
229249

230250
* From our blog: [Fixing the cache latency for self-hosted GitHub Actions](https://actuated.com/blog/faster-self-hosted-cache)
231-
* A primer on using the GitHub Actions cache: [Using caching in builds](/examples/github-actions-cache/)
251+
* A primer on using the GitHub Actions cache: [Using caching in builds](/examples/github-actions-cache/)

0 commit comments

Comments
 (0)