From 85af1ed62734085ce938cc36ff71ae6460831661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Sun, 9 Apr 2023 15:09:32 +0200 Subject: [PATCH] build: updated Dockerfile and .dockerignore --- .dockerignore | 19 +++++++++++--- Dockerfile | 71 +++++++++++++++++++++++++++++++++++++++++++-------- Makefile | 8 ++++++ 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/.dockerignore b/.dockerignore index 88e5bcd5..6ad44f74 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,19 @@ **/*.pyc -.*cache +**/.*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-android -./other +aw-server-rust/NDK diff --git a/Dockerfile b/Dockerfile index b8966945..c0d040b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,13 @@ -FROM python:3.8 +# 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 @@ -8,31 +17,73 @@ ENV PIP_NO_CACHE_DIR=false # Install dependencies RUN apt-get update -RUN apt-get install -y git build-essential apt-utils wget libfreetype6 libpng-dev libopenblas-dev gcc gfortran -RUN python3 -m pip install pipenv +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/requirements.txt /app/aw-core +COPY aw-core/poetry.lock aw-core/pyproject.toml /app/aw-core WORKDIR /app/aw-core -RUN pip install -r requirements.txt +RUN poetry install --no-root && rm -rf ~/.cache/pypoetry/{cache,artifacts} RUN mkdir /app/aw-server -COPY aw-server/requirements.txt /app/aw-server +COPY aw-server/poetry.lock aw-server/pyproject.toml /app/aw-server WORKDIR /app/aw-server -RUN pip install -r requirements.txt +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 -# Debugging, just for printing the build context -#RUN find /tmp/build +#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 -RUN make build SKIP_WEBUI=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