diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..1667bae --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,60 @@ +name: Docker + +on: + push: + branches: ["main"] + tags: ["v*.*.*"] + pull_request: + branches: ["main"] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index bb21957..40dab6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use an official Python runtime as a parent image -FROM python:3.9-slim +FROM python:3.12-slim # Set the working directory in the container WORKDIR /app @@ -21,5 +21,5 @@ RUN mkdir -p /data # Expose the port the sync server runs on EXPOSE 8080 -# Run the sync server -CMD ["python", "-m", "anki.syncserver"] +# Run the script to update the package and start the server +CMD ["/app/start.sh"] diff --git a/README.md b/README.md index dd1c6db..96ae6e8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,13 @@ This docker container simply wraps the official minimal sync server based on Pyt ## Configuration -The docker container uses the same environmental variable as described in the [official documentation](https://docs.ankiweb.net/sync-server.html). Some meaningful defaults are set. One might want to change the following environmental variables: +The docker container uses the same environmental variable as described in the [official documentation](https://docs.ankiweb.net/sync-server.html). For more information, please consult it directly. The following environmental variables are bound to the container's setup and therefore, should not be changed: + +- `SYNC_BASE` +- `SYNC_HOST` +- `SYNC_PORT` + +At least the following environmental variables has to be set outside of the container: - `SYNC_USER1`: The username and password for the first user in the format `user:password`. @@ -49,6 +55,11 @@ services: ``` +## Updating the Docker Container + +Upon each restart, the docker container verifies that it runs with the most recent version of the official sync server and updates automatically if a new version is available. The docker image itself likely does not need an update. + + ## Building the Docker Image Locally 1. Clone this Repository: diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..978aa7f --- /dev/null +++ b/start.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Update the Anki sync server package +echo "Updating Anki sync server package..." +pip install --upgrade anki + +# Start the Anki sync server +echo "Starting Anki sync server..." +exec python -m anki.syncserver