Andrew Smith commited on
Commit
90c17df
·
1 Parent(s): 75ef96c

Change build process

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -18
Dockerfile CHANGED
@@ -1,27 +1,33 @@
1
- FROM python:3.9
 
2
 
3
- # Get secret DB_URL and output it to /test at buildtime
4
- RUN --mount=type=secret,id=DB_URL,mode=0444,required=true \
5
- cat /run/secrets/DB_URL > /test
 
 
 
6
 
7
- # Set up a new user named "user" with user ID 1000
8
- RUN useradd -m -u 1000 user
9
 
10
- # Switch to the "user" user
11
- USER user
12
 
13
- # Set home to the user's home directory
14
- ENV HOME=/home/user \
15
- PATH=/home/user/.local/bin:$PATH
16
 
17
- # Set the working directory to the user's home directory
18
- WORKDIR $HOME/app
 
 
 
 
19
 
20
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
21
- COPY --chown=user . $HOME/app
22
 
23
- RUN pip install --no-cache-dir poetry
24
 
25
- RUN poetry install --only main
 
 
26
 
27
- CMD ["poetry", "run", "start"]
 
1
+ # The builder image, used to build the virtual environment
2
+ FROM python:3.11-buster as builder
3
 
4
+ RUN pip install poetry==1.4.2
5
+
6
+ ENV POETRY_NO_INTERACTION=1 \
7
+ POETRY_VIRTUALENVS_IN_PROJECT=1 \
8
+ POETRY_VIRTUALENVS_CREATE=1 \
9
+ POETRY_CACHE_DIR=/tmp/poetry_cache
10
 
11
+ WORKDIR /app
 
12
 
13
+ COPY pyproject.toml poetry.lock ./
 
14
 
15
+ RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root
 
 
16
 
17
+ # The runtime image, used to just run the code provided its virtual environment
18
+ FROM python:3.11-slim-buster as runtime
19
+
20
+ # Get secret DB_URL and output it to /test at buildtime
21
+ RUN --mount=type=secret,id=DB_URL,mode=0444,required=true \
22
+ cat /run/secrets/DB_URL > /test
23
 
24
+ ENV VIRTUAL_ENV=/app/.venv \
25
+ PATH="/app/.venv/bin:$PATH"
26
 
27
+ COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
28
 
29
+ COPY image_search ./image_search
30
+ COPY static ./static
31
+ COPY images ./images
32
 
33
+ CMD ["uvicorn", "image_search.main:app", "--host", "0.0.0.0", "--port", "7860"]