-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDockerfile
73 lines (56 loc) · 2.1 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
# Backend for OpenCloning
# https://github.com/manulera/OpenCloning_backend
# BUILDER IMAGE
FROM python:3.11-slim-bookworm as builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y gcc git g++ wget
# Download MARS executable
RUN wget https://github.com/manulera/MARS/releases/download/v0.2/mars-Debian-Bookworm && \
chmod +x mars-Debian-Bookworm && \
mv mars-Debian-Bookworm /usr/local/bin/mars
RUN useradd -ms /bin/bash backend
USER backend
WORKDIR /home/backend
ENV PIP_DISABLE_PIP_VERSION_CHECK=on
# Poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
# make poetry install to this location
ENV POETRY_HOME="/home/backend/.bin"
# do not ask any interactive question
ENV POETRY_NO_INTERACTION=1
# never create virtual environment automatically, only use env prepared by us
ENV POETRY_VIRTUALENVS_CREATE=false
# this is where our dependencies and virtual environment will live
ENV VIRTUAL_ENV="/home/backend/venv"
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$POETRY_HOME/bin:$VIRTUAL_ENV/bin:$PATH"
RUN pip install --no-cache-dir poetry
COPY ./src ./src
COPY ./poetry.lock .
COPY ./pyproject.toml .
COPY ./README.md .
RUN poetry build
RUN pip install dist/opencloning-*.whl
# FINAL IMAGE
FROM python:3.11-slim-bookworm
# directly output things to stdout/stderr, without buffering
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y mafft libgomp1
# create a user to run the app
RUN useradd -ms /bin/bash backend
USER backend
WORKDIR /home/backend
# Accept the COMMIT_SHA as a build argument
ARG COMMIT_SHA
ARG VERSION
# Store the COMMIT_SHA and VERSION in files
RUN echo "${COMMIT_SHA}" > commit_sha.txt
RUN echo "${VERSION}" > version.txt
ENV VIRTUAL_ENV="/home/backend/venv"
COPY --from=builder $VIRTUAL_ENV $VIRTUAL_ENV
COPY --from=builder /usr/local/bin/mars /usr/local/bin/mars
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# For example, ROOT_PATH="/syc"
ENV ROOT_PATH=""
# Only add --root-path if ROOT_PATH is not empty, otherwise uvicorn will throw an error
CMD uvicorn opencloning.main:app --host 0.0.0.0 --port 8000 ${ROOT_PATH:+--root-path ${ROOT_PATH}}