diff --git a/anki-sync/Dockerfile b/anki-sync/Dockerfile index 62eb5e3..c67486b 100644 --- a/anki-sync/Dockerfile +++ b/anki-sync/Dockerfile @@ -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"] diff --git a/anki-sync/bin/download-release.sh b/anki-sync/bin/download-release.sh deleted file mode 100755 index 1ce1fa9..0000000 --- a/anki-sync/bin/download-release.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# file: download-release.sh - - -mkdir -p release - -cd release - -git clone https://github.com/ankicommunity/anki-sync-server - -mv anki-sync-server/src/* . - -rm -rf anki-sync-server - -cd .. \ No newline at end of file diff --git a/anki-sync/bin/entrypoint.sh b/anki-sync/bin/entrypoint.sh index f7a96b8..b05e8bd 100755 --- a/anki-sync/bin/entrypoint.sh +++ b/anki-sync/bin/entrypoint.sh @@ -1,15 +1,13 @@ -#!/bin/sh -# file: entrypoint.sh +#!/bin/bash -# if [ -f "/app/data/auth.db" ]; then -# echo "auth.db found" -# else -# echo "Creating new authentication database: auth.db." -# sqlite3 /app/data/auth.db 'CREATE TABLE auth (user VARCHAR PRIMARY KEY, hash VARCHAR)' -# fi +IFS=',' read -ra USER_ARRAY <<< "$SYNC_USERS" -# echo "Updating database schema" -# python3 utils/migrate_user_tables.py +for index in "${!USER_ARRAY[@]}"; do + USER_PASS="${USER_ARRAY[index]}" + export "SYNC_USER$((index+1))=$USER_PASS" +done + +# Now start the anki-sync-server +echo "Starting anki sync server..." +exec anki-sync-server -echo "Starting anki-sync-server" -python3 -m ankisyncd \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 12f3b33..fa9a42f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,9 @@ services: - ANKISYNCD_DATA_ROOT=/data - ANKISYNCD_AUTH_DB_PATH=/data/auth.db - ANKISYNCD_SESSION_DB_PATH=/data/session.db + - SYNC_USERS=${SYNC_USERS} ports: - - "${ANKI_PORT}:27701" + - "${ANKI_PORT}:8080" volumes: - "${ANKI_VOLUME_PATH}:/data"