11# syntax=docker/dockerfile:1.3
22FROM node:14 AS frontend-builder
33
4- ENV NPM_CACHE_LOCATION=/root /.npm \
4+ ENV NPM_CACHE_LOCATION=$HOME /.npm \
55 PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
66
77WORKDIR /label-studio/label_studio/frontend
88
9- COPY label_studio/frontend .
10- COPY label_studio/__init__.py /label-studio/label_studio/__init__.py
9+ COPY --chown=1001:0 label_studio/frontend .
10+ COPY --chown=1001:0 label_studio/__init__.py /label-studio/label_studio/__init__.py
1111
12- RUN --mount=type=cache,target=$NPM_CACHE_LOCATION \
12+ RUN --mount=type=cache,target=$NPM_CACHE_LOCATION,uid=1001,gid=0 \
1313 npm ci \
1414 && npm run build:production
1515
1616FROM ubuntu:20.04
1717
1818ENV DEBIAN_FRONTEND=noninteractive \
1919 LS_DIR=/label-studio \
20- PIP_CACHE_DIR=/.cache \
20+ PIP_CACHE_DIR=$HOME /.cache \
2121 DJANGO_SETTINGS_MODULE=core.settings.label_studio \
2222 LABEL_STUDIO_BASE_DATA_DIR=/label-studio/data \
23+ OPT_DIR=/opt/heartex/instance-data/etc \
2324 SETUPTOOLS_USE_DISTUTILS=stdlib
2425
2526WORKDIR $LS_DIR
@@ -29,26 +30,46 @@ RUN set -eux \
2930 && apt-get update \
3031 && apt-get install --no-install-recommends --no-install-suggests -y \
3132 build-essential postgresql-client libmysqlclient-dev mysql-client python3.8 python3-pip python3.8-dev \
32- git libxml2-dev libxslt-dev zlib1g-dev
33+ git libxml2-dev libxslt-dev zlib1g-dev gnupg curl lsb-release && \
34+ apt-get purge --assume-yes --auto-remove --option APT::AutoRemove::RecommendsImportant=false \
35+ --option APT::AutoRemove::SuggestsImportant=false && rm -rf /var/lib/apt/lists/* /tmp/*
36+
37+ RUN --mount=type=cache,target=$PIP_CACHE_DIR,uid=1001,gid=0 \
38+ pip3 install --upgrade pip setuptools && pip3 install uwsgi uwsgitop
39+
40+ # incapsulate nginx install & configure to a single layer
41+ RUN set -eux; \
42+ curl -sSL https://nginx.org/keys/nginx_signing.key | apt-key add - && \
43+ echo "deb https://nginx.org/packages/mainline/ubuntu/ $(lsb_release -cs) nginx" >> /etc/apt/sources.list && \
44+ apt-get update && apt-get install nginx && \
45+ apt-get purge --assume-yes --auto-remove --option APT::AutoRemove::RecommendsImportant=false \
46+ --option APT::AutoRemove::SuggestsImportant=false && rm -rf /var/lib/apt/lists/* /tmp/* && \
47+ nginx -v
3348
3449# Copy and install middleware dependencies
35- COPY deploy/requirements-mw.txt .
36- RUN --mount=type=cache,target=$PIP_CACHE_DIR \
50+ COPY --chown=1001:0 deploy/requirements-mw.txt .
51+ RUN --mount=type=cache,target=$PIP_CACHE_DIR,uid=1001,gid=0 \
3752 pip3 install -r requirements-mw.txt
3853
3954# Copy and install requirements.txt first for caching
40- COPY deploy/requirements.txt .
41- RUN --mount=type=cache,target=$PIP_CACHE_DIR \
55+ COPY --chown=1001:0 deploy/requirements.txt .
56+ RUN --mount=type=cache,target=$PIP_CACHE_DIR,uid=1001,gid=0 \
4257 pip3 install -r requirements.txt
4358
44- COPY . .
45- RUN --mount=type=cache,target=$PIP_CACHE_DIR \
46- pip3 install -e .
59+ COPY --chown=1001:0 . .
60+ RUN --mount=type=cache,target=$PIP_CACHE_DIR,uid=1001,gid=0 \
61+ pip3 install -e . && \
62+ chown -R 1001:0 $LS_DIR && \
63+ chmod -R g=u $LS_DIR
4764
4865RUN rm -rf ./label_studio/frontend
49- COPY --from=frontend-builder /label-studio/label_studio/frontend/dist ./label_studio/frontend/dist
66+ COPY --chown=1001:0 --from=frontend-builder /label-studio/label_studio/frontend/dist ./label_studio/frontend/dist
67+
68+ RUN python3 label_studio/manage.py collectstatic --no-input && \
69+ chown -R 1001:0 $LS_DIR && \
70+ chmod -R g=u $LS_DIR
5071
51- RUN python3 label_studio/manage.py collectstatic --no-input
72+ ENV HOME=/label-studio
5273
5374EXPOSE 8080
5475
0 commit comments