Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ jobs:
- name: Install rust target
run: rustup target add ${{ matrix.target }}

- name: Set release version
if: startsWith(github.ref, 'refs/tags/')
shell: bash
run: echo "SPACETIMEDB_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"

- name: Add signtool.exe to PATH
if: ${{ runner.os == 'Windows' }}
shell: pwsh
Expand Down
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FROM rust:bookworm AS builder
WORKDIR /usr/src/app
COPY . .

ARG SPACETIMEDB_RELEASE_VERSION

# If we're in a git submodule, we'll have a corrupted/nonfunctional .git file instead of a proper .git directory.
# To make the errors more sane, remove .git entirely.
RUN if [ -f .git ]; then \
Expand All @@ -13,7 +15,11 @@ RUN if [ -f .git ]; then \
exit 1; \
fi

RUN cargo build -p spacetimedb-standalone -p spacetimedb-cli --release --locked
RUN if [ -n "$SPACETIMEDB_RELEASE_VERSION" ]; then \
SPACETIMEDB_VERSION="$SPACETIMEDB_RELEASE_VERSION" cargo build -p spacetimedb-standalone -p spacetimedb-cli --release --locked; \
else \
cargo build -p spacetimedb-standalone -p spacetimedb-cli --release --locked; \
fi

FROM rust:bookworm

Expand Down Expand Up @@ -62,4 +68,3 @@ EXPOSE 3000

# Define the entrypoint
ENTRYPOINT ["spacetime"]

24 changes: 23 additions & 1 deletion crates/client-api/src/routes/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ use axum::extract::State;
use axum::response::IntoResponse;
use http::StatusCode;

static VERSION: &str = env!("CARGO_PKG_VERSION");
static VERSION: &str = selected_version(option_env!("SPACETIMEDB_VERSION"), env!("CARGO_PKG_VERSION"));
static PACKAGE_NAME: &str = env!("CARGO_PKG_NAME");

const fn selected_version(release_version: Option<&'static str>, cargo_version: &'static str) -> &'static str {
match release_version {
Some(version) => version,
None => cargo_version,
}
}

pub async fn health<S: ControlStateDelegate + NodeDelegate>(
State(ctx): State<S>,
) -> axum::response::Result<impl IntoResponse> {
Expand Down Expand Up @@ -47,3 +54,18 @@ where
use axum::routing::get;
axum::Router::new().route("/", get(health::<S>))
}

#[cfg(test)]
mod tests {
use super::selected_version;

#[test]
fn selected_version_uses_release_version_when_present() {
assert_eq!(selected_version(Some("2.7.0-hotfix3"), "2.7.0"), "2.7.0-hotfix3");
}

#[test]
fn selected_version_falls_back_to_cargo_version() {
assert_eq!(selected_version(None, "2.8.0"), "2.8.0");
}
}
1 change: 1 addition & 0 deletions tools/ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ fn main() -> Result<()> {
"unreal"
)
.run()?;
cmd!("cargo", "test", "--manifest-path", "tools/release/Cargo.toml").run()?;
// Bindings snapshot tests rely on the unstable feature,
// as they compile and test APIs which are gated behind that feature,
// e.g. procedures, HTTP handlers.
Expand Down
22 changes: 22 additions & 0 deletions tools/release/src/targets/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use std::process::Command;
use std::thread;
use std::time::{Duration, Instant};

fn healthcheck_version(release_version: &str) -> &str {
release_version.strip_prefix('v').unwrap_or(release_version)
}

pub struct DockerRelease {
pub version: String,
pub dry_run: bool,
Expand Down Expand Up @@ -111,6 +115,7 @@ impl DockerRelease {
println!("Building for platforms: linux/amd64, linux/arm64");

let version_tag = format!("{}:{}", image_repo, self.version);
let healthcheck_version = healthcheck_version(&self.version);

// Build and push the multi-platform image
let mut cmd = Command::new("docker");
Expand All @@ -121,6 +126,8 @@ impl DockerRelease {
"linux/amd64,linux/arm64",
"-t",
&version_tag,
"--build-arg",
&format!("SPACETIMEDB_RELEASE_VERSION={healthcheck_version}"),
"--push",
".",
]);
Expand Down Expand Up @@ -209,3 +216,18 @@ impl ReleaseTarget for DockerRelease {
"docker"
}
}

#[cfg(test)]
mod tests {
use super::healthcheck_version;

#[test]
fn healthcheck_version_strips_leading_v() {
assert_eq!(healthcheck_version("v2.7.0-hotfix3"), "2.7.0-hotfix3");
}

#[test]
fn healthcheck_version_keeps_version_without_leading_v() {
assert_eq!(healthcheck_version("2.7.0-hotfix3"), "2.7.0-hotfix3");
}
}
Loading