Changed to docker image that builds from source

master
B.J. Dweck 2023-09-07 10:52:31 +00:00
parent 4a8c1de794
commit 3d0ec7f2f6
4 changed files with 36 additions and 79 deletions

View File

@ -1,59 +1,32 @@
ARG ANKISYNCD_ROOT=/opt/ankisyncd # Set the base image
ARG PYTHONUSERBASE=/opt/venv FROM rust:latest as builder
# -- BUILDER -- # Install dependencies
FROM library/python:3.9-buster as builder RUN apt-get update && apt-get install -y protobuf-compiler
ARG ANKISYNCD_ROOT # Build the Anki sync server
WORKDIR ${ANKISYNCD_ROOT} 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 # Set environment variables for the sync server
RUN sh ./bin/download-release.sh && \ ENV ANKISYNCD_DATA_ROOT=/data
pip3 install --upgrade pip && \ ENV ANKISYNCD_AUTH_DB_PATH=/data/auth.db
pip3 install --user -r ./release/requirements.txt ENV ANKISYNCD_SESSION_DB_PATH=/data/session.db
ENV SYNC_BASE=/data
# -- DEPLOYER -- # Create a directory for data
FROM python:3.9-slim-buster VOLUME /data
# Copy Python dependencies # Expose the default port
ARG PYTHONUSERBASE EXPOSE 27701
ENV PYTHONUSERBASE=${PYTHONUSERBASE}
COPY --from=builder ${PYTHONUSERBASE} ${PYTHONUSERBASE}
# Copy Anki Sync Server release and scripts # Copy the entrypoint script and make it executable
ARG ANKISYNCD_ROOT COPY bin/entrypoint.sh /entrypoint.sh
COPY --from=builder ${ANKISYNCD_ROOT}/release ${ANKISYNCD_ROOT} RUN chmod +x /entrypoint.sh
WORKDIR ${ANKISYNCD_ROOT}
# Move ankisyncctl.py to the working directory and make it executable # Set the entrypoint for the container
RUN mv /opt/ankisyncd/ankisyncd_cli/ankisyncctl.py /opt/ankisyncd/ankisyncctl.py && \ ENTRYPOINT ["/entrypoint.sh"]
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}/')"

View File

@ -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 ..

View File

@ -1,15 +1,13 @@
#!/bin/sh #!/bin/bash
# file: entrypoint.sh
# if [ -f "/app/data/auth.db" ]; then IFS=',' read -ra USER_ARRAY <<< "$SYNC_USERS"
# 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
# echo "Updating database schema" for index in "${!USER_ARRAY[@]}"; do
# python3 utils/migrate_user_tables.py 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

View File

@ -6,8 +6,9 @@ services:
- ANKISYNCD_DATA_ROOT=/data - ANKISYNCD_DATA_ROOT=/data
- ANKISYNCD_AUTH_DB_PATH=/data/auth.db - ANKISYNCD_AUTH_DB_PATH=/data/auth.db
- ANKISYNCD_SESSION_DB_PATH=/data/session.db - ANKISYNCD_SESSION_DB_PATH=/data/session.db
- SYNC_USERS=${SYNC_USERS}
ports: ports:
- "${ANKI_PORT}:27701" - "${ANKI_PORT}:8080"
volumes: volumes:
- "${ANKI_VOLUME_PATH}:/data" - "${ANKI_VOLUME_PATH}:/data"