-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
67 lines (57 loc) · 2.7 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# syntax=docker/dockerfile:1.4
FROM python:3.11-slim AS builder
ARG TARGETARCH
ARG VERSION
ENV DEBIAN_FRONTEND=noninteractive
RUN printf 'Dir::Cache::pkgcache "";\nDir::Cache::srcpkgcache "";' > /etc/apt/apt.conf.d/00_disable-cache-files
RUN apt-get update -qq
RUN apt-get install -y --no-install-recommends \
git \
gcc clang ccache \
patchelf libnss3-dev
RUN if ! [ "$(uname -m)" = 'x86_64' ]; then apt-get install -y --no-install-recommends zlib1g-dev make; fi
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-${TARGETARCH} \
env MAKEFLAGS="-j$(nproc)" pip install --root-user-action=ignore -U scons wheel pip build
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-${TARGETARCH} \
--mount=type=cache,target=/root/.cache/ccache,id=ccache-${TARGETARCH} \
env MAKEFLAGS="-j$(nproc)" CC='ccache gcc' \
pip install --root-user-action=ignore -U pyinstaller staticx
RUN git clone --depth 1 -b ${VERSION} https://github.com/psf/black.git
WORKDIR black
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-${TARGETARCH} \
--mount=type=cache,target=/root/.cache/ccache,id=ccache-${TARGETARCH} \
--mount=type=cache,target=/black/.mypy_cache,id=mypy-${TARGETARCH} \
env \
MAKEFLAGS="-j$(nproc)" \
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
HATCH_BUILD_HOOKS_ENABLE=1 \
MYPYC_OPT_LEVEL=3 MYPYC_DEBUG_LEVEL=0 CC='ccache clang' \
python -m build --wheel
RUN --mount=type=cache,target=/root/.cache/pip,id=pip-${TARGETARCH} \
--mount=type=cache,target=/root/.cache/ccache,id=ccache-${TARGETARCH} \
env MAKEFLAGS="-j$(nproc)" CC='ccache gcc' \
pip install --compile "$(ls dist/*.whl)"[d,uvloop]
WORKDIR /root
RUN --mount=type=cache,target=/root/.cache/pyinstaller,id=pyinstaller-${TARGETARCH} \
--mount=type=cache,target=/root/build,id=mypy-build-${TARGETARCH} \
env MAKEFLAGS="-j$(nproc)" \
pyinstaller \
--clean \
--onefile \
--strip \
--name blackd \
$(python -c "import sys,blackd;print(' '.join(map(lambda s: f'--hiddenimport {s}', filter(lambda s: s.endswith('__mypyc'), sys.modules.keys()))))") \
--hiddenimport platformdirs \
--collect-submodules blackd \
--collect-submodules black \
--collect-submodules blib2to3 \
--add-data '/black/src/blib2to3:blib2to3' \
$(which blackd)
RUN env MAKEFLAGS="-j$(nproc)" staticx --strip dist/blackd dist/blackd_static
FROM gcr.io/distroless/static:nonroot
USER 65532:65532
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/blackd"]
CMD ["--bind-host", "0.0.0.0", "--bind-port", "80"]
MAINTAINER 'Byeonghoon Isac Yoo <bhyoo@bhyoo.com>'
COPY --link --from=builder --chown=65532:65532 /root/dist/blackd_static /usr/local/bin/blackd