fixed runtime env allowed_frame_urls

This commit is contained in:
Santosh Tharu 2024-07-27 13:16:23 +05:45
parent 39b32edc9d
commit b518b15559
2 changed files with 35 additions and 1 deletions

View file

@ -23,7 +23,8 @@ ENV BASE_PATH $BASE_PATH
ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build-docker
RUN ALLOWED_FRAME_URLS=/__ENTRYPOINT__ yarn build-docker
ENV ALLOWED_FRAME_URLS=""
# Production image, copy all the files and run next
FROM node:18-alpine AS runner
@ -51,6 +52,10 @@ COPY --from=builder /app/scripts ./scripts
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Create entrypoint script
COPY entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh
USER nextjs
EXPOSE 3000
@ -58,4 +63,6 @@ EXPOSE 3000
ENV HOSTNAME 0.0.0.0
ENV PORT 3000
ENTRYPOINT ["./entrypoint.sh"]
CMD ["yarn", "start-docker"]

27
entrypoint.sh Normal file
View file

@ -0,0 +1,27 @@
#!/bin/sh
# replace /__ENTRYPOINT__ with the runtime-configured entrypoint
escaped_frame_urls=$(echo "$ALLOWED_FRAME_URLS" | sed 's/\//\\\//g')
echo "Replacing /__ENTRYPOINT__ in all .next file..."
find .next -type f -exec sed -i 's/\/__ENTRYPOINT__/'"${escaped_frame_urls}"'/g' {} +
# Check if any replacements were made in .next files
if [ $? -eq 0 ]; then
echo "Replacements in .next completed."
else
echo "No replacements made in .next or an error occurred."
fi
# Replace /__ENTRYPOINT__ in server.js
echo "Replacing /__ENTRYPOINT__ in server.js..."
sed -i "s/\/__ENTRYPOINT__/${escaped_frame_urls}/g" server.js
# Check if any replacements were made in server.js
if [ $? -eq 0 ]; then
echo "Replacements in server.js completed."
else
echo "No replacements made in server.js or an error occurred."
fi
$@