FROM registry.access.redhat.com/ubi8/nodejs-16:latest as builder

# Add dependencies
COPY --chown=1001:1001 package*.json ./
RUN npm ci

# Add source code
COPY --chown=1001:1001 . .

# Build plugin
RUN npm run build

FROM registry.access.redhat.com/ubi8/nodejs-16-minimal:latest

# Add plugin server
COPY --from=builder /opt/app-root/src/dist /opt/app-root/src/dist
COPY --from=builder /opt/app-root/src/node_modules /opt/app-root/src/node_modules
COPY --from=builder /opt/app-root/src/package*.json /opt/app-root/src/
COPY --from=builder /opt/app-root/src/src/server.ts /opt/app-root/src/src/
COPY --from=builder /opt/app-root/src/src/utils/health-check.ts /opt/app-root/src/src/utils/

EXPOSE 9443

# Start plugin server
CMD ["npm", "run", "start"]