diff --git a/.github/actions/cache-build-web/action.yml b/.github/actions/cache-build-web/action.yml index 4d68fc506b..25d18f4245 100644 --- a/.github/actions/cache-build-web/action.yml +++ b/.github/actions/cache-build-web/action.yml @@ -56,6 +56,7 @@ runs: - name: Fill ENCRYPTION_KEY, ENTERPRISE_LICENSE_KEY and E2E_TESTING in .env run: | RANDOM_KEY=$(openssl rand -hex 32) + sed -i "s/ENCRYPTION_KEY=.*/ENCRYPTION_KEY=${RANDOM_KEY}/" .env echo "E2E_TESTING=${{ inputs.e2e_testing_mode }}" >> .env shell: bash diff --git a/.github/workflows/release-docker-github-experimental.yml b/.github/workflows/release-docker-github-experimental.yml index c009debdcd..25b8e5e61e 100644 --- a/.github/workflows/release-docker-github-experimental.yml +++ b/.github/workflows/release-docker-github-experimental.yml @@ -15,7 +15,6 @@ env: IMAGE_NAME: ${{ github.repository }}-experimental TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ secrets.TURBO_TEAM }} - DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/formbricks?schema=public" permissions: contents: read @@ -80,6 +79,9 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + secrets: | + database_url=${{ secrets.DUMMY_DATABASE_URL }} + encryption_key=${{ secrets.DUMMY_ENCRYPTION_KEY }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/release-docker-github.yml b/.github/workflows/release-docker-github.yml index c09d66d553..0748805c31 100644 --- a/.github/workflows/release-docker-github.yml +++ b/.github/workflows/release-docker-github.yml @@ -100,6 +100,9 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + secrets: | + database_url=${{ secrets.DUMMY_DATABASE_URL }} + encryption_key=${{ secrets.DUMMY_ENCRYPTION_KEY }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index 4724f7bf18..94db1a39eb 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -24,11 +24,28 @@ RUN corepack enable # Install necessary build tools and compilers RUN apk update && apk add --no-cache g++ cmake make gcc python3 openssl-dev jq +# BuildKit secret handling without hardcoded fallback values +# This approach relies entirely on secrets passed from GitHub Actions +RUN echo '#!/bin/sh' > /tmp/read-secrets.sh && \ + echo 'if [ -f "/run/secrets/database_url" ]; then' >> /tmp/read-secrets.sh && \ + echo ' export DATABASE_URL=$(cat /run/secrets/database_url)' >> /tmp/read-secrets.sh && \ + echo 'else' >> /tmp/read-secrets.sh && \ + echo ' echo "DATABASE_URL secret not found. Build may fail if this is required."' >> /tmp/read-secrets.sh && \ + echo 'fi' >> /tmp/read-secrets.sh && \ + echo 'if [ -f "/run/secrets/encryption_key" ]; then' >> /tmp/read-secrets.sh && \ + echo ' export ENCRYPTION_KEY=$(cat /run/secrets/encryption_key)' >> /tmp/read-secrets.sh && \ + echo 'else' >> /tmp/read-secrets.sh && \ + echo ' echo "ENCRYPTION_KEY secret not found. Build may fail if this is required."' >> /tmp/read-secrets.sh && \ + echo 'fi' >> /tmp/read-secrets.sh && \ + echo 'exec "$@"' >> /tmp/read-secrets.sh && \ + chmod +x /tmp/read-secrets.sh + ARG NEXT_PUBLIC_SENTRY_DSN ARG SENTRY_AUTH_TOKEN -# Increase Node.js memory limit -# ENV NODE_OPTIONS="--max_old_space_size=4096" +# Increase Node.js memory limit as a regular build argument +ARG NODE_OPTIONS="--max_old_space_size=4096" +ENV NODE_OPTIONS=${NODE_OPTIONS} # Set the working directory WORKDIR /app @@ -47,8 +64,11 @@ RUN touch apps/web/.env # Install the dependencies RUN pnpm install -# Build the project -RUN NODE_OPTIONS="--max_old_space_size=4096" pnpm build --filter=@formbricks/web... +# Build the project using our secret reader script +# This mounts the secrets only during this build step without storing them in layers +RUN --mount=type=secret,id=database_url \ + --mount=type=secret,id=encryption_key \ + /tmp/read-secrets.sh pnpm build --filter=@formbricks/web... # Extract Prisma version RUN jq -r '.devDependencies.prisma' packages/database/package.json > /prisma_version.txt diff --git a/packages/lib/env.ts b/packages/lib/env.ts index 769fcb53c0..069e77eb0a 100644 --- a/packages/lib/env.ts +++ b/packages/lib/env.ts @@ -20,7 +20,7 @@ export const env = createEnv({ CRON_SECRET: z.string().optional(), BREVO_API_KEY: z.string().optional(), BREVO_LIST_ID: z.string().optional(), - DATABASE_URL: z.string().url().optional(), + DATABASE_URL: z.string().url(), DEBUG: z.enum(["1", "0"]).optional(), DOCKER_CRON_ENABLED: z.enum(["1", "0"]).optional(), DEFAULT_ORGANIZATION_ID: z.string().optional(), @@ -28,7 +28,7 @@ export const env = createEnv({ E2E_TESTING: z.enum(["1", "0"]).optional(), EMAIL_AUTH_DISABLED: z.enum(["1", "0"]).optional(), EMAIL_VERIFICATION_DISABLED: z.enum(["1", "0"]).optional(), - ENCRYPTION_KEY: z.string().optional(), + ENCRYPTION_KEY: z.string(), ENTERPRISE_LICENSE_KEY: z.string().optional(), FORMBRICKS_ENCRYPTION_KEY: z.string().optional(), GITHUB_ID: z.string().optional(),