add Dockerfile
Docker provides a standard way of installing software. This is particularly useful with software that requires fairly complex dependencies, like Anki. The Dockerfile added in this commit builds a Docker image with Anki. The Docker image is based on `python:3.8`, which is based on a Debian Buster image. This Docker image can be useful to end users, because it can be installed on any system that has Docker (e.g., Windows, macOS, Linux), and it is also useful to developers who might not have -- or want to install -- the dependencies that Anki requires at compile time. To build the image, run `docker build --tag anki .` in the project root directory. To run the image with a GUI (on Unix-like systems), run ``` docker run --rm -it --env "DISPLAY=$DISPLAY" --volume /tmp/.X11-unix:/tmp/.X11-unix anki ``` One may also mount a user's Anki directory into the container and run the container as the current user. One may also run with Singularity (which typically has more transparent support for GUI applications and behaving as the current user) by first building the Docker image as above and then converting to Singularity Image Format (SIF) with ``` sudo singularity build anki.sif docker-daemon://anki:latest ``` Run the Singularity image with ``` singularity run anki.sif ```
This commit is contained in:
parent
8d2867aa2d
commit
fa43164ba8
79
Dockerfile
Normal file
79
Dockerfile
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
FROM python:3.8 AS builder
|
||||||
|
|
||||||
|
ARG DEBIAN_FRONTEND="noninteractive"
|
||||||
|
|
||||||
|
# Install rust.
|
||||||
|
ENV CARGO_HOME="/opt/cargo" \
|
||||||
|
RUSTUP_HOME="/opt/rustup"
|
||||||
|
ENV PATH="$CARGO_HOME/bin:$PATH"
|
||||||
|
RUN curl -fsSL --proto '=https' --tlsv1.2 https://sh.rustup.rs \
|
||||||
|
| sh -s -- -y --quiet --no-modify-path \
|
||||||
|
&& rustup update \
|
||||||
|
&& cargo install ripgrep
|
||||||
|
|
||||||
|
# Install system dependencies.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install --yes --no-install-recommends \
|
||||||
|
gettext \
|
||||||
|
lame \
|
||||||
|
mpv \
|
||||||
|
portaudio19-dev \
|
||||||
|
rsync \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install node and npm.
|
||||||
|
WORKDIR /opt/node
|
||||||
|
RUN curl -fsSL --proto '=https' https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz \
|
||||||
|
| tar xJ --strip-components 1
|
||||||
|
ENV PATH="/opt/node/bin:$PATH"
|
||||||
|
|
||||||
|
# Install protoc.
|
||||||
|
WORKDIR /opt/protoc
|
||||||
|
RUN curl -fsSL --proto '=https' -O https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-linux-x86_64.zip \
|
||||||
|
&& unzip protoc-3.11.4-linux-x86_64.zip -x readme.txt \
|
||||||
|
&& rm protoc-3.11.4-linux-x86_64.zip
|
||||||
|
ENV PATH="/opt/protoc/bin:$PATH"
|
||||||
|
|
||||||
|
# Build anki.
|
||||||
|
WORKDIR /opt/anki
|
||||||
|
COPY . .
|
||||||
|
RUN make develop \
|
||||||
|
&& make build
|
||||||
|
|
||||||
|
# Build final image.
|
||||||
|
FROM python:3.8-slim
|
||||||
|
|
||||||
|
# Install system dependencies.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install --yes --no-install-recommends \
|
||||||
|
gettext \
|
||||||
|
lame \
|
||||||
|
libnss3 \
|
||||||
|
libxcb-icccm4 \
|
||||||
|
libxcb-image0 \
|
||||||
|
libxcb-keysyms1 \
|
||||||
|
libxcb-randr0 \
|
||||||
|
libxcb-render-util0 \
|
||||||
|
libxcb-xinerama0 \
|
||||||
|
libxcb-xkb1 \
|
||||||
|
libxkbcommon-x11-0 \
|
||||||
|
libxcomposite1 \
|
||||||
|
mpv \
|
||||||
|
portaudio19-dev \
|
||||||
|
rsync \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install pre-compiled Anki.
|
||||||
|
COPY --from=builder /opt/anki/dist/ /opt/anki/
|
||||||
|
RUN python -m pip install --no-cache-dir \
|
||||||
|
PyQtWebEngine \
|
||||||
|
/opt/anki/*.whl \
|
||||||
|
# Create an anki executable.
|
||||||
|
&& printf "#!/usr/bin/env python\nimport aqt\naqt.run()\n" > /usr/local/bin/anki \
|
||||||
|
&& chmod +x /usr/local/bin/anki \
|
||||||
|
# Create non-root user.
|
||||||
|
&& useradd --create-home anki
|
||||||
|
|
||||||
|
USER anki
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/anki"]
|
Loading…
Reference in New Issue
Block a user