Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
# Use an official Python runtime as a parent image
FROM python:3.12-slim

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app
# Set PUID/PGID build arguments
ARG PUID=1000
ARG PGID=1000

# Install the Anki sync server
RUN pip install anki
# Create a non-root user and group first
RUN groupadd -g ${PGID} anki && useradd -u ${PUID} -g anki -m anki

# Set environment variables for the sync server (do not change)
# Set environment variables
ENV PATH="/app/.venv/bin:$PATH"
ENV SYNC_BASE=/data
ENV SYNC_HOST=0.0.0.0
ENV SYNC_PORT=8080
ENV UPDATE_INTERVAL=604800

# Create the data directory
RUN mkdir -p /data
# Create app, venv and data directories
RUN mkdir -p /app /data && \
python3 -m venv /app/.venv

# Expose the port the sync server runs on
EXPOSE 8080
# Install dependencies
RUN pip install anki

# Use PUID and PGID if set, otherwise fallback to default user and group
ARG PUID=1000
ARG PGID=1000
# Copy application files
COPY . /app

# Create group and user based on PUID and PGID
RUN groupadd -g ${PGID} anki && useradd -u ${PUID} -g anki -m anki
# Set ownership
RUN chown -R anki:anki /app /data

# Set the working directory
WORKDIR /app

# Set ownership of the working directory and data directory to the new user
RUN chown -R anki:anki /app && chown -R anki:anki /data
# Expose the port
EXPOSE 8080

# Switch to the non-root user
USER anki

# Run the script to update the package and start the server
# Run the start script
CMD ["/app/start.sh"]
18 changes: 15 additions & 3 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#!/bin/sh

# Update the Anki sync server package
echo "Updating Anki sync server package..."
pip install --upgrade anki
# Function to update the package
update_package() {
echo "Checking for Anki-sync-server updates..."
pip install --upgrade anki
}

# Background loop for periodic updates
(
# Sleep for a short period before the first check
sleep 60
while true; do
update_package
sleep ${UPDATE_INTERVAL:-21600}
done
) &

# Start the Anki sync server
echo "Starting Anki sync server..."
Expand Down