FROM ubuntu:24.04
USER root

ENV GOOGLE_APPLICATION_CREDENTIALS=/app/config/adc.json
ENV CACHE_DB_PATH=/app/config

######################
## Install Packages ##
######################

RUN set -eux; \
	apt-get update; \
	apt-get install -y --no-install-recommends python3 gosu; \
	rm -rf /var/lib/apt/lists/*; \
# verify that the binary works
	gosu nobody true
COPY --from=ghcr.io/astral-sh/uv:0.12.21 /uv /usr/local/bin/uv

##################
## Add Src Code ##
##################
ADD calendar_event_engine /app/calendar_event_engine
COPY pyproject.toml uv.lock /app/
COPY README.md /app


#########################################
## Making Users and Setting Permisions ##
#########################################
RUN groupadd eventg
RUN useradd -m -g eventg eventscraper
RUN chown eventscraper:eventg -R /app
RUN find /app/calendar_event_engine -type f -exec chmod u=r,g=r,o= {} +
RUN find /app/calendar_event_engine -type d -exec chmod u=rx,g=rx,o=rx {} +
RUN chmod u=rx,g=rx,o=rx /app/calendar_event_engine


#################################
## Install Python Dependencies ##
#################################

USER eventscraper
WORKDIR /app
RUN uv sync --frozen --no-dev

RUN mkdir /app/config
VOLUME /app/config


######################
## Copy Entrypoint ##
######################

USER root
ADD ./docker/entrypoint.sh /app/entrypoint.sh
RUN chmod u=rx,g=r,o=r /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
