Skip to content

Commit 85af1ed

Browse files
committed
build: updated Dockerfile and .dockerignore
1 parent f58ff4f commit 85af1ed

3 files changed

Lines changed: 85 additions & 13 deletions

File tree

.dockerignore

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
**/*.pyc
2-
.*cache
2+
**/.*cache
3+
**/.cov
4+
**/coverage
5+
6+
**/*.zip
7+
**/*.db*
8+
9+
**/tags
10+
**/dist
11+
**/build
312
**/node_modules
13+
14+
other
15+
16+
aw-server/aw_server/static
17+
!aw-server/aw_server/static/logo.png
418
aw-server-rust/target
5-
aw-android
6-
./other
19+
aw-server-rust/NDK

Dockerfile

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
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

312
ARG PORT
413
ENV SERVER_PORT=$PORT
@@ -8,31 +17,73 @@ ENV PIP_NO_CACHE_DIR=false
817

918
# Install dependencies
1019
RUN 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
1440
RUN mkdir /app
1541
WORKDIR /app
1642

1743
# Install dependencies seperately, to utilize caching
1844
RUN 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
2046
WORKDIR /app/aw-core
21-
RUN pip install -r requirements.txt
47+
RUN poetry install --no-root && rm -rf ~/.cache/pypoetry/{cache,artifacts}
2248

2349
RUN 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
2551
WORKDIR /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
2971
WORKDIR /app
3072
COPY . /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
3889
ENTRYPOINT ["/bin/sh", "-c"]

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ else
5151
echo 'Rust not found, skipping aw-server-rust!'; \
5252
fi
5353
endif
54+
ifeq ($(SKIP_QT),true)
55+
@echo "Skipping aw-qt build"
56+
else
5457
make --directory=aw-qt build
58+
endif
5559
# The below is needed due to: https://github.com/ActivityWatch/activitywatch/issues/173
5660
make --directory=aw-client build
5761
make --directory=aw-core build
@@ -167,8 +171,12 @@ else
167171
mkdir -p dist/activitywatch/aw-server-rust
168172
cp -r aw-server-rust/target/package/* dist/activitywatch/aw-server-rust
169173
endif
174+
ifeq ($(SKIP_QT),true)
175+
@echo "Skipping aw-qt package"
176+
else
170177
make --directory=aw-qt package
171178
cp -r aw-qt/dist/aw-qt/. dist/activitywatch
179+
endif
172180
# Remove problem-causing binaries
173181
rm -f dist/activitywatch/libdrm.so.2 # see: https://github.com/ActivityWatch/activitywatch/issues/161
174182
rm -f dist/activitywatch/libharfbuzz.so.0 # see: https://github.com/ActivityWatch/activitywatch/issues/660#issuecomment-959889230

0 commit comments

Comments
 (0)