Skip to content
Closed
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"site",
"sdks/api/full/typescript",
"examples/*",
"tests/load"
"tests/load",
"scripts/lz4"
],
"scripts": {
"start": "npx turbo dev",
Expand Down
22 changes: 22 additions & 0 deletions scripts/lz4/Dockerfile.debian11
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM --platform=linux/amd64 debian:11-slim

# Install required build tools
RUN apt-get update && \
apt-get install -y make gcc curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /build

# Arguments for LZ4 version
ARG LZ4_VERSION=1.10.0

# Download and extract LZ4
RUN curl -L https://github.com/lz4/lz4/releases/download/v${LZ4_VERSION}/lz4-${LZ4_VERSION}.tar.gz | tar xz

# Build LZ4
WORKDIR /build/lz4-${LZ4_VERSION}
RUN make

# Output binary is at /build/lz4-${LZ4_VERSION}/lz4
65 changes: 65 additions & 0 deletions scripts/lz4/distribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Build & push lz4. Most repos are on a significantly older version of lz4 that doesn't support multithreading.
*/

import { $, cd } from "zx";
import { mkdtempSync, mkdirSync, rmSync } from "fs";
import { tmpdir, platform } from "os";
import { join } from "path";
import { dirname } from "path";
import { fileURLToPath } from "url";

const LZ4_VERSION = "1.10.0";
const DISTRO = "debian11";
const UPLOAD_PATH = `tools/lz4/${LZ4_VERSION}/${DISTRO}-amd64/lz4`;

// Get the directory where this script is located
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

async function main() {
// Get credentials
const awsAccessKeyId = process.env.R2_RELEASES_ACCESS_KEY_ID ||
(await $({ quiet: true })`op read "op://Engineering/rivet-releases R2 Upload/username"`).stdout.trim();
const awsSecretAccessKey = process.env.R2_RELEASES_SECRET_ACCESS_KEY ||
(await $({ quiet: true })`op read "op://Engineering/rivet-releases R2 Upload/password"`).stdout.trim();

// Create temp directory for Docker build
const tempDir = mkdtempSync(join(tmpdir(), 'lz4-docker-'));
console.log(`Using temp directory: ${tempDir}`);

// Create output directory
const outputDir = join(tempDir, 'output');
mkdirSync(outputDir, { recursive: true });

// Build Docker image
console.log("Building Docker image for Debian 11");
await $`docker build -t lz4-builder:debian11 -f ${join(__dirname, 'Dockerfile.debian11')} --build-arg LZ4_VERSION=${LZ4_VERSION} ${__dirname}`;

// Run container to extract binary
console.log("Extracting LZ4 binary from container");
await $`docker run --rm -v ${outputDir}:/output lz4-builder:debian11 cp /build/lz4-${LZ4_VERSION}/lz4 /output/`;

console.log("LZ4 build complete");

// Upload to S3
console.log("Uploading LZ4 binary to S3");

// Upload the binary
console.log(`Uploading to s3://rivet-releases/${UPLOAD_PATH}`);
await $({
env: {
...process.env,
AWS_ACCESS_KEY_ID: awsAccessKeyId,
AWS_SECRET_ACCESS_KEY: awsSecretAccessKey,
AWS_DEFAULT_REGION: "auto",
}
})`aws s3 cp ${join(outputDir, 'lz4')} ${`s3://rivet-releases/${UPLOAD_PATH}`} --content-type application/octet-stream --endpoint-url https://2a94c6a0ced8d35ea63cddc86c2681e7.r2.cloudflarestorage.com`;

console.log("Upload complete!");
}

main().catch(error => {
console.error(`Error: ${error}`);
process.exit(1);
});
16 changes: 16 additions & 0 deletions scripts/lz4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@scripts/lz4",
"version": "0.0.0",
"private": true,
"main": "distribute.ts",
"type": "module",
"scripts": {
"distribute": "tsx distribute.ts"
},
"dependencies": {
"zx": "^8.5.0"
},
"devDependencies": {
"tsx": "^4.19.3"
}
}
Loading