forked from kreneskyp/ix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
executable file
·122 lines (93 loc) · 3.71 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# =============================================================================
# Base stage - shared setup
FROM python:3.11 as base
ARG LANGCHAIN_DEV
# System setup
ENV HOME=/root
ENV APP=/var/app
ENV PATH=$PATH:/usr/bin/ix
RUN mkdir -p /usr/bin/ix
COPY bin/* /usr/bin/ix/
# create useful directories
RUN mkdir -p $APP
RUN mkdir -p /var/wheels
RUN mkdir -p /var/vault/certs
# create directies needed for dev mode - these aren't used in production
# but raise warnings if they aren't there. (harmless but yellow and scary)
RUN mkdir -p $APP/.compiled-static
RUN mkdir -p $APP/frontend/static
RUN apt update -y && \
apt install -y curl postgresql-client && \
rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR $APP
# Copy base files to working dir
COPY manage.py .
COPY requirements.txt .
COPY LICENSE .
# =============================================================================
# PYTHON_LIB stage - Downloads and builds wheels for python libraries.
# This is done separately so that download cache isn't
# included in the final image.
FROM base as wheelhouse
RUN pip wheel -r $APP/requirements.txt -w /var/wheels
# =============================================================================
# FRONTEND stage - Container for building the frontend with webpack and other
# nodejs tools.
FROM base as nodejs
# NVM / NPM Setup
ENV NVM_DIR=/usr/local/nvm
ENV NPM_DIR=$APP
ENV NODE_VERSION=18.15.0
ENV NODE_MODULES=$NPM_DIR/node_modules
RUN mkdir -p $NVM_DIR
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash && \
. $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
ENV NODE_MODULES_BIN=$NPM_DIR/node_modules/.bin
ENV PATH $PATH:$NODE_MODULES_BIN
# build config
COPY package.json $NPM_DIR
COPY package-lock.json $NPM_DIR
COPY babel.config.js $NPM_DIR
COPY relay.config.js $NPM_DIR
COPY webpack.config.js $NPM_DIR
# NPM package installs
RUN echo "[$NPM_DIR]"
RUN npm install
# =============================================================================
# APP stage produces the image:
# - python packages
# - compiled static
# - nginx
FROM base as app
COPY --from=wheelhouse /var/wheels /var/wheels
RUN pip install --no-index --find-links=/var/wheels -r $APP/requirements.txt
COPY client_config /var/client_config
# XXX: hacky way of generating a unique key on build, needs to be removed prior to deploy readiness
# Generate a Django secret key
# Set the Django secret key
ENV DJANGO_SECRET_KEY $(date +%s | sha256sum | base64 | head -c 32)
RUN echo "export DJANGO_SECRET_KEY=${DJANGO_SECRET_KEY}" >> /etc/profile
# FRONTEND
ENV COMPILED_STATIC=/var/static
RUN mkdir -p ${COMPILED_STATIC}
# nginx setup
RUN mkdir -p /etc/nginx
COPY nginx.conf /etc/nginx/nginx.conf
# Copy the rest of the application code to the working directory
COPY ix ${APP}/ix
# If LANGCHAIN_DEV is set then install the local dev version of LangChain
RUN if [ -n "${LANGCHAIN_DEV}" ]; then pip install -e /var/app/langchain/libs/langchain; fi
# Set the environment variable for selecting between ASGI and Celery
ENV APP_MODE=asgi
WORKDIR ${APP}
# Add compiled static if available.
COPY .compiled-static/ ${COMPILED_STATIC}/
# Start the application using either ASGI or Celery depending on APP_MODE
# XXX: disabling until this is tested more
#CMD if [ "$APP_MODE" = "asgi" ] export ; then python manage.py runserver 0.0.0.0:8000 ; else celery -A myapp worker -l info ; fi