FROM httpd:2.4.59

RUN apt-get update && \
    apt-get -o Acquire::Retries=3 install -y \
    curl \
    wget \
    python3 \
    python3-pip \
    chromium \
    chromium-common \
    chromium-driver \
    libnss3 \
    libatk-bridge2.0-0 \
    libgtk-3-0 \
    libgbm1 \
    libasound2 \
    fonts-liberation \
    ca-certificates \
    --no-install-recommends \
    --fix-missing && \
    rm -rf /var/lib/apt/lists/*

RUN pip3 install requests selenium --break-system-packages

RUN curl -LO https://go.dev/dl/go1.22.0.linux-amd64.tar.gz \
    && tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz \
    && rm go1.22.0.linux-amd64.tar.gz

ENV PATH="/usr/local/go/bin:${PATH}"

WORKDIR /app
COPY . .

RUN go mod init app || true
RUN go mod tidy
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server .

COPY ./apache/httpd.conf /usr/local/apache2/conf/httpd.conf

EXPOSE 80

CMD sh -c "./server & httpd-foreground"