FROM alpine:3.19

ENV MIX_ENV prod
ENV PATH "${PATH}:/opt/akkoma/bin"
ENV AKKOMA_CONFIG_PATH "/config/config.exs"

# Install required (and optional) packages
RUN awk 'NR==2' /etc/apk/repositories | sed 's/main/community/' | tee -a /etc/apk/repositories && \
    apk update && \
    apk add su-exec curl unzip ncurses file-dev imagemagick ffmpeg exiftool

# Set entrypoint
COPY ./entrypoint.sh /entrypoint.sh
RUN chown root:root /entrypoint.sh && \
    chmod u+x /entrypoint.sh

# Create a dedicated user for Akkoma
RUN adduser --system --shell /bin/false --home /opt/akkoma akkoma

# Download the release build into a temporary directory and unpack it
# then move the release to the home directory and delete temporary files
ADD 'https://akkoma-updates.s3-website.fr-par.scw.cloud/stable/akkoma-amd64-musl.zip' /tmp/akkoma.zip
RUN unzip /tmp/akkoma.zip -d /tmp/ && \
    mv /tmp/release/* /opt/akkoma && \
    rmdir /tmp/release && \
    rm /tmp/akkoma.zip && \
    chown akkoma -R /opt/akkoma

VOLUME /data
VOLUME /config

WORKDIR /opt/akkoma

EXPOSE 4000

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "pleroma", "start" ]
