2023-08-22 21:23:18 +00:00
|
|
|
ARG PYTHONVER=3.11
|
|
|
|
## Base build stage for Slidge, prepares and installs common dependencies.
|
|
|
|
FROM docker.io/library/python:$PYTHONVER-bookworm AS builder
|
|
|
|
ARG PYTHONVER
|
|
|
|
ENV PATH="/venv/bin:/root/.local/bin:$PATH"
|
|
|
|
|
|
|
|
# rust/cargo is for building "cryptography" since they don't provide wheels for arm32
|
2024-02-17 07:59:31 +00:00
|
|
|
RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/sources.list \
|
|
|
|
&& apt-get update -y && apt-get install -y --no-install-recommends \
|
2023-08-22 21:23:18 +00:00
|
|
|
build-essential \
|
|
|
|
ca-certificates \
|
|
|
|
cargo \
|
|
|
|
curl \
|
|
|
|
git \
|
|
|
|
gcc \
|
|
|
|
g++ \
|
|
|
|
libffi-dev \
|
|
|
|
libssl-dev \
|
|
|
|
pkg-config \
|
|
|
|
python3-dev \
|
|
|
|
rustc \
|
2024-02-17 07:59:31 +00:00
|
|
|
&& apt-get install -y golang -t bookworm-backports
|
2023-08-22 21:23:18 +00:00
|
|
|
|
2023-09-10 19:57:24 +00:00
|
|
|
RUN pip install poetry
|
2023-08-22 21:23:18 +00:00
|
|
|
RUN python3 -m venv /venv
|
|
|
|
RUN ln -s /venv/lib/python$PYTHONVER /venv/lib/python
|
|
|
|
|
|
|
|
WORKDIR /build
|
2023-04-25 12:40:54 +00:00
|
|
|
|
2023-06-16 19:04:23 +00:00
|
|
|
ENV GOBIN="/usr/local/bin"
|
2023-12-14 18:57:27 +00:00
|
|
|
RUN go install -v github.com/go-python/gopy@latest
|
2023-04-25 12:40:54 +00:00
|
|
|
RUN go install golang.org/x/tools/cmd/goimports@latest
|
|
|
|
|
|
|
|
ENV PATH="/root/.local/bin:$PATH"
|
|
|
|
COPY poetry.lock pyproject.toml /build/
|
|
|
|
|
|
|
|
RUN poetry export --without-hashes > requirements.txt
|
|
|
|
RUN python3 -m pip install --requirement requirements.txt
|
|
|
|
|
2023-06-16 19:04:23 +00:00
|
|
|
COPY ./slidge_whatsapp/*.go ./slidge_whatsapp/go.* /build/
|
|
|
|
RUN gopy build -output=generated -no-make=true /build/
|
2023-04-25 12:40:54 +00:00
|
|
|
|
|
|
|
FROM docker.io/nicocool84/slidge-base AS slidge-whatsapp
|
|
|
|
|
Implement on-the-fly outgoing media conversion
WhatsApp clients are set to accept only a specific set of media files as
image, audio, or video messages, specifically:
- Images must be in JPEG (non-progressive) format.
- Audio messages must be in Opus-encoded Ogg if sent as voice messages,
otherwise may be in MP3 or AAC format if not (though client support
may vary).
- Video messages must be in h264-encoded MP4, with some additional
constraints on color format and profile used.
Several edge-cases exist, e.g. with GIF files needing to be re-encoded
as MP4 in order to be animated (and requiring extra metadata in messages
to be called out as such).
This commit implements a somewhat comprehensive media conversion scheme,
built upon FFmpeg for audio and video, and native Go facilities for
images, based on the source format. Specifically:
- Audio files in `audio/mp4` or `audio/aac` format (corresponding to
formats commonly used in Android and iOS XMPP clients, respectively)
are automatically re-encoded as Opus-encoded voice messages.
- Audio files in `audio/mpeg` (i.e. MP3 files) or `audio/ogg` format
are sent as plain audio files in their own format, with varying client
support assumed.
- Images in `image/png` or `image/webp` format are automatically
re-encoded as JPEG image messages. Conversely, images in `image/gif`
format are re-encoded as MP4 video messages with auto-play enabled.
- Videos in `video/webm` or `video/mp4` format are automatically
re-encoded as MP4 video messages (the latter is re-encoded to ensure
option compatibility).
As stated above, all audio and video conversions require FFmpeg and
FFprobe to be installed, and, if missing, will leave attachments
unchanged (which may result these being sent as binary files). Image
conversions do not rely on any external functionality, however.
Current limits are: 10MiB for images and 20MiB for audio and video
files; above these conversions will fail and original files will be sent
instead.
Future commits may see compatibility improved, or semantics corrected
where these do not match expectations on the WhatsApp side.
2023-07-17 21:21:31 +00:00
|
|
|
USER root
|
|
|
|
RUN apt update -y && apt install ffmpeg -y
|
|
|
|
|
2023-08-22 21:23:18 +00:00
|
|
|
COPY --from=builder /venv /venv
|
2023-04-25 12:40:54 +00:00
|
|
|
COPY ./slidge_whatsapp/*.py /venv/lib/python/site-packages/legacy_module/
|
2023-08-22 21:23:18 +00:00
|
|
|
COPY --from=builder /build/generated /venv/lib/python/site-packages/legacy_module/generated
|
2023-04-25 12:40:54 +00:00
|
|
|
|
Implement on-the-fly outgoing media conversion
WhatsApp clients are set to accept only a specific set of media files as
image, audio, or video messages, specifically:
- Images must be in JPEG (non-progressive) format.
- Audio messages must be in Opus-encoded Ogg if sent as voice messages,
otherwise may be in MP3 or AAC format if not (though client support
may vary).
- Video messages must be in h264-encoded MP4, with some additional
constraints on color format and profile used.
Several edge-cases exist, e.g. with GIF files needing to be re-encoded
as MP4 in order to be animated (and requiring extra metadata in messages
to be called out as such).
This commit implements a somewhat comprehensive media conversion scheme,
built upon FFmpeg for audio and video, and native Go facilities for
images, based on the source format. Specifically:
- Audio files in `audio/mp4` or `audio/aac` format (corresponding to
formats commonly used in Android and iOS XMPP clients, respectively)
are automatically re-encoded as Opus-encoded voice messages.
- Audio files in `audio/mpeg` (i.e. MP3 files) or `audio/ogg` format
are sent as plain audio files in their own format, with varying client
support assumed.
- Images in `image/png` or `image/webp` format are automatically
re-encoded as JPEG image messages. Conversely, images in `image/gif`
format are re-encoded as MP4 video messages with auto-play enabled.
- Videos in `video/webm` or `video/mp4` format are automatically
re-encoded as MP4 video messages (the latter is re-encoded to ensure
option compatibility).
As stated above, all audio and video conversions require FFmpeg and
FFprobe to be installed, and, if missing, will leave attachments
unchanged (which may result these being sent as binary files). Image
conversions do not rely on any external functionality, however.
Current limits are: 10MiB for images and 20MiB for audio and video
files; above these conversions will fail and original files will be sent
instead.
Future commits may see compatibility improved, or semantics corrected
where these do not match expectations on the WhatsApp side.
2023-07-17 21:21:31 +00:00
|
|
|
USER slidge
|
|
|
|
|
2023-08-22 21:23:18 +00:00
|
|
|
FROM builder AS slidge-whatsapp-dev
|
2023-04-25 12:40:54 +00:00
|
|
|
|
2023-05-13 15:09:53 +00:00
|
|
|
COPY --from=docker.io/nicocool84/slidge-prosody-dev:latest /etc/prosody/certs/localhost.crt /usr/local/share/ca-certificates/
|
2023-04-25 12:40:54 +00:00
|
|
|
RUN update-ca-certificates
|
|
|
|
|
Implement on-the-fly outgoing media conversion
WhatsApp clients are set to accept only a specific set of media files as
image, audio, or video messages, specifically:
- Images must be in JPEG (non-progressive) format.
- Audio messages must be in Opus-encoded Ogg if sent as voice messages,
otherwise may be in MP3 or AAC format if not (though client support
may vary).
- Video messages must be in h264-encoded MP4, with some additional
constraints on color format and profile used.
Several edge-cases exist, e.g. with GIF files needing to be re-encoded
as MP4 in order to be animated (and requiring extra metadata in messages
to be called out as such).
This commit implements a somewhat comprehensive media conversion scheme,
built upon FFmpeg for audio and video, and native Go facilities for
images, based on the source format. Specifically:
- Audio files in `audio/mp4` or `audio/aac` format (corresponding to
formats commonly used in Android and iOS XMPP clients, respectively)
are automatically re-encoded as Opus-encoded voice messages.
- Audio files in `audio/mpeg` (i.e. MP3 files) or `audio/ogg` format
are sent as plain audio files in their own format, with varying client
support assumed.
- Images in `image/png` or `image/webp` format are automatically
re-encoded as JPEG image messages. Conversely, images in `image/gif`
format are re-encoded as MP4 video messages with auto-play enabled.
- Videos in `video/webm` or `video/mp4` format are automatically
re-encoded as MP4 video messages (the latter is re-encoded to ensure
option compatibility).
As stated above, all audio and video conversions require FFmpeg and
FFprobe to be installed, and, if missing, will leave attachments
unchanged (which may result these being sent as binary files). Image
conversions do not rely on any external functionality, however.
Current limits are: 10MiB for images and 20MiB for audio and video
files; above these conversions will fail and original files will be sent
instead.
Future commits may see compatibility improved, or semantics corrected
where these do not match expectations on the WhatsApp side.
2023-07-17 21:21:31 +00:00
|
|
|
RUN apt update -y && apt install ffmpeg -y
|
2023-04-25 12:40:54 +00:00
|
|
|
RUN pip install watchdog[watchmedo]
|
|
|
|
ENV SLIDGE_LEGACY_MODULE=slidge_whatsapp
|
|
|
|
|
|
|
|
COPY ./watcher.py /
|
2023-06-16 19:04:23 +00:00
|
|
|
USER root
|
2023-04-25 12:40:54 +00:00
|
|
|
|
2024-04-29 18:14:13 +00:00
|
|
|
ENTRYPOINT ["python", "/watcher.py", "/venv/lib/python/site-packages/slidge:/venv/lib/python/site-packages/slidge_whatsapp", "--dev-mode", "--log-format", "%(levelname)s:%(threadName)s:%(name)s:%(message)s"]
|
2023-04-25 12:40:54 +00:00
|
|
|
|
|
|
|
# wheel builder
|
|
|
|
# docker buildx build . --target wheel \
|
|
|
|
# --platform linux/arm64,linux/amd64 \
|
|
|
|
# -o ./dist/
|
2023-08-22 21:23:18 +00:00
|
|
|
FROM builder AS builder-wheel
|
2023-04-25 12:40:54 +00:00
|
|
|
|
|
|
|
RUN pip install pybindgen
|
|
|
|
COPY go.* /build/
|
|
|
|
COPY README.md /build/
|
|
|
|
COPY slidge_whatsapp/*.py /build/slidge_whatsapp/
|
|
|
|
COPY slidge_whatsapp/*.go /build/slidge_whatsapp/
|
|
|
|
COPY build.py /build/
|
|
|
|
|
|
|
|
RUN poetry build
|
|
|
|
RUN ls -l ./dist
|
|
|
|
RUN python --version
|
|
|
|
|
|
|
|
FROM scratch as wheel
|
|
|
|
COPY --from=builder-wheel ./build/dist/* /
|