diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 1f1ad16fc..280e84705 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -161,7 +161,7 @@ Kai Knoblich Lucas Scharenbroch Antonio Cavallo Han Yeong-woo - +Jean Khawand ******************** The text of the 3 clause BSD license follows: diff --git a/docs/syncserver/Dockerfile b/docs/syncserver/Dockerfile new file mode 100644 index 000000000..89fcc008f --- /dev/null +++ b/docs/syncserver/Dockerfile @@ -0,0 +1,32 @@ +FROM rust:1.76-alpine3.19 AS builder + +ARG ANKI_VERSION + +RUN apk update && apk add --no-cache build-base protobuf && rm -rf /var/cache/apk/* +RUN cargo install --git https://github.com/ankitects/anki.git \ + --tag ${ANKI_VERSION} \ + --root /anki-server \ + anki-sync-server + +FROM alpine:3.19.1 + +RUN adduser -D -h /home/anki anki + +COPY --from=builder /anki-server/bin/anki-sync-server /usr/local/bin/anki-sync-server + + +RUN apk update && apk add --no-cache bash && rm -rf /var/cache/apk/* + +USER anki + +ENV SYNC_PORT=${SYNC_PORT:-"8080"} + +EXPOSE ${SYNC_PORT} + +CMD ["anki-sync-server"] + +# TODO - consider exposing endpoint /health to check on health cause currently it will return 404 error +# HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ +# CMD wget -qO- http://localhost:${SYNC_PORT} || exit 1 + +LABEL maintainer="Jean Khawand " \ No newline at end of file diff --git a/docs/syncserver/README.md b/docs/syncserver/README.md new file mode 100644 index 000000000..4dc78a54c --- /dev/null +++ b/docs/syncserver/README.md @@ -0,0 +1,38 @@ +# Building and running Anki sync server in Docker + +This is an example Dockerfile contributed by an Anki user, which shows how you can run a self-hosted sync server, +similar to what AnkiWeb.net offers. + +Building and running the sync server within a container has the advantage of fully isolating +the build products and runtime dependencies from the rest of your system. + +## Requirements + +- [x] [Docker](https://docs.docker.com/get-started/) + +# Building image + +To proceed with building, you must specify the Anki version you want, by replacing `` with something like `23.12.1`. + +```bash +# Ensure you are running this command inside /docs/syncserver +docker build --no-cache --build-arg ANKI_VERSION= -t anki-sync-server . +``` + +# Run container + +Once done with build, you can proceed with running this image with the following command: + +```bash +# this will create anki server +docker run -d -e "SYNC_USER1=admin:admin" -p 8080:8080 --name anki-sync-server anki-sync-server +``` + +However, if you want to have multiple users, you have to use the following approach: + +```bash +# this will create anki server with multiple users +docker run -d -e "SYNC_USER1=test:test" -e "SYNC_USER2=test2:test2" -p 8080:8080 --name anki-sync-server anki-sync-server +``` + +Moreover, you can pass additional env vars mentioned [here](https://docs.ankiweb.net/sync-server.html)