ARG REPO_LOCATION

FROM ${REPO_LOCATION}minideb AS builder

RUN install_packages software-properties-common git gpg dirmngr gpg-agent gcc libc-dev

# Add the golang apt repository
# Note that install_packages runs apt update automatically
# Apparentl apt-add-repository doesn't properly import the GPG key :-/
RUN echo "deb http://ppa.launchpad.net/longsleep/golang-backports/ubuntu focal main" >/etc/apt/sources.list.d/golang.list \
	&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6BC817356A3D45E

RUN install_packages golang-go

RUN git clone https://github.com/go-shiori/shiori.git /srv/shiori

WORKDIR /srv/shiori

RUN git checkout "$(git describe --tags "$(git rev-list --tags --max-count=1)")"

# armv7l+, GOARM can be set as low as 5 if you have an old board (but I have Raspberry Pi 4B+ boards)
RUN GOOS=linux GOARCH=arm GOARM=7 go build -v


FROM ${REPO_LOCATION}minideb

COPY --from=builder /srv/shiori/shiori /srv/shiori
COPY ./run.sh /srv/run.sh

VOLUME /srv/data

WORKDIR /srv/data

USER 95:95

ENTRYPOINT [ "/srv/run.sh" ]

CMD [ "serve" ]