# Dockerfile.ci
# -------------------------------------------------------------------
# This “CI image” simply extends your Rails‐only image (built from rails/Dockerfile)
# and installs Node.js, Playwright, and Docker CLI for CI test stages.
# -------------------------------------------------------------------

# 1) Start FROM the image you pushed in the build stage:
FROM registry.gitlab.com/gumtu/phluid_rails/rails-playwright:latest

# 2) Install Node.js (we’ll use Node 18 LTS here as an example) + Docker CLI
USER root
RUN apt-get update -qq && \
    apt-get install -y --no-install-recommends \
    curl gnupg build-essential ca-certificates \
    docker.io && \
    curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get install -y nodejs && \
    rm -rf /var/lib/apt/lists/*

# 3) Create a working directory for JS dependencies
WORKDIR /ci-build

# 4) Copy only your package.json / package-lock.json (assumes these live at repo root)
COPY package.json package-lock.json ./

# 5) Install JS dependencies and download Playwright browsers + necessary libs
RUN npm ci && npx playwright install --with-deps

# 6) (Optional) Test-specific build steps (e.g. transpile)

# 7) Wrapper ENTRYPOINT to force `cd /rails` but forward any commands like bin/rails
RUN printf '#!/usr/bin/env bash\n\
cd /rails\n\
exec "$@"\n' \
  > /usr/local/bin/ci-entrypoint.sh && \
  chmod +x /usr/local/bin/ci-entrypoint.sh

# 9) Override ENTRYPOINT to use wrapper
ENTRYPOINT ["/usr/local/bin/ci-entrypoint.sh"]
