Skip to content

Commit c786087

Browse files
authored
Merge pull request #4 from Brendonovich/ci/improve-dockerfile
improve docker build
2 parents 944b4a1 + 7b009a2 commit c786087

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ jobs:
6262
push: true
6363
platforms: linux/${{ matrix.arch }}
6464
tags: |
65+
6566
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-slim-${{ matrix.arch }}
6667
${{ env.IMAGE }}:slim-${{ matrix.arch }}
67-
cache-from: type=gha
68-
cache-to: type=gha,mode=max
68+
cache-from: type=gha,scope=release-slim
69+
cache-to: type=gha,mode=max,scope=release-slim
6970

7071
- name: Build and push full
7172
uses: docker/build-push-action@v6
@@ -77,8 +78,9 @@ jobs:
7778
tags: |
7879
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-full-${{ matrix.arch }}
7980
${{ env.IMAGE }}:full-${{ matrix.arch }}
80-
cache-from: type=gha
81-
cache-to: type=gha,mode=max
81+
cache-from: type=gha,scope=release-full
82+
cache-to: type=gha,mode=max,scope=release-full
83+
8284

8385
publish-manifests:
8486
runs-on: ubuntu-latest

Dockerfile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1.6
12
# ---- Builder stage ----
23
# Compiles the React frontend and the Rust binary with the frontend embedded.
34
FROM rust:bookworm AS builder
@@ -21,11 +22,20 @@ WORKDIR /build
2122
# 1. Fetch and cache Rust dependencies.
2223
# cargo fetch needs a valid target, so we create stubs that get replaced later.
2324
COPY Cargo.toml Cargo.lock ./
24-
RUN mkdir src && echo "fn main() {}" > src/main.rs && touch src/lib.rs && cargo fetch && rm -rf src
25+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
26+
--mount=type=cache,target=/usr/local/cargo/git \
27+
--mount=type=cache,target=/build/target \
28+
mkdir src && echo "fn main() {}" > src/main.rs && touch src/lib.rs \
29+
&& cargo build --release \
30+
&& rm -rf src
2531

2632
# 2. Build the frontend.
33+
COPY interface/package.json interface/
34+
RUN --mount=type=cache,target=/root/.bun/install/cache \
35+
cd interface && bun install
2736
COPY interface/ interface/
28-
RUN cd interface && bun install && bun add -d @rollup/rollup-linux-x64-gnu && bun run build
37+
RUN --mount=type=cache,target=/root/.bun/install/cache \
38+
cd interface && bun run build
2939

3040
# 3. Copy source and compile the real binary.
3141
# build.rs runs the frontend build (already done above, node_modules present).
@@ -35,7 +45,10 @@ COPY build.rs ./
3545
COPY prompts/ prompts/
3646
COPY migrations/ migrations/
3747
COPY src/ src/
38-
RUN cargo build --release
48+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
49+
--mount=type=cache,target=/usr/local/cargo/git \
50+
--mount=type=cache,target=/build/target \
51+
SPACEBOT_SKIP_FRONTEND_BUILD=1 cargo build --release
3952

4053
# ---- Slim stage ----
4154
# Minimal runtime with just the binary. No browser.

build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::process::Command;
22

33
fn main() {
4+
if std::env::var("SPACEBOT_SKIP_FRONTEND_BUILD").is_ok() {
5+
return;
6+
}
47
// Re-run if interface source files change
58
println!("cargo:rerun-if-changed=interface/src/");
69
println!("cargo:rerun-if-changed=interface/index.html");

0 commit comments

Comments
 (0)