Skip to content

Commit

Permalink
build: updated Dockerfile and .dockerignore
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Apr 9, 2023
1 parent f58ff4f commit 85af1ed
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 13 deletions.
19 changes: 16 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
71 changes: 61 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 85af1ed

Please sign in to comment.