forked from F33RNI/GPT-Telegramus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
80 lines (64 loc) · 2.35 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
68
69
70
71
72
73
74
75
76
77
78
79
80
# syntax=docker/dockerfile:labs
# Dockerfile for GPT-Telegramus using multi-stage build
# Use buildkit syntax labs
# https://github.com/moby/buildkit
# First stage: install dependencies
FROM python:3.9 AS build
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app
# Install Python and pip
RUN <<eot
apt update
apt install -y --no-install-recommends python3 gcc libc-dev linux-headers wget
python3 -m ensurepip
wget "https://static.rust-lang.org/rustup/dist/$(uname -m)-unknown-linux-gnu/rustup-init" -O /tmp/rustup-init
chmod +x /tmp/rustup-init
/tmp/rustup-init -y
eot
ENV PATH=/root/.cargo/bin:$PATH
# Add just requirements.txt file (for caching purposes)
ADD requirements.txt requirements.txt
# Install requirements
RUN --mount=type=cache,target=/root/.cache/pip pip3 install -r requirements.txt --upgrade
# Build and save wheels
RUN --mount=type=cache,target=/root/.cache/pip pip3 wheel --wheel-dir=/wheels -r requirements.txt
FROM build as compile
ENV DEBIAN_FRONTEND=noninteractive
RUN mkdir -p /lib64
RUN mkdir -p /lib
WORKDIR /app
# Add just requirements.txt file (for caching purposes)
ADD requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip pip3 install --no-index -r requirements.txt
ADD . .
RUN --mount=type=cache,target=/root/.cache/pip <<EOT
apt install upx
pip3 install pyinstaller
EOT
RUN pyinstaller --clean --onefile --name main --collect-all tiktoken_ext.openai_public \
--collect-all blobfile --collect-all tls_client \
main.py
# Optional target: build classic python-based container
FROM python:3.9 as classic
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app
ADD . .
COPY --link --from=build /app /app
COPY --link --from=build /wheels /wheels
# install deps
RUN apt update && apt install -y --no-install-recommends gcc build-base libc-dev linux-headers rustc cargo
# Install wheels
RUN --mount=type=cache,target=/root/.cache/pip pip3 install --upgrade --no-index --find-links=/wheels -r requirements.txt
ENV TELEGRAMUS_CONFIG_FILE "config.json"
# Run main script
CMD ["python3", "main.py"]
# Build distoless (main) variant
FROM gcr.io/distroless/static
WORKDIR /app
COPY --link --from=compile /app/dist/main /app/telegramus
COPY --link --from=compile /lib/ /lib/
COPY --link --from=compile /lib64/ /lib64/
ADD config.json messages.json /app/
ENV TELEGRAMUS_CONFIG_FILE "config.json"
# Run main script
CMD ["/app/telegramus"]