diff --git a/.dockerignore b/.dockerignore index 231219e..5b2b6c2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -16,6 +16,6 @@ sync docker-compose.yml # Runtime files -config/ +anki_data/ *.log diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..be60040 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,47 @@ +name: Build & Push (Docker Hub) + +on: + push: + branches: [ "main" ] + tags: [ "v*.*.*" ] + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract repo name + id: repo + run: echo "name=${GITHUB_REPOSITORY#*/}" >> $GITHUB_OUTPUT + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.repo.outputs.name }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha + + - name: Build & push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index 5ab9782..dd9947c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ .env -docker-compose.yml +# Ignore everything in config +anki_data/* + +# But don't ignore these specific files +!anki_data/.gitkeep diff --git a/Dockerfile b/Dockerfile index da82c36..87e2f6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,8 @@ RUN apt-get update && \ libxcb-xinerama0 \ libxcb-cursor0 \ python3-xdg \ + lame \ + mplayer \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -22,10 +24,8 @@ RUN dpkg --remove anki && \ cd anki-launcher-${ANKI_VERSION}-linux && ./install.sh && cd .. && \ rm -rf anki-launcher-${ANKI_VERSION}-linux anki-launcher-${ANKI_VERSION}-linux.tar.zst -# Create a config directory to be mounted and add symbolic links to Anki's real config directories -RUN mkdir -p /config/.local/share && \ - ln -s /config/app/Anki /config/.local/share/Anki && \ - ln -s /config/app/Anki2 /config/.local/share/Anki2 +# Create a config directory to be mounted +RUN mkdir -p /config/.local/share COPY ./root / diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..467d7a0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Lua 🌈 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 2655951..3675a31 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This project is inspired by [pnorcross/anki-desktop-docker](https://github.com/p Why? Because it makes automating Anki (with addons like AnkiConnect) easier. -The Anki desktop app runs in a browser (via VNC) on port `3000`. Your Anki data is stored in a volume mounted at `/config/app` inside the container. +The Anki desktop app runs in a browser (via VNC) on port `3000`. Your Anki data is stored in `anki_data` mounted as a volume at '/config` inside the container. --- @@ -21,7 +21,7 @@ The Anki desktop app runs in a browser (via VNC) on port `3000`. Your Anki data ## Files in This Repo ### `Dockerfile` -Builds the container with Anki 25.02.7 You can change the Anki version, but compatibility may vary. +Builds the container with Anki 25.07.5 You can change the Anki version, but compatibility may vary. ### `docker_installation` Contains commands to install Docker on Ubuntu. @@ -37,52 +37,79 @@ Also uses `curl` to call AnkiConnect. It forces a sync and optionally reschedule --- -## Docker Compose Setup +## How to run + +If you want you can run this using the image `mlcivilengineer/anki-desktop-docker` which is automatically built using Github Actions in this repo. Use the following command: +```bash +docker run -d \ + --name anki-desktop \ + -e PUID=1000 \ + -e PGID=1000 \ + -v "$(pwd)/anki_data:/config" \ + -p 3000:3000 \ + -p 8765:8765 \ + mlcivilengineer/anki-desktop-docker:main +``` + +Then open your browser and head to: + +``` +http://localhost:3000 +``` + +Press Enter after Anki is installed for the first time. Now you can use it as normal. In order to sync with the other clients, put your sync information in the Sync tab. -Create a `docker-compose.yml` in the root of the repo: +## Docker Compose Setup + +If you prefer docker compose instead, use the `docker-compose.yml` in the root of the repo: ```yaml -services: - anki-desktop: - build: +services: + anki-desktop: + image: mlcivilengineer/anki-desktop-docker:main + build: context: ./ dockerfile: Dockerfile environment: - PUID=1000 - PGID=1000 volumes: - - ~/.local/share/Anki2:/config/app/Anki2 - - ~/backups:/config/app/backups - ports: - - 3000:3000 - # Anki Connect port - - 8765:8765 + - ./anki_data:/config + ports: + - 3000:3000 # Web UI + - 8765:8765 # AnkiConnect ```` -* The **first volume** maps your local Anki data (on Ubuntu it's usually at `~/.local/share/Anki2`) into the container. -* The **second volume** is for backups you extract via AnkiConnect. To get started: ```bash git clone cd anki-desktop-docker -docker compose up --build -d +docker compose up -d ``` -Then open your browser and head to: +--- -``` -http://localhost:3000 +## Optional: CJK Font Support + +If you need support for Chinese, Japanese, or Korean (CJK) characters in your Anki cards, you can enable this by uncommenting the following environment variables in the `docker-compose.yml` file: + +```yaml +environment: + - PUID=1000 + - PGID=1000 + # Uncomment the following lines to enable CJK font support + - DOCKER_MODS=linuxserver/mods:universal-package-install + - INSTALL_PACKAGES=language-pack-zh-hans|fonts-arphic-ukai|fonts-arphic-uming|fonts-ipafont-mincho|fonts-ipafont-gothic|fonts-unfonts-core ``` ---- +After making these changes, rebuild your container for the changes to take effect. ## AnkiConnect Configuration -Make sure your AnkiConnect config (inside Anki) looks like this: - +If you want to expose the Anki client to http requests, make sure to install the [AnkiConnect](https://ankiweb.net/shared/info/2055492159) Add-on and to configure the Add-on with: ```json { "apiKey": null, diff --git a/anki_data/.gitkeep b/anki_data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..25fecde --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +services: + anki-desktop: + image: mlcivilengineer/anki-desktop-docker:main + build: + context: ./ + dockerfile: Dockerfile + environment: + - PUID=1000 + - PGID=1000 + # Uncomment the following lines to enable CJK font support + # - DOCKER_MODS=linuxserver/mods:universal-package-install + # - INSTALL_PACKAGES=language-pack-zh-hans|fonts-arphic-ukai|fonts-arphic-uming|fonts-ipafont-mincho|fonts-ipafont-gothic|fonts-unfonts-core + volumes: + - ./anki_data:/config + ports: + - 3000:3000 # Web UI + - 8765:8765 # AnkiConnect diff --git a/root/defaults/autostart b/root/defaults/autostart index 01676c5..9258747 100755 --- a/root/defaults/autostart +++ b/root/defaults/autostart @@ -1,10 +1,6 @@ # Set layout to avoid keybinding warnings setxkbmap -layout us & -sudo chown -R 1000:1000 /config/app && \ -mkdir -p /config/app/Anki2 && \ -mkdir -p /config/app/Anki - export DISABLE_QT5_COMPAT=1 export LC_ALL=en_US.UTF-8 diff --git a/root/defaults/menu.xml b/root/defaults/menu.xml index bc57f27..f17d04e 100644 --- a/root/defaults/menu.xml +++ b/root/defaults/menu.xml @@ -3,7 +3,7 @@ - /usr/bin/anki + /usr/local/bin/anki