Skip to content

Commit 2c96e36

Browse files
committed
A few optimizations
- Reduce Docker image size - Migrate requirements.txt to Pipfile - Remove unused dependencies - Add a few unnecessary files in .dockerignore
1 parent e5c9149 commit 2c96e36

File tree

5 files changed

+629
-579
lines changed

5 files changed

+629
-579
lines changed

.dockerignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ test.py
142142
.gitignore
143143
.github/
144144
app.json
145-
CHANGELOG.md
146145
Procfile
147146
pyproject.toml
148-
README.md
149-
Pipfile
150-
Pipfile.lock
147+
*.md
148+
.*.json

Dockerfile

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
FROM python:3.10 as py
1+
FROM python:3.10-alpine as base
22

3-
FROM py as build
3+
RUN apk add wget git cairo-dev cairo cairo-tools \
4+
# pillow dependencies
5+
jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev
46

5-
RUN apt update && apt install -y g++ git
6-
COPY requirements.txt /
7-
RUN pip install --prefix=/inst -U -r /requirements.txt
7+
FROM base AS python-deps
88

9-
FROM py
9+
# Install pipenv and compilation dependencies
10+
RUN apk update && apk add --virtual build-dependencies build-base gcc libffi-dev
11+
RUN pip install pipenv
1012

13+
# Install python dependencies in /.venv
14+
COPY Pipfile Pipfile.lock .
15+
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
16+
17+
FROM base AS runtime
18+
19+
# Copy virtual env from python-deps stage
20+
COPY --from=python-deps /.venv /.venv
21+
ENV PATH="/.venv/bin:$PATH"
22+
23+
# Create and switch to a new user
24+
RUN adduser -D modmail
25+
WORKDIR /home/modmail
26+
USER modmail
27+
28+
# Install application into container
1129
ENV USING_DOCKER yes
12-
COPY --from=build /inst /usr/local
30+
COPY . .
1331

14-
WORKDIR /modmailbot
15-
CMD ["python", "bot.py"]
16-
COPY . /modmailbot
32+
# Run the application
33+
CMD ["python", "-m", "bot"]

Pipfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ typing-extensions = "==4.2.0"
1212
[packages]
1313
aiohttp = "==3.8.1"
1414
colorama = "~=0.4.5"
15-
"discord.py" = "==2.0.1"
1615
emoji = "==1.7.0"
1716
isodate = "~=0.6.0"
1817
motor = "==2.5.1"
@@ -24,6 +23,12 @@ python-dotenv = "==0.20.0"
2423
uvloop = {version = ">=0.15.2", markers = "sys_platform != 'win32'"}
2524
lottie = {version = "==0.6.11", extras = ["pdf"]}
2625
requests = "==2.28.1"
26+
attrs = "==21.4.0"
27+
cairocffi = "==1.3.0"
28+
cairosvg = "==2.7.0"
29+
cffi = "==1.15.0"
30+
pillow = "==9.5.0"
31+
"discord.py" = "==2.0.1"
2732

2833
[scripts]
2934
bot = "python bot.py"

0 commit comments

Comments
 (0)