FROM golang:bookworm

RUN mkdir -p /meguca/images
ENTRYPOINT ["./scripts/with_postgres.sh"]
CMD ["./meguca", "-a", ":8000"]

ENV DEBIAN_FRONTEND=noninteractive
RUN echo deb-src \
	http://ftp.debian.org/debian/ \
	bullseye main contrib non-free \
	>> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y \
	build-essential \
	pkg-config \
	libwebp-dev \
	libopencv-dev \
	libgeoip-dev geoip-database \
	python3 python3-requests \
	git lsb-release wget curl postgresql-client gzip nasm netcat-openbsd
RUN apt-get dist-upgrade -y

ENV LANG=en_US.UTF-8

WORKDIR /home/meguca

COPY ffmpeg-4.1 ffmpeg
WORKDIR ffmpeg
RUN ./configure
RUN nice -n 19 make -j $(nproc)
RUN make install

WORKDIR /home/meguca

COPY meguca .
COPY thumbnailer ../thumbnailer
COPY meguca_homuchan.patch ../meguca_homuchan.patch
COPY thumbnailer.patch ../thumbnailer.patch


RUN git checkout -b dev
RUN git apply ../meguca_homuchan.patch
RUN git add .
RUN git config --global user.email "you@example.com"
RUN git config --global user.name "Your Name"
RUN git commit -m "init fork"

WORKDIR /home/thumbnailer

RUN git clone https://github.com/meowmin/thumbnailer
RUN cd thumbnailer
RUN git checkout -b dev
RUN git apply ../thumbnailer.patch
RUN git add	.
RUN git commit -m "init fork"

WORKDIR /home/meguca

RUN make

COPY meguca/scripts/with_postgres.sh scripts/with_postgres.sh

COPY config.json config.json
