FROM ghcr.io/puppeteer/puppeteer:16.1.0

USER root
# Install dependencies
RUN rm -f /etc/apt/sources.list.d/google-chrome.list /etc/apt/sources.list.d/google.list \
    && mkdir -p /var/lib/apt/lists/partial && chmod 755 /var/lib/apt/lists/partial \
    && apt-get update && apt-get install -y --no-install-recommends wget git

# Set environment variables
ENV GO_VERSION=1.24.1
ENV GOROOT=/go
ENV GOPATH=/gopath
ENV PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"

# Download and install Golang
RUN wget -q https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz -O /tmp/go.tar.gz \
    && tar -C / -xzf /tmp/go.tar.gz \
    && rm /tmp/go.tar.gz

# Precompile the test and download go modules to shorten runtime
# Set environment variables
ARG GITHUB_TOKEN
ENV GOPRIVATE=github.com/tidbcloud
# Create .netrc for git auth
RUN echo "machine github.com login $GITHUB_TOKEN password x-oauth-basic" > ~/.netrc
WORKDIR /home/pptruser/precompile
COPY . .
RUN go mod tidy
RUN make install-gotestsum
ENV GOPRIVATE=
RUN rm ~/.netrc

# Install Node.js modules
WORKDIR /home/pptruser
COPY ./test/e2e/internal/login/login.js ./login.js
RUN npm install js-yaml fs

# Default command
CMD ["bash"]
