FROM docker.io/alpine:3.15

ARG TARGETARCH=amd64

RUN apk add --no-cache \
      python3 py3-pip py3-setuptools py3-wheel \
      py3-pillow \
      py3-aiohttp \
      py3-magic \
      py3-ruamel.yaml \
      py3-commonmark \
      py3-prometheus-client \
      # encryption
      py3-olm \
      py3-cffi \
      py3-pycryptodome \
      py3-unpaddedbase64 \
      py3-future \
      # proxy support
      py3-aiohttp-socks \
      py3-pysocks \
      # Other dependencies
      ffmpeg \
      ca-certificates \
      su-exec \
      netcat-openbsd \
      bash \
      curl \
      jq \
      yq

WORKDIR /opt/matrix-appservice-kakaotalk

COPY requirements.txt optional-requirements.txt ./
RUN apk add --virtual .build-deps python3-dev libffi-dev build-base \
 && pip3 install -r requirements.txt -r optional-requirements.txt \
 && apk del .build-deps

# Copy specific files & directories to avoid copying the node directory
COPY LICENSE setup.py docker-run.sh ./
COPY matrix_appservice_kakaotalk matrix_appservice_kakaotalk
RUN apk add --no-cache git && pip3 install .[e2be] && apk del git \
  # This doesn't make the image smaller, but it's needed so that the `version` command works properly
  && cp matrix_appservice_kakaotalk/example-config.yaml . && rm -rf matrix_appservice_kakaotalk

ENV UID=1337 GID=1337
VOLUME /data

CMD ["./docker-run.sh"]