Skip to content

Commit 1fa58bd

Browse files
authored
Merge pull request #1990 from wger-project/feature/update-translations-docker
Compile django translations on docker build time
2 parents 6398a9e + 0911741 commit 1fa58bd

File tree

6 files changed

+247
-155
lines changed

6 files changed

+247
-155
lines changed

.dockerignore

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Docker
6+
Dockerfile*
7+
.dockerignore
8+
9+
# Python
10+
__pycache__/
11+
*.pyo
12+
*.pyd
113
.venv
214
venv
3-
node_modules
415
*.sqlite3
5-
**/__pycache__
616
*.egg-info
717

18+
# IDE / OS specific
19+
.idea/
20+
.vscode/
21+
*.swp
22+
.DS_Store
23+
824
# Other files and folders
925
/coverage.lcov
1026
/media/
1127
/static/
1228
/db/
13-
/extras/docker/open-food-facts/dump/*.tar.gz
14-
/extras/docker/open-food-facts/dump/off/*
29+
/extras/open-food-facts/dump/
1530
/extras/authors/commits_cache/
1631
/extras/authors/*.md
1732
/extras/scripts/*.json

extras/docker/base/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
FROM ubuntu:24.04
1212

13-
LABEL maintainer="Roland Geider <[email protected]>"
13+
LABEL org.opencontainers.image.authors="wger team <[email protected]>"
1414

1515
# Install dependencies
1616
ENV DEBIAN_FRONTEND=noninteractive

extras/docker/demo/Dockerfile

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
FROM wger/base:latest AS builder
2121
ARG DEBIAN_FRONTEND=noninteractive
2222

23-
RUN apt update \
23+
RUN wget -O- https://deb.nodesource.com/setup_22.x | bash - \
24+
&& apt update \
2425
&& apt install --no-install-recommends -y \
2526
build-essential \
2627
python3-dev \
@@ -32,31 +33,33 @@ RUN apt update \
3233
libpq-dev \
3334
rustc \
3435
cargo \
35-
yarnpkg \
3636
sassc \
37-
&& ln -s /usr/bin/yarnpkg /usr/bin/yarn \
38-
&& ln -s /usr/bin/sassc /usr/bin/sass
37+
nodejs \
38+
&& ln -s /usr/bin/sassc /usr/bin/sass \
39+
&& rm -rf /var/lib/apt/lists/* \
40+
&& corepack enable
3941

4042
# Build the necessary python wheels
4143
# Note that the --mount is a workaround for https://github.com/rust-lang/cargo/issues/8719
42-
COPY pyproject.toml .
43-
COPY wger/version.py ./wger/version.py
44-
COPY wger/__init__.py ./wger/__init__.py
45-
COPY README.md ./README.md
46-
RUN --mount=type=tmpfs,target=/root/.cargo pip3 wheel --no-cache-dir --wheel-dir /wheels --group docker . \
47-
&& pip3 install --break-system-packages --user --no-cache-dir /wheels/*
48-
49-
COPY . /home/wger/src
5044
WORKDIR /home/wger/src
51-
RUN yarn install \
52-
&& yarn build:css:sass
45+
46+
COPY pyproject.toml /home/wger/src
47+
COPY wger/version.py /home/wger/src/wger/
48+
COPY wger/__init__.py /home/wger/src/wger/
49+
COPY README.md /home/wger/src
50+
COPY package.json /home/wger/src
51+
COPY yarn.lock /home/wger/src
52+
COPY wger/core/static /home/wger/src/wger/core/static
53+
RUN --mount=type=tmpfs,target=/root/.cargo pip3 wheel --no-cache-dir --wheel-dir /wheels --group docker . \
54+
&& yarn install \
55+
&& yarn build:css:sass
5356

5457

5558
########
5659
# Final
5760
########
5861
FROM wger/base:latest AS final
59-
LABEL maintainer="Roland Geider <[email protected]>"
62+
LABEL org.opencontainers.image.authors="wger team <[email protected]>"
6063
ENV TERM=xterm
6164
ARG DOCKER_DIR=./extras/docker/demo
6265
EXPOSE 80
@@ -90,7 +93,6 @@ RUN chmod 0644 /etc/cron.d/wger \
9093
&& chmod +x /home/wger/venvwrapper \
9194
&& touch /var/log/cron.log
9295

93-
COPY --from=builder /wheels /wheels
9496
COPY --chown=wger:www-data . /home/wger/src
9597
COPY --from=builder --chown=wger:wger /home/wger/src/wger/core/static/yarn /home/wger/src/wger/core/static/yarn
9698

@@ -107,7 +109,7 @@ RUN mkdir -p ~/static/CACHE ~/media \
107109
&& ln -s /home/wger/static/CACHE /home/wger/src/CACHE \
108110
&& chmod g+w /home/wger/static/CACHE
109111

110-
RUN . /home/wger/venv/bin/activate \
112+
RUN --mount=type=bind,from=builder,source=/wheels,target=/wheels . /home/wger/venv/bin/activate \
111113
&& pip install --upgrade pip \
112114
&& pip install --no-cache /wheels/* \
113115
&& pip install -e . \

extras/docker/production/Dockerfile

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
FROM wger/base:latest AS builder
1515
ARG DEBIAN_FRONTEND=noninteractive
1616

17-
RUN apt update \
17+
# Need a newer node than what's in ubuntu
18+
RUN wget -O- https://deb.nodesource.com/setup_22.x | bash - \
19+
&& apt update \
1820
&& apt install --no-install-recommends -y \
1921
build-essential \
2022
python3-dev \
@@ -25,61 +27,67 @@ RUN apt update \
2527
libwebp-dev \
2628
libpq-dev \
2729
rustc \
28-
yarnpkg \
2930
sassc \
30-
cargo
31+
cargo \
32+
unzip \
33+
nodejs \
34+
&& rm -rf /var/lib/apt/lists/* \
35+
&& corepack enable \
36+
&& mkdir -p /root/src/wger/core/static
37+
3138

32-
# Build the necessary python wheels
3339
#
34-
# PS: the --mount tmpfs is a workaround for https://github.com/rust-lang/cargo/issues/8719
40+
# Build the python wheels
3541
#
36-
# PPS: actually only pyproject.toml is needed here, but it seems there is no way
37-
# to tell pip to only build the dependencies and not the project itself as well,
38-
# so we copy enough to make this is possible
39-
COPY pyproject.toml .
40-
COPY wger/version.py ./wger/version.py
41-
COPY wger/__init__.py ./wger/__init__.py
42-
COPY README.md ./README.md
42+
WORKDIR /root/src
43+
44+
# Copy necessary files to build the application
45+
COPY pyproject.toml /root/src
46+
COPY wger/version.py /root/src/wger/
47+
COPY wger/__init__.py /root/src/wger/
48+
COPY README.md /root/src
49+
COPY package.json /root/src
50+
COPY yarn.lock /root/src
51+
COPY wger/core/static /root/src/wger/core/static
4352

53+
# NB: the --mount tmpfs is a workaround for https://github.com/rust-lang/cargo/issues/8719
4454
RUN --mount=type=tmpfs,target=/root/.cargo \
4555
pip3 wheel \
4656
--no-cache-dir \
4757
--wheel-dir /wheels \
4858
--group docker . \
49-
&& pip3 install \
50-
--break-system-packages \
51-
--no-warn-script-location \
52-
--root-user-action ignore \
53-
--user \
54-
--no-cache-dir /wheels/* \
55-
&& ln -s /usr/bin/yarnpkg /usr/bin/yarn \
5659
&& ln -s /usr/bin/sassc /usr/bin/sass
5760

58-
59-
# Download and copy js and css files
60-
COPY . /home/wger/src
61-
WORKDIR /home/wger/src
62-
RUN yarn install \
63-
&& yarn build:css:sass
61+
#
62+
# Build the JS and CSS files
63+
#
64+
RUN yarn config set nodeLinker node-modules \
65+
&& yarn install \
66+
&& yarn build:css:sass \
67+
&& cd .. \
68+
&& wget https://github.com/wger-project/react/archive/refs/heads/master.zip \
69+
&& unzip master.zip \
70+
&& cd react-master \
71+
&& yarn config set --home enableTelemetry 0 \
72+
&& yarn config set nodeLinker node-modules \
73+
&& yarn install \
74+
&& WGER_STATIC_FOLDER="/root/src/wger/core/static/react" yarn build
6475

6576

6677
########
6778
# Final
6879
########
6980
FROM wger/base:latest AS final
70-
LABEL maintainer="Roland Geider <[email protected]>"
81+
LABEL org.opencontainers.image.authors="wger team <[email protected]>"
7182
ARG DOCKER_DIR=./extras/docker/production
7283
ENV PATH="/home/wger/.local/bin:$PATH"
73-
84+
WORKDIR /home/wger/src
7485
EXPOSE 8000
7586

76-
7787
# Set up the application
78-
COPY --from=builder --chown=wger:wger /root/.local /home/wger/.local
79-
80-
WORKDIR /home/wger/src
8188
COPY --chown=wger:wger . /home/wger/src
82-
COPY --from=builder --chown=wger:wger /home/wger/src/wger/core/static/yarn /home/wger/src/wger/core/static/yarn
89+
COPY --chown=wger:wger --from=builder /root/src/wger/core/static/yarn /home/wger/src/wger/core/static/yarn
90+
COPY --chown=wger:wger --from=builder /root/src/wger/core/static/react /home/wger/src/wger/core/static/react
8391
COPY ${DOCKER_DIR}/settings.py /home/wger/src
8492
COPY ${DOCKER_DIR}/settings.py /tmp/
8593
COPY ${DOCKER_DIR}/entrypoint.sh /home/wger/entrypoint.sh
@@ -93,10 +101,11 @@ RUN chmod +x /home/wger/entrypoint.sh \
93101
&& chown wger:wger /home/wger/src
94102

95103
USER wger
96-
RUN pip3 install --break-system-packages --user --editable . \
97-
&& mkdir ~/media \
98-
&& mkdir ~/static \
99-
&& mkdir ~/beat \
100-
&& mkdir ~/db
104+
RUN --mount=type=bind,from=builder,source=/wheels,target=/wheels \
105+
pip3 install --break-system-packages --no-cache-dir --user /wheels/* \
106+
&& pip3 install --break-system-packages --user . \
107+
&& mkdir -p ~/media ~/static ~/beat ~/db \
108+
&& cd wger \
109+
&& django-admin compilemessages
101110

102111
CMD ["/home/wger/entrypoint.sh"]

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
},
1111
"homepage": "https://github.com/wger-project/wger",
1212
"dependencies": {
13-
"htmx.org": "^2.0.5",
13+
"@popperjs/core": "^2.11.8",
1414
"bootstrap": "5.3.7",
1515
"components-font-awesome": "5.9.0",
1616
"datatables.net-bs5": "^2.3.1",
1717
"devbridge-autocomplete": "^1.4.11",
18+
"htmx.org": "^2.0.5",
1819
"jquery": "^3.7.1",
1920
"masonry-layout": "^4.2.2",
2021
"popper.js": "^1.16.1",
@@ -25,5 +26,6 @@
2526
},
2627
"engines": {
2728
"yarn": ">= 1.0.0"
28-
}
29+
},
30+
"packageManager": "[email protected]"
2931
}

0 commit comments

Comments
 (0)