Skip to content

Commit

Permalink
Make pip package update independent of docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzschmid committed Sep 13, 2024
1 parent fb670c6 commit 99f7a3f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 99f7a3f

Please sign in to comment.