-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
100 lines (72 loc) · 2.28 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Adapted from https://github.com/Chainlit/cookbook/blob/main/aws-ecs-deployment/README.md
ARG PYTHON_VERSION=3.12
ARG BUILD_ENV_IS_CI=1
###############
# Base image #
###############
FROM python:${PYTHON_VERSION}-slim AS base
COPY --from=ghcr.io/astral-sh/uv:0.5.28 /uv /uvx /bin/
ARG BUILD_ENV_IS_CI
# Set environment variables
ENV PYTHONUNBUFFERED=1
# Install git and ssh
RUN apt-get update && \
apt-get install -y --no-install-recommends git openssh-client
# Add GitLab's SSH key opnly if running locally.
# CI will use HTTPS to fetch from GitLab.
RUN \
if [ "${BUILD_ENV_IS_CI:-0}" != "1" ]; then \
mkdir -p -m 0700 ~/.ssh && ssh-keyscan repo.element84.com > ~/.ssh/known_hosts; \
fi
# Update git config to fetch llm-agent private repo over HTTPS using basic auth.
# the HTTPS basic auth password will be the CI_JOB_TOKEN provided in secrets.
# Run ONLY if build is not local (i.e. is CI)
RUN --mount=type=secret,id=CI_JOB_TOKEN \
if [ "${BUILD_ENV_IS_CI:-0}" -eq 1 ]; then \
git config --global \
url."https://gitlab-ci-token:$(cat /run/secrets/CI_JOB_TOKEN)@repo.element84.com/noaa_km_nlp/llm-agent.git".insteadOf ssh://[email protected]/noaa_km_nlp/llm-agent.git; \
fi
# Set working directory
WORKDIR /app
# Create venv and use it
RUN uv venv
ENV PATH="/app/.venv/bin:$PATH"
# Add requirements file so we can install our dependencies
COPY requirements.txt .
# Setup venv and call `natural-language-geocoding init`.
# Do not mount SSH if CI, do if local
RUN \
if [ "${BUILD_ENV_IS_CI:-0}" -eq 1 ]; then \
uv pip sync requirements.txt; \
natural-language-geocoding init; \
fi
RUN --mount=type=ssh \
if [ "${BUILD_ENV_IS_CI:-0}" != "1" ]; then \
uv pip sync requirements.txt; \
natural-language-geocoding init; \
fi
###############
# Build image #
###############
FROM base AS build
COPY . /app
WORKDIR /app
# Build app
RUN python -m build
##################
# Chainlit image #
##################
FROM build AS chainlit
COPY . /app/
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
# Expose the port the app runs on
EXPOSE 8000
# Command to run the app
CMD ["chainlit", "run", "src/app.py", "--host", "0.0.0.0", "--port", "8000"]
##############
# Dask image #
##############
FROM base AS dask
WORKDIR /app
CMD ["bash"]