Repository: promptfoo/promptfoo
Issue: Use UBI images for building promptfoo container
Root cause: Unimplemented Feature Gap

Use UBI images for building promptfoo container 


https://developers.redhat.com/blog/2019/10/09/what-is-red-hat-universal-base-image

The following worked for me , @mldangelo Is this something we could merge as a version of the dockerfile that uses Universal base images ?

```

# ---- Build ----
ARG BUILDPLATFORM=linux/amd64
FROM --platform=${BUILDPLATFORM} registry.access.redhat.com/ubi8/nodejs-20 AS builder

ARG NEXT_PUBLIC_PROMPTFOO_BASE_URL
ENV NEXT_PUBLIC_PROMPTFOO_BASE_URL=${NEXT_PUBLIC_PROMPTFOO_BASE_URL}
ENV NEXT_PUBLIC_PROMPTFOO_BUILD_STANDALONE_SERVER=1
ENV NEXT_TELEMETRY_DISABLED=1

# TODO: Backwards compatibility, 2024-04-01
ARG NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL
ENV NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL=${NEXT_PUBLIC_PROMPTFOO_REMOTE_API_BASE_URL}

# Supabase opt-in
ARG NEXT_PUBLIC_PROMPTFOO_USE_SUPABASE
ENV NEXT_PUBLIC_PROMPTFOO_USE_SUPABASE=${NEXT_PUBLIC_PROMPTFOO_USE_SUPABASE}

# These envars are not necessarily used, but must be set to prevent the build process from erroring.
ENV NEXT_PUBLIC_SUPABASE_URL=http://placeholder.promptfoo.dev
ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=placeholder

WORKDIR /app
COPY . .

# Switch to root user for package installation
USER root

# Necessary for node-gyp deps
RUN yum update -y && yum install -y python3 make gcc-c++

# Envars are read in from src/web/nextui/.env.production
RUN echo "*** Building with env vars from .env.production"

# Install Node.js dependencies
RUN npm install

# Build the application
RUN npm run build

# Ensure the build process creates the expected output
RUN ls -al /app/src/web/nextui/.next

WORKDIR /app/src/web/nextui
RUN npm prune --omit=dev

# ---- Final Stage ----
ARG TARGETPLATFORM=linux/amd64
FROM --platform=${TARGETPLATFORM} registry.access.redhat.com/ubi8/nodejs-20

LABEL org.opencontainers.image.source="https://github.com/promptfoo/promptfoo"
LABEL org.opencontainers.image.description="promptfoo is a tool for testing evaluating and red-teaming LLM apps."
LABEL org.opencontainers.image.licenses="MIT"

ENV NEXT_TELEMETRY_DISABLED=1

WORKDIR /app

# Copy the necessary files from the builder stage
COPY --from=builder /app/src/web/nextui/public ./public
COPY --from=builder /app/src/web/nextui/.next/standalone ./
COPY --from=builder /app/src/web/nextui/.next/static ./src/web/nextui/.next/static
COPY --from=builder /app/drizzle ./src/web/nextui/.next/server/drizzle

# Switch to root user for creating directories and setting permissions
USER root

RUN mkdir -p /root/.promptfoo/output

# Permissions
RUN groupadd -r nodejs && useradd -r -g nodejs nextjs
RUN mkdir -p /root/.promptfoo/output
RUN chown -R nextjs:nodejs /app /root/.promptfoo

# Create the .env file directory with correct permissions
RUN mkdir -p /app/src/web/nextui
RUN chown nextjs:nodejs /app/src/web/nextui

# Install curl for the healthcheck
RUN yum install -y curl sqlite

# Create a script to write environment variables to .env file
RUN echo -e '#!/bin/sh\n\
    echo "Writing environment variables to .env file..."\n\
    env > /app/src/web/nextui/.env\n\
    echo "Loaded environment variables:"\n\
    cat /app/src/web/nextui/.env\n\
    echo "Starting server..."\n\
    node src/web/nextui/server.js' > entrypoint.sh

# Make the script executable
RUN chmod +x entrypoint.sh

# Switch to non-root user
USER nextjs

EXPOSE 3000

ENV PORT=3000
ENV HOSTNAME="0.0.0.0"

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s CMD curl -f http://$HOSTNAME:$PORT || exit 1

CMD ["sh", "entrypoint.sh"]

```

Hi @rrbanda! Thanks for suggesting this change! We would welcome this as an alternative Dockerfile in a new docker folder. If you're up for PRing it yourself, could you create a pull request with the UBI Dockerfile and a brief README explaining its use? You might also consider updating our docs at site/docs/usage/self-hosting.md to include this option. Let me know if you need any assistance. Thanks! 

Hi @rrbanda, thanks again for your suggestion! As there hasn’t been much recent activity, I’ll go ahead and close this issue for now. If you’re still interested in adding this feature, feel free to reopen the issue or submit a pull request with your changes. We’d be happy to review it. I appreciate the idea and look forward to seeing more of your ideas in the future!