Changed to docker image that builds from source

This commit is contained in:
bj
2023-09-07 10:52:31 +00:00
parent 4a8c1de794
commit 3d0ec7f2f6
4 changed files with 36 additions and 79 deletions
+24 -51
View File
@@ -1,59 +1,32 @@
ARG ANKISYNCD_ROOT=/opt/ankisyncd
ARG PYTHONUSERBASE=/opt/venv
# Set the base image
FROM rust:latest as builder
# -- BUILDER --
FROM library/python:3.9-buster as builder
# Install dependencies
RUN apt-get update && apt-get install -y protobuf-compiler
ARG ANKISYNCD_ROOT
WORKDIR ${ANKISYNCD_ROOT}
# Build the Anki sync server
WORKDIR /usr/src/ankisyncd
RUN cargo install --git https://github.com/ankitects/anki.git --tag 2.1.66 anki-sync-server
COPY bin/download-release.sh ./bin/download-release.sh
# Create a deploy image for smaller size
FROM debian:bookworm-slim
COPY --from=builder /usr/local/cargo/bin/anki-sync-server /usr/local/bin/
ARG PYTHONUSERBASE
RUN sh ./bin/download-release.sh && \
pip3 install --upgrade pip && \
pip3 install --user -r ./release/requirements.txt
# Set environment variables for the sync server
ENV ANKISYNCD_DATA_ROOT=/data
ENV ANKISYNCD_AUTH_DB_PATH=/data/auth.db
ENV ANKISYNCD_SESSION_DB_PATH=/data/session.db
ENV SYNC_BASE=/data
# -- DEPLOYER --
FROM python:3.9-slim-buster
# Create a directory for data
VOLUME /data
# Copy Python dependencies
ARG PYTHONUSERBASE
ENV PYTHONUSERBASE=${PYTHONUSERBASE}
COPY --from=builder ${PYTHONUSERBASE} ${PYTHONUSERBASE}
# Expose the default port
EXPOSE 27701
# Copy Anki Sync Server release and scripts
ARG ANKISYNCD_ROOT
COPY --from=builder ${ANKISYNCD_ROOT}/release ${ANKISYNCD_ROOT}
WORKDIR ${ANKISYNCD_ROOT}
# Copy the entrypoint script and make it executable
COPY bin/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Move ankisyncctl.py to the working directory and make it executable
RUN mv /opt/ankisyncd/ankisyncd_cli/ankisyncctl.py /opt/ankisyncd/ankisyncctl.py && \
chmod +x /opt/ankisyncd/ankisyncctl.py
# Create data volume.
ARG ANKISYNCD_DATA_ROOT=/srv/ankisyncd
VOLUME ${ANKISYNCD_DATA_ROOT}
# Set default environment variables.
ARG ANKISYNCD_PORT=27701
ARG ANKISYNCD_BASE_URL=/sync/
ARG ANKISYNCD_BASE_MEDIA_URL=/msync/
ENV ANKISYNCD_HOST=0.0.0.0 \
ANKISYNCD_PORT=${ANKISYNCD_PORT} \
ANKISYNCD_DATA_ROOT=${ANKISYNCD_DATA_ROOT} \
ANKISYNCD_BASE_URL=${ANKISYNCD_BASE_URL} \
ANKISYNCD_BASE_MEDIA_URL=${ANKISYNCD_BASE_MEDIA_URL} \
ANKISYNCD_AUTH_DB_PATH=/data/auth.db \
ANKISYNCD_SESSION_DB_PATH=/data/session.db \
ANKISYNCD_DATA_ROOT=/data
COPY bin/entrypoint.sh ./bin/entrypoint.sh
EXPOSE ${ANKISYNCD_PORT}
# TODO: Change to ENTRYPOINT. Currently CMD to allow shell access if needed.
CMD ["/bin/sh", "./bin/entrypoint.sh"]
HEALTHCHECK --interval=60s --timeout=3s CMD python -c "import requests; requests.get('http://127.0.0.1:${ANKISYNCD_PORT}/')"
# Set the entrypoint for the container
ENTRYPOINT ["/entrypoint.sh"]