Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KNIGHT
Asyst Moodle Plugin
Commits
33c6c7c7
Commit
33c6c7c7
authored
Dec 16, 2024
by
Artem Baranovskyi
Browse files
Image build is optimized.
parent
3e0bde72
Changes
1
Show whitespace changes
Inline
Side-by-side
flask_ml_api/Dockerfile.test
0 → 100644
View file @
33c6c7c7
# Build stage
FROM
python
:
3.10
-
slim
AS
builder
# Install system dependencies
RUN
apt
-
get
update
&&
apt
-
get
install
-
y
--
no
-
install
-
recommends
\
build
-
essential
\
python3
-
venv
\
&&
rm
-
rf
/
var
/
lib
/
apt
/
lists
/*
# Create and activate virtual environment
RUN
python3
-
m
venv
/
opt
/
myenv
ENV
PATH
=
"/opt/myenv/bin:
$PATH
"
WORKDIR
/
app
COPY
.
/
app
COPY
.
/
asyst
/
app
/
asyst
# Install dependencies in separate steps to reduce memory usage
RUN
/
opt
/
myenv
/
bin
/
pip
install
--
no
-
cache
-
dir
Flask
RUN
/
opt
/
myenv
/
bin
/
pip
install
--
no
-
cache
-
dir
matplotlib
RUN
/
opt
/
myenv
/
bin
/
pip
install
--
no
-
cache
-
dir
scikit
-
learn
RUN
/
opt
/
myenv
/
bin
/
pip
install
--
no
-
cache
-
dir
transformers
RUN
/
opt
/
myenv
/
bin
/
pip
install
--
no
-
cache
-
dir
pandas
RUN
/
opt
/
myenv
/
bin
/
pip
install
--
no
-
cache
-
dir
sentence_transformers
RUN
/
opt
/
myenv
/
bin
/
python3
-
m
pip
install
--
upgrade
setuptools
wheel
# Install CPU-only version of torch
RUN
/
opt
/
myenv
/
bin
/
pip
install
torch
==
1.10.2
+
cpu
-
f
https
://
download
.
pytorch
.
org
/
whl
/
torch_stable
.
html
# Final image
FROM
python
:
3.10
-
slim
# Install system dependencies
RUN
apt
-
get
update
&&
apt
-
get
install
-
y
--
no
-
install
-
recommends
\
&&
rm
-
rf
/
var
/
lib
/
apt
/
lists
/*
# Copy virtual environment and application from build stage
COPY
--
from
=
builder
/
opt
/
myenv
/
opt
/
myenv
COPY
--
from
=
builder
/
app
/
app
# Activate virtual environment in the final image
ENV
PATH
=
"/opt/myenv/bin:
$PATH
"
# Set permissions
RUN
chown
-
R
www
-
data
:
www
-
data
/
app
/
asyst
\
&&
chmod
-
R
755
/
app
/
asyst
# Expose port for Flask API
EXPOSE
5000
# Run the application
CMD
[
"/opt/myenv/bin/python"
,
"/app/api.py"
]
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment