Skip to content

Commit eaec53b

Browse files
authored
Ignore SYNC_PORT and SYNC_BASE in syncserver Dockerfile (#3716)
Hardcode them to: SYNC_PORT=8080 SYNC_BASE=/anki_data If these env variables are passed into the container with different values, they are ignored. The reasons is if the user modifies SYNC_BASE they risk data loss since anki-sync-server will no longer write data into the volume. If they change SYNC_PORT they need to also change it when mapping this internal port to the external port of the container, which could be confusing plus it has no benefit to allow this since it's always possible to change the external port even if the internal port is fixed to 8080 (e.g. `-p 1234:8080`). In both cases there is no benefit to making these values configurable and there are risks associated. Unfortunately there is no easy way of implementing this for the Dockerfile.distroless so it's up to the user not to modify these values.
1 parent 5ef8e33 commit eaec53b

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

docs/syncserver/Dockerfile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ anki-sync-server
1111

1212
FROM alpine:3.21.0
1313

14-
ARG SYNC_PORT=8080
15-
1614
# Default PUID and PGID values (can be overridden at runtime). Use these to
1715
# ensure the files on the volume have the permissions you need.
1816
ENV PUID=1000
@@ -22,11 +20,8 @@ COPY --from=builder /anki-server/bin/anki-sync-server /usr/local/bin/anki-sync-s
2220

2321
RUN apk update && apk add --no-cache bash su-exec && rm -rf /var/cache/apk/*
2422

25-
ENV SYNC_PORT=${SYNC_PORT}
26-
27-
ENV SYNC_BASE=/anki_data
2823

29-
EXPOSE ${SYNC_PORT}
24+
EXPOSE 8080
3025

3126
COPY entrypoint.sh /entrypoint.sh
3227
RUN chmod +x /entrypoint.sh
@@ -37,7 +32,7 @@ CMD ["anki-sync-server"]
3732
# This health check will work for Anki versions 24.08.x and newer.
3833
# For older versions, it may incorrectly report an unhealthy status, which should not be the case.
3934
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
40-
CMD wget -qO- http://127.0.0.1:${SYNC_PORT}/health || exit 1
35+
CMD wget -qO- http://127.0.0.1:8080/health || exit 1
4136

4237
VOLUME /anki_data
4338

docs/syncserver/Dockerfile.distroless

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ anki-sync-server
1111

1212
FROM gcr.io/distroless/cc-debian12
1313

14-
ARG SYNC_PORT=8080
15-
1614
COPY --from=builder /anki-server/bin/anki-sync-server /usr/bin/anki-sync-server
1715

18-
ENV SYNC_PORT=${SYNC_PORT}
19-
16+
# Note that as a user of the container you should NOT overwrite these values
17+
# for safety and simplicity reasons
18+
ENV SYNC_PORT=8080
2019
ENV SYNC_BASE=/anki_data
2120

2221
EXPOSE ${SYNC_PORT}

docs/syncserver/README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,25 @@ docker run -d \
7171
```
7272

7373
Moreover, you can pass additional env vars mentioned
74-
[here](https://docs.ankiweb.net/sync-server.html). Note that you should **not**
75-
override SYNC_BASE because you risk data loss.
74+
[here](https://docs.ankiweb.net/sync-server.html). Note that `SYNC_BASE` and
75+
`SYNC_PORT` will be ignored. In the first case for safety reasons, to avoid
76+
accidentally placing data outside the volume and the second for simplicity
77+
since the internal port of the container does not matter given that you can
78+
change the external one.
79+
80+
# Upgrading
81+
82+
If your image was built after January 2025 then you can just build a new image
83+
and start a new container with the same configuration as the previous
84+
container. Everything should work as expected.
85+
86+
If the image you were running was built **before January 2025** then it did not
87+
contain a volume, meaning all syncserver data was stored inside the container.
88+
If you discard the container, for example because you want to build a new
89+
container using an updated image, then your syncserver data will be lost.
90+
91+
The easiest way of working around this is by ensuring at least one of your
92+
devices is fully in sync with your syncserver before upgrading the Docker
93+
container. Then after upgrading the container when you try to sync your device
94+
it will tell you that the server has no data. You will then be given the option
95+
of uploading all local data from the device to syncserver.

docs/syncserver/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ set -o pipefail
77
export PUID=${PUID:-1000}
88
export PGID=${PGID:-1000}
99

10+
# These values are fixed and cannot be overwritten from the outside for
11+
# convenience and safety reasons
12+
export SYNC_PORT=8080
13+
export SYNC_BASE=/anki_data
14+
1015
# Check if group exists, create if not
1116
if ! getent group anki-group > /dev/null 2>&1; then
1217
addgroup -g "$PGID" anki-group

0 commit comments

Comments
 (0)