1- FROM python:3.8
1+ # This Dockerfile is used to build ActivityWatch in a Docker container.
2+ #
3+ # It lets us to build ActivityWatch on any platform that supports Docker,
4+ # it also provides a way to build arm64 releases (not possible with GitHub Actions).
5+
6+ # TODO: Clean up this Dockerfile, it's a mess
7+ # TODO: make use of multi-stage builds
8+ # TODO: Avoid building aw-webui twice
9+ # TODO: Fix aw-server-rust rebuilding in last step
10+ FROM ubuntu:22.10
211
312ARG PORT
413ENV SERVER_PORT=$PORT
@@ -8,31 +17,73 @@ ENV PIP_NO_CACHE_DIR=false
817
918# Install dependencies
1019RUN apt-get update
11- RUN apt-get install -y git build-essential apt-utils wget libfreetype6 libpng-dev libopenblas-dev gcc gfortran
12- RUN python3 -m pip install pipenv
20+ RUN apt-get install -y python3 python3-distutils python3-pip python3-pyqt6 git build-essential apt-utils wget libfreetype6 libpng-dev libopenblas-dev gcc gfortran curl sudo zip
21+
22+ # Add `python` alias for `python3`
23+ RUN ln -s /usr/bin/python3 /usr/bin/python
24+
25+ # Add nodejs repo
26+ RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
27+ RUN apt-get install -y nodejs
28+
29+ # Install rustup
30+ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y
31+ ENV PATH="/root/.cargo/bin:$PATH"
32+ RUN rustup toolchain install nightly --allow-downgrade --profile minimal
33+
34+ # Set up poetry
35+ RUN curl -sSL https://install.python-poetry.org | python3 -
36+ ENV PATH="/root/.local/bin:$PATH"
37+ RUN poetry config virtualenvs.create false
1338
39+ # Create build directory
1440RUN mkdir /app
1541WORKDIR /app
1642
1743# Install dependencies seperately, to utilize caching
1844RUN mkdir /app/aw-core
19- COPY aw-core/requirements.txt /app/aw-core
45+ COPY aw-core/poetry.lock aw-core/pyproject.toml /app/aw-core
2046WORKDIR /app/aw-core
21- RUN pip install -r requirements.txt
47+ RUN poetry install --no-root && rm -rf ~/.cache/pypoetry/{cache,artifacts}
2248
2349RUN mkdir /app/aw-server
24- COPY aw-server/requirements.txt /app/aw-server
50+ COPY aw-server/poetry.lock aw-server/pyproject.toml /app/aw-server
2551WORKDIR /app/aw-server
26- RUN pip install -r requirements.txt
52+ RUN poetry install --no-root && rm -rf ~/.cache/pypoetry/{cache,artifacts}
53+
54+ # Set wether to build in release mode or not
55+ ENV RELEASE=false
56+
57+ RUN mkdir /app/aw-server-rust
58+ COPY aw-server-rust/. /app/aw-server-rust
59+ WORKDIR /app/aw-server-rust
60+ RUN --mount=type=cache,target=/app/aw-server-rust/target \
61+ make build SKIP_WEBUI=true
62+
63+ # Build the webui
64+ # RUN mkdir /app/aw-server/aw-webui
65+ # COPY aw-server/aw-webui/. /app/aw-server/aw-webui
66+ # WORKDIR /app/aw-server/aw-webui
67+ # RUN --mount=type=cache,target=/root/.npm \
68+ # make build
2769
2870# Build the rest
2971WORKDIR /app
3072COPY . /app
3173
32- # Debugging, just for printing the build context
33- # RUN find /tmp/build
74+ # RUN make build SKIP_WEBUI=true
75+
76+ RUN poetry install --no-root
77+ # NOTE: we have to skip aw-qt because there's no arm64 wheel for pyqt6 on PyPI
78+ RUN --mount=type=cache,target=/app/aw-server-rust/target \
79+ --mount=type=cache,target=/root/.npm \
80+ make build SKIP_QT=true
81+ RUN --mount=type=cache,target=/app/aw-server-rust/target \
82+ make package SKIP_QT=true
3483
35- RUN make build SKIP_WEBUI=true
84+ # Cleanup
85+ RUN rm -rf ~/.cache/pypoetry/{cache,artifacts}
86+ RUN rm -rf /app/aw-server-rust/target
3687
3788# Entrypoint
3889ENTRYPOINT ["/bin/sh" , "-c" ]
0 commit comments