Skip to content

Commit aabc364

Browse files
committed
refactor dockerfile to install dependencies with pdm and dockerfile to allowlist
Moves adduser statements to beginning of base image
1 parent 00f1d51 commit aabc364

File tree

4 files changed

+30
-166
lines changed

4 files changed

+30
-166
lines changed

.dockerignore

Lines changed: 13 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,14 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
1+
# Ignore everything
2+
*
3+
# Ignore the IDE, these are not duplicate and not having this makes the build context potentially *very* large
4+
**
5+
!/cogs
6+
!/core
7+
!/plugins
8+
!/src
9+
!*.py
10+
!LICENSE
11+
!pdm.lock
12+
!pyproject.toml
13+
!README.md
514

6-
# C extensions
7-
*.so
8-
9-
# Distribution / packaging
10-
.Python
11-
build/
12-
develop-eggs/
13-
dist/
14-
downloads/
15-
eggs/
16-
.eggs/
17-
lib/
18-
lib64/
19-
parts/
20-
sdist/
21-
var/
22-
wheels/
23-
pip-wheel-metadata/
24-
share/python-wheels/
25-
*.egg-info/
26-
.installed.cfg
27-
*.egg
28-
MANIFEST
29-
30-
# PyInstaller
31-
# Usually these files are written by a python script from a template
32-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33-
*.manifest
34-
*.spec
35-
36-
# Installer logs
37-
pip-log.txt
38-
pip-delete-this-directory.txt
39-
40-
# Unit test / coverage reports
41-
htmlcov/
42-
.tox/
43-
.nox/
44-
.coverage
45-
.coverage.*
46-
.cache
47-
nosetests.xml
48-
coverage.xml
49-
*.cover
50-
.hypothesis/
51-
.pytest_cache/
52-
.ruff_cache/
53-
54-
# Translations
55-
*.mo
56-
*.pot
57-
58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
63-
# Flask stuff:
64-
instance/
65-
.webassets-cache
66-
67-
# Scrapy stuff:
68-
.scrapy
69-
70-
# Sphinx documentation
71-
docs/_build/
72-
73-
# PyBuilder
74-
target/
75-
76-
# Jupyter Notebook
77-
.ipynb_checkpoints
78-
79-
# IPython
80-
profile_default/
81-
ipython_config.py
82-
83-
# pyenv
84-
.python-version
85-
86-
# celery beat schedule file
87-
celerybeat-schedule
88-
89-
# SageMath parsed files
90-
*.sage.py
91-
92-
# Environments
93-
.env
94-
.venv
95-
env/
96-
venv/
97-
venv2/
98-
ENV/
99-
env.bak/
100-
venv.bak/
101-
102-
# Spyder project settings
103-
.spyderproject
104-
.spyproject
105-
106-
# Rope project settings
107-
.ropeproject
108-
109-
# mkdocs documentation
110-
/site
111-
112-
# mypy
113-
.mypy_cache/
114-
.dmypy.json
115-
dmypy.json
116-
117-
# Pyre type checker
118-
.pyre/
119-
120-
# PyCharm
121-
.idea/
122-
123-
# MacOS
124-
.DS_Store
125-
126-
# VS Code
127-
.vscode/
128-
129-
# Node
130-
package-lock.json
131-
node_modules/
132-
133-
# Modmail
134-
config.json
135-
plugins/
136-
!plugins/registry.json
137-
!plugins/@local/
138-
temp/
139-
test.py
140-
141-
# Other stuff
142-
.env.example
143-
.gitignore
144-
.dockerignore
145-
.github/
146-
app.json
147-
Procfile
148-
pyproject.toml
149-
*.md
150-
.*.json
151-
Dockerfile
152-
docker-compose.yml
153-
LICENSE
154-
PRIVACY.md
155-
156-
# Docs
157-
docs/
158-
159-
.pdm-python

Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@ RUN apk update && apk add git \
77
FROM base as python-deps
88

99
RUN apk add --virtual build-deps build-base gcc libffi-dev
10-
COPY requirements.txt /
11-
RUN pip install --prefix=/inst -U -r /requirements.txt
10+
11+
#Install pdm
12+
RUN pip install -U pip setuptools wheel
13+
RUN pip install pdm
14+
15+
COPY pyproject.toml pdm.lock README.md /modmail/
16+
17+
WORKDIR /modmail
18+
RUN pdm sync --prod --no-editable --fail-fast
1219

1320
FROM base as runtime
1421

22+
RUN adduser --disabled-password modmail
23+
USER modmail
24+
25+
1526
ENV USING_DOCKER yes
16-
COPY --from=python-deps /inst /usr/local
27+
COPY --chown=modmail:modmail --from=python-deps /modmail /modmail
1728

18-
COPY . /modmail
29+
COPY --chown=modmail:modmail . /modmail
1930
WORKDIR /modmail
2031

32+
ENV PATH="/modmail/.venv/bin:${PATH}"
2133
CMD ["python", "bot.py"]
2234

23-
RUN adduser --disabled-password --gecos '' app && \
24-
chown -R app /modmail
25-
USER app

dev.docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ services:
1111
- mongo
1212
mongo:
1313
image: mongo:7
14-
restart: always
1514
volumes:
1615
- mongodb:/data/db
1716
ports:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ dependencies = [
7575
"cffi~=1.15.0",
7676
"strenum",
7777
"discord-py~=2.3.0",
78+
"setuptools>=69.0.3",
7879
]
7980
requires-python = ">=3.10"
8081
readme = "README.md"

0 commit comments

Comments
 (0)