Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

Dockerfile 3.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  1. # syntax=docker/dockerfile:1
  2. # check=skip=SecretsUsedInArgOrEnv
  3. # TODO(ian): Remove the SecretsUsedInArgOrEnv check once we remove the placeholder for NEXT_PUBLIC_SUPABASE_ANON_KEY
  4. # https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
  5. # ---- Build ----
  6. ARG BUILDPLATFORM=linux/amd64
  7. FROM --platform=${BUILDPLATFORM} node:20-alpine AS builder
  8. # Set environment variables for the build
  9. ARG NEXT_PUBLIC_PROMPTFOO_BASE_URL
  10. ENV NEXT_PUBLIC_PROMPTFOO_BASE_URL=${NEXT_PUBLIC_PROMPTFOO_BASE_URL}
  11. ENV NEXT_PUBLIC_PROMPTFOO_BUILD_STANDALONE_SERVER=1
  12. ENV NEXT_TELEMETRY_DISABLED=1
  13. # TODO(ian): Backwards compatibility, 2024-04-01
  14. ARG NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL
  15. ENV NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL=${NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL}
  16. # Supabase opt-in
  17. ARG NEXT_PUBLIC_PROMPTFOO_USE_SUPABASE
  18. ENV NEXT_PUBLIC_PROMPTFOO_USE_SUPABASE=${NEXT_PUBLIC_PROMPTFOO_USE_SUPABASE}
  19. # These envars are not necessarily used, but must be set to prevent the build process from erroring.
  20. ENV NEXT_PUBLIC_SUPABASE_URL=http://placeholder.promptfoo.dev
  21. ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=placeholder
  22. WORKDIR /app
  23. COPY . .
  24. # Install dependencies and build the application
  25. RUN apk update && apk add --no-cache python3 build-base
  26. # Envars are read in from src/web/nextui/.env.production
  27. RUN echo "*** Building with env vars from .env.production"
  28. RUN npm install
  29. RUN npm run build
  30. WORKDIR /app/src/web/nextui
  31. RUN npm prune --omit=dev
  32. # Final Stage
  33. FROM node:20-alpine
  34. # Set metadata for the image
  35. LABEL org.opencontainers.image.source="https://github.com/promptfoo/promptfoo"
  36. LABEL org.opencontainers.image.description="promptfoo is a tool for testing evaluating and red-teaming LLM apps."
  37. LABEL org.opencontainers.image.licenses="MIT"
  38. ENV NEXT_TELEMETRY_DISABLED=1
  39. WORKDIR /app
  40. # Copy built files from the builder stage
  41. COPY --from=builder /app/src/web/nextui/public ./public
  42. COPY --from=builder /app/src/web/nextui/.next/standalone ./
  43. COPY --from=builder /app/src/web/nextui/.next/static ./src/web/nextui/.next/static
  44. COPY --from=builder /app/drizzle ./src/web/nextui/.next/server/drizzle
  45. ## build + install better-sqlite3
  46. ## This is a kludge to get better-sqlite3 to work on mac M1
  47. ## see: https://github.com/promptfoo/promptfoo/issues/1330
  48. ARG BSQL3_VERSION=v11.1.2
  49. RUN apk update && apk add --no-cache python3 build-base git && \
  50. mkdir -p /tmp/build/ && \
  51. cd /tmp/build/ && \
  52. git clone --depth 1 --branch $BSQL3_VERSION https://github.com/WiseLibs/better-sqlite3.git && \
  53. cd better-sqlite3 && \
  54. cd /app && \
  55. cp -r /tmp/build/better-sqlite3/* /app/node_modules/better-sqlite3/ && \
  56. cd node_modules/better-sqlite3 && \
  57. npm run build-release && \
  58. rm -rf /tmp/build/ && \
  59. apk del python3 build-base git
  60. # Set up directories and permissions
  61. RUN mkdir -p /root/.promptfoo/output
  62. RUN addgroup -g 1001 -S nodejs
  63. RUN adduser -S nextjs -u 1001
  64. RUN mkdir -p /root/.promptfoo/output /app/src/web/nextui
  65. RUN chown -R nextjs:nodejs /app /root/.promptfoo /app/src/web/nextui
  66. # Install Python, pip, and other necessary packages
  67. RUN apk add --no-cache python3 py3-pip curl sqlite-dev && \
  68. python3 -m venv /app/venv && \
  69. /app/venv/bin/pip install --no-cache-dir --upgrade pip setuptools && \
  70. ln -sf python3 /usr/bin/python
  71. # Update PATH to use the virtual environment
  72. ENV PATH="/app/venv/bin:$PATH"
  73. # Create entrypoint script
  74. RUN echo -e '#!/bin/sh\n\
  75. echo "Writing environment variables to .env file..."\n\
  76. env > /app/src/web/nextui/.env\n\
  77. echo "Loaded environment variables:"\n\
  78. cat /app/src/web/nextui/.env\n\
  79. echo "Starting server..."\n\
  80. node src/web/nextui/server.js' > entrypoint.sh
  81. RUN chmod +x entrypoint.sh
  82. # Switch to non-root user
  83. USER nextjs
  84. EXPOSE 3000
  85. ENV PORT=3000
  86. ENV HOSTNAME="0.0.0.0"
  87. # Set up healthcheck
  88. HEALTHCHECK --interval=30s --timeout=10s --start-period=5s CMD curl -f http://$HOSTNAME:$PORT || exit 1
  89. CMD ["sh", "entrypoint.sh"]
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...