diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..6ad44f74 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +**/*.pyc +**/.*cache +**/.cov +**/coverage + +**/*.zip +**/*.db* + +**/tags +**/dist +**/build +**/node_modules + +other + +aw-server/aw_server/static +!aw-server/aw_server/static/logo.png +aw-server-rust/target +aw-server-rust/NDK diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c0d040b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,89 @@ +# This Dockerfile is used to build ActivityWatch in a Docker container. +# +# It lets us to build ActivityWatch on any platform that supports Docker, +# it also provides a way to build arm64 releases (not possible with GitHub Actions). + +# TODO: Clean up this Dockerfile, it's a mess +# TODO: make use of multi-stage builds +# TODO: Avoid building aw-webui twice +# TODO: Fix aw-server-rust rebuilding in last step +FROM ubuntu:22.10 + +ARG PORT +ENV SERVER_PORT=$PORT + +# Disables pip caching +ENV PIP_NO_CACHE_DIR=false + +# Install dependencies +RUN apt-get update +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 + +# Add `python` alias for `python3` +RUN ln -s /usr/bin/python3 /usr/bin/python + +# Add nodejs repo +RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - +RUN apt-get install -y nodejs + +# Install rustup +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y +ENV PATH="/root/.cargo/bin:$PATH" +RUN rustup toolchain install nightly --allow-downgrade --profile minimal + +# Set up poetry +RUN curl -sSL https://install.python-poetry.org | python3 - +ENV PATH="/root/.local/bin:$PATH" +RUN poetry config virtualenvs.create false + +# Create build directory +RUN mkdir /app +WORKDIR /app + +# Install dependencies seperately, to utilize caching +RUN mkdir /app/aw-core +COPY aw-core/poetry.lock aw-core/pyproject.toml /app/aw-core +WORKDIR /app/aw-core +RUN poetry install --no-root && rm -rf ~/.cache/pypoetry/{cache,artifacts} + +RUN mkdir /app/aw-server +COPY aw-server/poetry.lock aw-server/pyproject.toml /app/aw-server +WORKDIR /app/aw-server +RUN poetry install --no-root && rm -rf ~/.cache/pypoetry/{cache,artifacts} + +# Set wether to build in release mode or not +ENV RELEASE=false + +RUN mkdir /app/aw-server-rust +COPY aw-server-rust/. /app/aw-server-rust +WORKDIR /app/aw-server-rust +RUN --mount=type=cache,target=/app/aw-server-rust/target \ + make build SKIP_WEBUI=true + +# Build the webui +#RUN mkdir /app/aw-server/aw-webui +#COPY aw-server/aw-webui/. /app/aw-server/aw-webui +#WORKDIR /app/aw-server/aw-webui +#RUN --mount=type=cache,target=/root/.npm \ +# make build + +# Build the rest +WORKDIR /app +COPY . /app + +#RUN make build SKIP_WEBUI=true + +RUN poetry install --no-root +# NOTE: we have to skip aw-qt because there's no arm64 wheel for pyqt6 on PyPI +RUN --mount=type=cache,target=/app/aw-server-rust/target \ + --mount=type=cache,target=/root/.npm \ + make build SKIP_QT=true +RUN --mount=type=cache,target=/app/aw-server-rust/target \ + make package SKIP_QT=true + +# Cleanup +RUN rm -rf ~/.cache/pypoetry/{cache,artifacts} +RUN rm -rf /app/aw-server-rust/target + +# Entrypoint +ENTRYPOINT ["/bin/sh", "-c"] diff --git a/Makefile b/Makefile index 0c6eada9..c233270b 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,11 @@ else echo 'Rust not found, skipping aw-server-rust!'; \ fi endif +ifeq ($(SKIP_QT),true) + @echo "Skipping aw-qt build" +else make --directory=aw-qt build +endif # The below is needed due to: https://github.com/ActivityWatch/activitywatch/issues/173 make --directory=aw-client build make --directory=aw-core build @@ -167,8 +171,12 @@ else mkdir -p dist/activitywatch/aw-server-rust cp -r aw-server-rust/target/package/* dist/activitywatch/aw-server-rust endif +ifeq ($(SKIP_QT),true) + @echo "Skipping aw-qt package" +else make --directory=aw-qt package cp -r aw-qt/dist/aw-qt/. dist/activitywatch +endif # Remove problem-causing binaries rm -f dist/activitywatch/libdrm.so.2 # see: https://github.com/ActivityWatch/activitywatch/issues/161 rm -f dist/activitywatch/libharfbuzz.so.0 # see: https://github.com/ActivityWatch/activitywatch/issues/660#issuecomment-959889230