Skip to content

Commit 3395b1e

Browse files
bfopsjdetter
andauthored
CI - Cache more of our build outputs (#3521)
# Description of Changes Changes with cache hit: CI / Smoketests (spacetimedb-runner): 17m -> 10m CI / Smoketests (windows-latest): 39m -> 31m CI / Lints: 3m30s -> 2m unity-testsuite: 23m -> 19m This included creating a stripped-down `Dockerfile` that only runs SpacetimeDB (as opposed to e.g. building tracy, flamegraphs, etc.). That shaves off about 4-5m on the linux smoketests job. # API and ABI breaking changes No. CI only. # Expected complexity level and risk 2 # Testing Ran existing CI and noted the change in times in the description above --------- Signed-off-by: Zeke Foppa <196249+bfops@users.noreply.github.com> Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com> Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
1 parent 353cc0d commit 3395b1e

File tree

6 files changed

+91
-21
lines changed

6 files changed

+91
-21
lines changed

.github/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Minimal Dockerfile that just wraps pre-built binaries, so we can test the server inside docker
2+
FROM rust:1.90.0
3+
RUN mkdir -p /stdb/data
4+
COPY ./target/debug/spacetimedb-standalone ./target/debug/spacetimedb-cli /usr/local/bin/
5+
COPY ./crates/standalone/config.toml /stdb/data/config.toml
6+
RUN ln -s /usr/local/bin/spacetimedb-cli /usr/local/bin/spacetime

.github/docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
node:
3+
labels:
4+
app: spacetimedb
5+
build:
6+
context: ../
7+
dockerfile: .github/Dockerfile
8+
ports:
9+
- "3000:3000"
10+
# Postgres
11+
- "5432:5432"
12+
entrypoint: spacetime start --pg-port 5432
13+
privileged: true
14+
environment:
15+
RUST_BACKTRACE: 1

.github/workflows/ci.yml

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ jobs:
3434
container: null
3535
runs-on: ${{ matrix.runner }}
3636
container: ${{ matrix.container }}
37-
37+
env:
38+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
3839
steps:
3940
- name: Find Git ref
4041
env:
@@ -53,6 +54,15 @@ jobs:
5354
with:
5455
ref: ${{ env.GIT_REF }}
5556
- uses: dsherret/rust-toolchain-file@v1
57+
- name: Cache Rust dependencies
58+
uses: Swatinem/rust-cache@v2
59+
with:
60+
workspaces: ${{ github.workspace }}
61+
shared-key: spacetimedb
62+
cache-on-failure: true
63+
cache-all-crates: true
64+
cache-workspace-crates: true
65+
5666
- uses: actions/setup-dotnet@v4
5767
with:
5868
global-json-file: global.json
@@ -71,21 +81,25 @@ jobs:
7181
if: runner.os == 'Windows'
7282
run: choco install psql -y --no-progress
7383
shell: powershell
84+
- name: Build crates
85+
run: cargo build -p spacetimedb-cli -p spacetimedb-standalone -p spacetimedb-update
7486
- name: Start Docker daemon
7587
if: runner.os == 'Linux'
7688
run: /usr/local/bin/start-docker.sh
7789

7890
- name: Build and start database (Linux)
7991
if: runner.os == 'Linux'
80-
run: docker compose up -d
92+
run: |
93+
# Our .dockerignore omits `target`, which our CI Dockerfile needs.
94+
rm .dockerignore
95+
docker compose -f .github/docker-compose.yml up -d
8196
- name: Build and start database (Windows)
8297
if: runner.os == 'Windows'
8398
run: |
8499
# Fail properly if any individual command fails
85100
$ErrorActionPreference = 'Stop'
86101
$PSNativeCommandUseErrorActionPreference = $true
87102
88-
cargo build -p spacetimedb-cli -p spacetimedb-standalone -p spacetimedb-update
89103
Start-Process target/debug/spacetimedb-cli.exe -ArgumentList 'start --pg-port 5432'
90104
cd modules
91105
# the sdk-manifests on windows-latest are messed up, so we need to update them
@@ -101,7 +115,7 @@ jobs:
101115
run: python -m smoketests ${{ matrix.smoketest_args }} -x clear_database replication teams
102116
- name: Stop containers (Linux)
103117
if: always() && runner.os == 'Linux'
104-
run: docker compose down
118+
run: docker compose -f .github/docker-compose.yml down
105119

106120
test:
107121
name: Test Suite
@@ -110,6 +124,8 @@ jobs:
110124
image: localhost:5000/spacetimedb-ci:latest
111125
options: >-
112126
--privileged
127+
env:
128+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
113129
steps:
114130
- name: Find Git ref
115131
env:
@@ -129,6 +145,13 @@ jobs:
129145
ref: ${{ env.GIT_REF }}
130146

131147
- uses: dsherret/rust-toolchain-file@v1
148+
- name: Cache Rust dependencies
149+
uses: Swatinem/rust-cache@v2
150+
with:
151+
workspaces: ${{ github.workspace }}
152+
shared-key: spacetimedb
153+
# Let the smoketests job save the cache since it builds the most things
154+
save-if: false
132155

133156
- uses: actions/setup-dotnet@v3
134157
with:
@@ -179,13 +202,23 @@ jobs:
179202
image: localhost:5000/spacetimedb-ci:latest
180203
options: >-
181204
--privileged
205+
env:
206+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
182207
steps:
183208
- name: Checkout sources
184209
uses: actions/checkout@v3
185210

186211
- uses: dsherret/rust-toolchain-file@v1
187212
- run: echo ::add-matcher::.github/workflows/rust_matcher.json
188213

214+
- name: Cache Rust dependencies
215+
uses: Swatinem/rust-cache@v2
216+
with:
217+
workspaces: ${{ github.workspace }}
218+
shared-key: spacetimedb
219+
# Let the smoketests job save the cache since it builds the most things
220+
save-if: false
221+
189222
- uses: actions/setup-dotnet@v3
190223
with:
191224
global-json-file: global.json
@@ -222,12 +255,22 @@ jobs:
222255
image: localhost:5000/spacetimedb-ci:latest
223256
options: >-
224257
--privileged
258+
env:
259+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
225260
steps:
226261
- uses: actions/checkout@v3
227262

228263
- uses: dsherret/rust-toolchain-file@v1
229264
- run: echo ::add-matcher::.github/workflows/rust_matcher.json
230265

266+
- name: Cache Rust dependencies
267+
uses: Swatinem/rust-cache@v2
268+
with:
269+
workspaces: ${{ github.workspace }}
270+
shared-key: spacetimedb
271+
# Let the smoketests job save the cache since it builds the most things
272+
save-if: false
273+
231274
- name: Run bindgen tests
232275
run: cargo test -p spacetimedb-codegen
233276

@@ -408,6 +451,8 @@ jobs:
408451
image: localhost:5000/spacetimedb-ci:latest
409452
options: >-
410453
--privileged
454+
env:
455+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
411456
steps:
412457
- name: Find Git ref
413458
env:
@@ -451,6 +496,14 @@ jobs:
451496
452497
- uses: dsherret/rust-toolchain-file@v1
453498

499+
- name: Cache Rust dependencies
500+
uses: Swatinem/rust-cache@v2
501+
with:
502+
workspaces: ${{ github.workspace }}
503+
shared-key: spacetimedb
504+
# Let the smoketests job save the cache since it builds the most things
505+
save-if: false
506+
454507
- name: Check for docs change
455508
run: |
456509
cargo run --features markdown-docs -p spacetimedb-cli > docs/docs/cli-reference.md

.github/workflows/csharp-test.yml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
group: unity-test-${{ github.event.pull_request.number || github.ref }}
2424
cancel-in-progress: true
2525
timeout-minutes: 30
26+
env:
27+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
2628
steps:
2729
- name: Checkout repository
2830
id: checkout-stdb
@@ -70,26 +72,18 @@ jobs:
7072

7173
- name: Cache Rust dependencies
7274
uses: Swatinem/rust-cache@v2
73-
id: cache-rust-deps
7475
with:
75-
workspaces: demo/Blackholio/server-rust
76-
key: ${{ steps.checkout-stdb.outputs.commit }}
77-
# Cache Rust deps even if unit tests have failed.
78-
cache-on-failure: true
79-
# Cache the CLI as well.
80-
cache-all-crates: true
76+
workspaces: ${{ github.workspace }}
77+
shared-key: spacetimedb
78+
# Let the main CI job save the cache since it builds the most things
79+
save-if: false
8180

8281
- name: Install SpacetimeDB CLI from the local checkout
83-
# Rebuild only if we didn't get a precise cache hit.
84-
if: steps.cache-rust-deps.outputs.cache-hit == 'false'
8582
run: |
8683
cargo install --force --path crates/cli --locked --message-format=short
8784
cargo install --force --path crates/standalone --locked --message-format=short
8885
# Add a handy alias using the old binary name, so that we don't have to rewrite all scripts (incl. in submodules).
8986
ln -sf $CARGO_HOME/bin/spacetimedb-cli $CARGO_HOME/bin/spacetime
90-
env:
91-
# Share the target directory with our local project to avoid rebuilding same SpacetimeDB crates twice.
92-
CARGO_TARGET_DIR: demo/Blackholio/server-rust/target
9387
9488
- name: Check quickstart-chat bindings are up to date
9589
working-directory: sdks/csharp

.github/workflows/typescript-test.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ concurrency:
1414
jobs:
1515
build-and-test:
1616
runs-on: ubuntu-latest
17+
env:
18+
CARGO_TARGET_DIR: ${{ github.workspace }}/target
1719

1820
steps:
1921
- name: Checkout repository
@@ -81,10 +83,10 @@ jobs:
8183
- name: Cache Rust dependencies
8284
uses: Swatinem/rust-cache@v2
8385
with:
84-
workspaces: |
85-
.
86-
modules/quickstart-chat
87-
shared-key: quickstart-chat-test
86+
workspaces: ${{ github.workspace }}
87+
shared-key: spacetimedb
88+
# Let the main CI job save the cache since it builds the most things
89+
save-if: false
8890

8991
- name: Install SpacetimeDB CLI from the local checkout
9092
run: |

smoketests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
REMOTE_SERVER = False
4949

5050
# default value can be overridden by `--compose-file` flag
51-
COMPOSE_FILE = "./docker-compose.yml"
51+
COMPOSE_FILE = ".github/docker-compose.yml"
5252

5353
# this will be initialized by main()
5454
STDB_CONFIG = ''

0 commit comments

Comments
 (0)