FROM ubuntu:bionic-20210930
LABEL maintainer="bennett.zachary@outlook.com"

ENV SQUID_VERSION=5.3

# Note that you will need to download the source code into the project directory
ADD ./squid-${SQUID_VERSION}.tar.gz /opt/squid

WORKDIR /opt/squid/squid-${SQUID_VERSION}

RUN apt update && apt install -y gcc g++ make

ENV SQUID_CACHE_DIR=/var/spool/squid \
    SQUID_LOG_DIR=/var/log/squid \
    SQUID_USER=proxy

RUN ./configure \
    --prefix=/usr \
    --localstatedir=/var \
    --libexecdir=${prefix}/lib/squid \
    --datadir=${prefix}/share/squid \
    --sysconfdir=/etc/squid \
    --with-default-user=proxy \
    --with-logdir=${SQUID_LOG_DIR} \
    --with-pidfile=/var/run/squid.pid

RUN make install

COPY entrypoint.sh /sbin/entrypoint.sh
COPY squid.conf /etc/squid/squid.conf
RUN chmod 755 /sbin/entrypoint.sh

# Add a sample user to test basic_getpwnam_auth
ARG USER=testuser
ARG PASS=abc123
RUN useradd -m -s /bin/bash $USER && echo "$USER:$PASS" | chpasswd


RUN chown root /lib/squid/basic_getpwnam_auth
RUN chmod u+s /lib/squid/basic_getpwnam_auth

EXPOSE 3128/tcp
ENTRYPOINT ["/sbin/entrypoint.sh"]
