Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
chore: bundle postgres & fix github rate limit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Oct 7, 2024
1 parent 54e2da7 commit 5734ed6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 39 deletions.
51 changes: 24 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/backend-embed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ anyhow = "1.0"
merkle_hash = "3.7.0"
rivet-deno-embed = { path = "../deno-embed", features = ["ignore-override-target"] }
sha2 = "0.10.8"
tempfile = "3.2"
tempfile = "3.13.0"
tokio = { version = "1.40.0", default-features = false, features = ["fs", "rt-multi-thread"] }
walkdir = "2.5.0"
2 changes: 1 addition & 1 deletion packages/deno-embed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ serde_json = "1.0.128"
zip = "0.5"

[dev-dependencies]
tempfile = "3.12.0"
tempfile = "3.13.0"

9 changes: 7 additions & 2 deletions packages/toolchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sysinfo = "0.30.0"
portpicker = "0.1"
tabled = "0.8.0"
tar = "0.4.40"
tempfile = "3.2"
tempfile = "3.13.0"
term_size = "0.3.2"
thiserror = "1.0"
tokio = { version = "1.40.0", default-features = false, features = ["fs", "macros", "process", "rt", "io-util"] }
Expand All @@ -57,7 +57,12 @@ rivet-deno-embed = { path = "../deno-embed" }
rivet-backend-embed = { path = "../backend-embed" }
lazy_static = "1.5.0"
sha1 = "0.10.6"
postgresql_embedded = { version = "0.16.3", features = ["rustls-tls", "theseus"], default-features = false}

[dependencies.postgresql_embedded]
git = "https://github.com/rivet-gg/postgresql-embedded"
rev = "d62273c226a8558a2c5dd34135cabb35e14d4c25"
features = ["rustls-tls", "theseus", "bundled"]
default-features = false

[target.'cfg(unix)'.dependencies]
nix = { version = "0.27", default-features = false, features = ["user", "signal"] }
Expand Down
5 changes: 1 addition & 4 deletions packages/toolchain/src/postgres.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use anyhow::*;
use lazy_static::lazy_static;
use postgresql_embedded::{PostgreSQL, Settings, VersionReq};
use postgresql_embedded::{PostgreSQL, Settings};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, fmt, path::PathBuf, sync::Arc, time::Duration};
use tokio::{net::TcpStream, sync::Mutex};

use crate::paths;

const DEFAULT_POSTGRES_VERSION: &str = "=16.4.0";

lazy_static! {
/// Holds the Postgres managers for each data dir.
static ref MANAGER_REGISTRY: Mutex<HashMap<PathBuf, Arc<PostgresManager>>> = Mutex::new(HashMap::new());
Expand Down Expand Up @@ -45,7 +43,6 @@ impl PostgresManager {
let state = read_state(data_dir).await?;

let mut settings = Settings::new();
settings.version = VersionReq::parse(DEFAULT_POSTGRES_VERSION).unwrap();
settings.installation_dir = paths::postgres_install_dir(data_dir)?;
settings.host = "127.0.0.1".into();
if let Some(port) = state.port {
Expand Down
37 changes: 33 additions & 4 deletions scripts/build/build_cross.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import { resolve } from "jsr:@std/path";
import { ensureDir } from "jsr:@std/fs";
import * as POSTGRESQL_VERSION from "./postgres_version.json";

interface Platform {
name: string;
target: string;
files: string[];
}

const REPO_DIR = resolve(import.meta.dirname!, "..", "..");
const DOCKER_IMAGE = "rust-cross-compiler";
Expand Down Expand Up @@ -96,7 +103,7 @@ async function buildDockerImage() {
}
}

async function buildAndCopyCrossPlatform(outDir: string) {
async function buildAndCopyCrossPlatform(outDir: string, packages: string[] = []) {
console.log("Building and copying cross-platform...");
await Deno.remove(outDir, { recursive: true }).catch(() => {});

Expand All @@ -123,6 +130,27 @@ async function buildAndCopyCrossPlatform(outDir: string) {
},
];

// Determine which files to include based on the packages
const includeAll = packages.length === 0 || packages.includes("all");
for (const platform of platforms) {
if (includeAll || packages.includes("rivet-cli")) {
platform.files.push(platform.name.includes("windows") ? "rivet.exe" : "rivet");
}
if (includeAll || packages.includes("rivet-toolchain-ffi")) {
let ffiLibrary: string;
if (platform.name.includes("windows")) {
ffiLibrary = "rivet_toolchain_ffi.dll";
} else if (platform.name.includes("linux")) {
ffiLibrary = "librivet_toolchain_ffi.so";
} else if (platform.name.includes("macos")) {
ffiLibrary = "librivet_toolchain_ffi.dylib";
} else {
throw new Error(`Unsupported platform: ${platform.name}`);
}
platform.files.push(ffiLibrary);
}
}

for (const platform of platforms) {
console.log(`Building for ${platform.name}...`);
const command = new Deno.Command("docker", {
Expand All @@ -133,6 +161,8 @@ async function buildAndCopyCrossPlatform(outDir: string) {
`${REPO_DIR}:/app`,
"-e",
`OVERRIDE_TARGET=${platform.target}`,
"-e",
`POSTGRESQL_VERSION=${POSTGRESQL_VERSION}`,
DOCKER_IMAGE,
"/bin/sh",
"-c",
Expand Down Expand Up @@ -172,8 +202,7 @@ async function buildAndCopyCrossPlatform(outDir: string) {
}
}

export async function buildCross(outDir: string) {
export async function buildCross(outDir: string, packages: string[] = []) {
await buildDockerImage();
await buildAndCopyCrossPlatform(outDir);
await buildAndCopyCrossPlatform(outDir, packages);
}

1 change: 1 addition & 0 deletions scripts/build/postgres_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"=16.4.0"

0 comments on commit 5734ed6

Please sign in to comment.