UNPKG

redis-smq-common

Version:

RedisSMQ Common Library provides many components that are mainly used by RedisSMQ and RedisSMQ Monitor.

49 lines 2.3 kB
import { chmod, copyFile } from 'node:fs/promises'; import os from 'node:os'; import path from 'path'; import { archive } from '../archive/index.js'; import { env } from '../env/index.js'; import { FileLock } from '../file-lock/index.js'; import { getSupportedPlatform, } from './get-supported-platform.js'; import { constants } from './constants.js'; const { REDIS_BINARY_PATH, REDIS_CACHE_DIRECTORY, REDIS_SETUP_LOCK_FILE } = constants; const tarballs = { linux: { x64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-linux-x64-v7.2.8-2.tar.gz', arm64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-linux-arm64-v7.2.8-2.tar.gz', }, darwin: { x64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-macos-x64-v7.2.8-2.tar.gz', arm64: 'https://github.com/weyoss/valkey/releases/download/v7.2.8-2/valkey-server-macos-arm64-v7.2.8-2.tar.gz', }, }; async function downloadAndExtractRedis(url, downloadPath) { const tarballPath = path.join(downloadPath, 'redis-server.tar.gz'); await env.downloadFile(url, tarballPath); const extractionDir = path.join(downloadPath, 'extracted'); await env.ensureDirectoryExists(extractionDir); await archive.extractTgz(tarballPath, extractionDir); return path.join(extractionDir, 'src', 'valkey-server'); } export async function downloadPrebuiltBinary() { const platform = getSupportedPlatform(); const fileLock = new FileLock(); try { await env.ensureDirectoryExists(REDIS_CACHE_DIRECTORY); await fileLock.acquireLock(REDIS_SETUP_LOCK_FILE); if (!(await env.doesPathExist(REDIS_BINARY_PATH))) { const tempDir = path.join(os.tmpdir(), `redis-${Date.now()}`); await env.ensureDirectoryExists(tempDir); const arch = os.arch(); const tarball = tarballs[platform][arch]; const redisBinary = await downloadAndExtractRedis(tarball, tempDir); await copyFile(redisBinary, REDIS_BINARY_PATH); await chmod(REDIS_BINARY_PATH, 0o755); } return REDIS_BINARY_PATH; } finally { await fileLock.releaseLock(REDIS_SETUP_LOCK_FILE); } } //# sourceMappingURL=redis-binary.js.map