From 9535276fe6f866634e7b8c849713ce84bc249929 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Sun, 1 Jun 2025 21:59:17 +0200 Subject: [PATCH 1/3] fix[railpack]: env parsing and update railpack to v0.0.66 Improve environment variable parsing to handle values containing equals signs by extracting a dedicated parseEnvironmentKeyValuePair function and updating Railpack secret formatting. --- Dockerfile | 2 +- .../server/src/utils/builders/railpack.ts | 23 +++++++++++-------- packages/server/src/utils/docker/utils.ts | 13 ++++++++++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 00043b0c..531cb082 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,7 @@ RUN curl -sSL https://nixpacks.com/install.sh -o install.sh \ && pnpm install -g tsx # Install Railpack -ARG RAILPACK_VERSION=0.0.64 +ARG RAILPACK_VERSION=0.0.66 RUN curl -sSL https://railpack.com/install.sh | bash # Install buildpacks diff --git a/packages/server/src/utils/builders/railpack.ts b/packages/server/src/utils/builders/railpack.ts index 481dc0fa..cda63e8f 100644 --- a/packages/server/src/utils/builders/railpack.ts +++ b/packages/server/src/utils/builders/railpack.ts @@ -2,7 +2,10 @@ import { createHash } from "node:crypto"; import type { WriteStream } from "node:fs"; import { nanoid } from "nanoid"; import type { ApplicationNested } from "."; -import { prepareEnvironmentVariables } from "../docker/utils"; +import { + parseEnvironmentKeyValuePair, + prepareEnvironmentVariables, +} from "../docker/utils"; import { getBuildAppDirectory } from "../filesystem/directory"; import { execAsync } from "../process/execAsync"; import { spawnAsync } from "../process/spawnAsync"; @@ -81,10 +84,10 @@ export const buildRailpack = async ( // Add secrets properly formatted const env: { [key: string]: string } = {}; - for (const envVar of envVariables) { - const [key, value] = envVar.split("="); - if (key && value) { - buildArgs.push("--secret", `id=${key},env='${key}'`); + for (const pair of envVariables) { + const [key, value] = parseEnvironmentKeyValuePair(pair); + if (key && value.length > 0) { + buildArgs.push("--secret", `id=${key},env=${key}`); env[key] = value; } } @@ -161,11 +164,11 @@ export const getRailpackCommand = ( // Add secrets properly formatted const exportEnvs = []; - for (const envVar of envVariables) { - const [key, value] = envVar.split("="); - if (key && value) { - buildArgs.push("--secret", `id=${key},env='${key}'`); - exportEnvs.push(`export ${key}=${value}`); + for (const pair of envVariables) { + const [key, value] = parseEnvironmentKeyValuePair(pair); + if (key && value.length > 0) { + buildArgs.push("--secret", `id=${key},env=${key}`); + exportEnvs.push(`export ${key}='${value}'`); } } diff --git a/packages/server/src/utils/docker/utils.ts b/packages/server/src/utils/docker/utils.ts index 840e6f41..61f71381 100644 --- a/packages/server/src/utils/docker/utils.ts +++ b/packages/server/src/utils/docker/utils.ts @@ -279,6 +279,17 @@ export const prepareEnvironmentVariables = ( return resolvedVars; }; +export const parseEnvironmentKeyValuePair = ( + pair: string, +): [string, string] => { + const [key, ...valueParts] = pair.split("="); + if (!key || !valueParts.length) { + throw new Error(`Invalid environment variable pair: ${pair}`); + } + + return [key, valueParts.join("")]; +}; + export const getEnviromentVariablesObject = ( input: string | null, projectEnv?: string | null, @@ -288,7 +299,7 @@ export const getEnviromentVariablesObject = ( const jsonObject: Record = {}; for (const pair of envs) { - const [key, value] = pair.split("="); + const [key, value] = parseEnvironmentKeyValuePair(pair); if (key && value) { jsonObject[key] = value; } From 7f9c19bc11f8d003b5d6624032cd25a4c29b0c37 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Sun, 1 Jun 2025 22:21:53 +0200 Subject: [PATCH 2/3] fix[railpack]: environment variable validation for empty strings Allow empty string values to be processed as valid environment variables by checking for existence rather than non-empty length. --- packages/server/src/utils/builders/railpack.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utils/builders/railpack.ts b/packages/server/src/utils/builders/railpack.ts index cda63e8f..991720f3 100644 --- a/packages/server/src/utils/builders/railpack.ts +++ b/packages/server/src/utils/builders/railpack.ts @@ -86,7 +86,7 @@ export const buildRailpack = async ( const env: { [key: string]: string } = {}; for (const pair of envVariables) { const [key, value] = parseEnvironmentKeyValuePair(pair); - if (key && value.length > 0) { + if (key && value) { buildArgs.push("--secret", `id=${key},env=${key}`); env[key] = value; } @@ -166,7 +166,7 @@ export const getRailpackCommand = ( const exportEnvs = []; for (const pair of envVariables) { const [key, value] = parseEnvironmentKeyValuePair(pair); - if (key && value.length > 0) { + if (key && value) { buildArgs.push("--secret", `id=${key},env=${key}`); exportEnvs.push(`export ${key}='${value}'`); } From 0c12d967e22023973732bc4a92fe3235a2179a5c Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sun, 1 Jun 2025 18:12:57 -0600 Subject: [PATCH 3/3] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 531cb082..00043b0c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,7 @@ RUN curl -sSL https://nixpacks.com/install.sh -o install.sh \ && pnpm install -g tsx # Install Railpack -ARG RAILPACK_VERSION=0.0.66 +ARG RAILPACK_VERSION=0.0.64 RUN curl -sSL https://railpack.com/install.sh | bash # Install buildpacks