@@ -25,21 +25,9 @@ RUN corepack prepare pnpm@9.15.9 --activate
2525# Install necessary build tools and compilers
2626RUN apk update && apk add --no-cache cmake g++ gcc jq make openssl-dev python3
2727
28- # BuildKit secret handling without hardcoded fallback values
29- # This approach relies entirely on secrets passed from GitHub Actions
30- RUN echo '#!/bin/sh' > /tmp/read-secrets.sh && \
31- echo 'if [ -f "/run/secrets/database_url" ]; then' >> /tmp/read-secrets.sh && \
32- echo ' export DATABASE_URL=$(cat /run/secrets/database_url)' >> /tmp/read-secrets.sh && \
33- echo 'else' >> /tmp/read-secrets.sh && \
34- echo ' echo "DATABASE_URL secret not found. Build may fail if this is required."' >> /tmp/read-secrets.sh && \
35- echo 'fi' >> /tmp/read-secrets.sh && \
36- echo 'if [ -f "/run/secrets/encryption_key" ]; then' >> /tmp/read-secrets.sh && \
37- echo ' export ENCRYPTION_KEY=$(cat /run/secrets/encryption_key)' >> /tmp/read-secrets.sh && \
38- echo 'else' >> /tmp/read-secrets.sh && \
39- echo ' echo "ENCRYPTION_KEY secret not found. Build may fail if this is required."' >> /tmp/read-secrets.sh && \
40- echo 'fi' >> /tmp/read-secrets.sh && \
41- echo 'exec "$@"' >> /tmp/read-secrets.sh && \
42- chmod +x /tmp/read-secrets.sh
28+ # Copy the secrets handling script
29+ COPY apps/web/scripts/docker/read-secrets.sh /tmp/read-secrets.sh
30+ RUN chmod +x /tmp/read-secrets.sh
4331
4432# Increase Node.js memory limit as a regular build argument
4533ARG NODE_OPTIONS="--max_old_space_size=4096"
@@ -62,6 +50,9 @@ RUN touch apps/web/.env
6250# Install the dependencies
6351RUN pnpm install --ignore-scripts
6452
53+ # Build the database package first
54+ RUN pnpm build --filter=@formbricks/database
55+
6556# Build the project using our secret reader script
6657# This mounts the secrets only during this build step without storing them in layers
6758RUN --mount=type=secret,id=database_url \
@@ -106,20 +97,8 @@ RUN chown -R nextjs:nextjs ./apps/web/public && chmod -R 755 ./apps/web/public
10697COPY --from=installer /app/packages/database/schema.prisma ./packages/database/schema.prisma
10798RUN chown nextjs:nextjs ./packages/database/schema.prisma && chmod 644 ./packages/database/schema.prisma
10899
109- COPY --from=installer /app/packages/database/package.json ./packages/database/package.json
110- RUN chown nextjs:nextjs ./packages/database/package.json && chmod 644 ./packages/database/package.json
111-
112- COPY --from=installer /app/packages/database/migration ./packages/database/migration
113- RUN chown -R nextjs:nextjs ./packages/database/migration && chmod -R 755 ./packages/database/migration
114-
115- COPY --from=installer /app/packages/database/src ./packages/database/src
116- RUN chown -R nextjs:nextjs ./packages/database/src && chmod -R 755 ./packages/database/src
117-
118- COPY --from=installer /app/packages/database/node_modules ./packages/database/node_modules
119- RUN chown -R nextjs:nextjs ./packages/database/node_modules && chmod -R 755 ./packages/database/node_modules
120-
121- COPY --from=installer /app/packages/logger/dist ./packages/database/node_modules/@formbricks/logger/dist
122- RUN chown -R nextjs:nextjs ./packages/database/node_modules/@formbricks/logger/dist && chmod -R 755 ./packages/database/node_modules/@formbricks/logger/dist
100+ COPY --from=installer /app/packages/database/dist ./packages/database/dist
101+ RUN chown -R nextjs:nextjs ./packages/database/dist && chmod -R 755 ./packages/database/dist
123102
124103COPY --from=installer /app/node_modules/@prisma/client ./node_modules/@prisma/client
125104RUN chown -R nextjs:nextjs ./node_modules/@prisma/client && chmod -R 755 ./node_modules/@prisma/client
@@ -142,12 +121,14 @@ RUN chmod -R 755 ./node_modules/@noble/hashes
142121COPY --from=installer /app/node_modules/zod ./node_modules/zod
143122RUN chmod -R 755 ./node_modules/zod
144123
145- RUN npm install --ignore-scripts -g tsx typescript pino-pretty
146124RUN npm install -g prisma
147125
126+ # Create a startup script to handle the conditional logic
127+ COPY --from=installer /app/apps/web/scripts/docker/next-start.sh /home/nextjs/start.sh
128+ RUN chown nextjs:nextjs /home/nextjs/start.sh && chmod +x /home/nextjs/start.sh
129+
148130EXPOSE 3000
149- ENV HOSTNAME "0.0.0.0"
150- ENV NODE_ENV="production"
131+ ENV HOSTNAME="0.0.0.0"
151132USER nextjs
152133
153134# Prepare volume for uploads
@@ -158,12 +139,4 @@ VOLUME /home/nextjs/apps/web/uploads/
158139RUN mkdir -p /home/nextjs/apps/web/saml-connection
159140VOLUME /home/nextjs/apps/web/saml-connection
160141
161- CMD if [ "${DOCKER_CRON_ENABLED:-1}" = "1" ]; then \
162- echo "Starting cron jobs..." ; \
163- supercronic -quiet /app/docker/cronjobs & \
164- else \
165- echo "Docker cron jobs are disabled via DOCKER_CRON_ENABLED=0" ; \
166- fi; \
167- (cd packages/database && npm run db:migrate:deploy) && \
168- (cd packages/database && npm run db:create-saml-database:deploy) && \
169- exec node apps/web/server.js
142+ CMD ["/home/nextjs/start.sh" ]
0 commit comments