# Stage 1: Build the Go application
FROM golang:latest AS go_builder

WORKDIR /app

COPY ./main /app/main

# Stage 2: Create the final image with Python 3, Go binary, and Google Chrome
FROM python:3

# NEEDED FOR SCRIPTS WHO USE google-chrome-stable: Install Google Chrome dependencies
RUN apt-get update && apt-get install -y \
    wget \
    ca-certificates \
    fonts-liberation \
    libappindicator3-1 \
    libasound2 \
    libatk-bridge2.0-0 \
    libatk1.0-0 \
    libcups2 \
    libdbus-1-3 \
    libgdk-pixbuf2.0-0 \
    libnspr4 \
    libnss3 \
    libxcomposite1 \
    libxdamage1 \
    libx11-xcb1 \
    libxtst6 \
    lsb-release \
    xdg-utils \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

# NEEDED FOR SCRIPTS WHO USE google-chrome-stable: Download and install Google Chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
    && apt-get update && apt-get install -y google-chrome-stable

WORKDIR /app

# Copy the Go binary from the previous stage
COPY --from=go_builder /app/main /app/main

COPY ./public/swagger/ /app/swagger

# Set up any Python dependencies you might need
# RUN pip install ...

# NEEDED FOR SCRIPTS WHO USE google-chrome-stable: Set up the display variable
ENV DISPLAY=:99

CMD ["./main"]