FROM node:18-alpine
# Minimal system dependencies
RUN apk --no-cache add procps
ENV LANG=en_US.utf8 \
TERM=xterm-256color
WORKDIR /app
# Install production dependencies first to leverage Docker layer caching
COPY package.json package-lock.json ./
RUN npm ci --production
# Copy the application source
COPY . .
# Create an entrypoint wrapper to handle --version reliably in smoke tests
RUN mkdir -p /usr/local/bin
RUN cat > /usr/local/bin/gtop-entrypoint <<'EOS'
#!/bin/sh
set -e
APP_DIR="/app"
if [ "$1" = "--version" ]; then
node -e "console.log(require('./package.json').version)"
echo
exit 0
fi
exec "$APP_DIR/bin/gtop" "$@"
EOS
RUN chmod +x /usr/local/bin/gtop-entrypoint
ENTRYPOINT ["/usr/local/bin/gtop-entrypoint"]