forked from tl-its-umich-edu/my-learning-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
82 lines (65 loc) · 3.12 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
# build react components for production mode
FROM node:18-bookworm-slim AS node-webpack
WORKDIR /usr/src/app
# NOTE: package.json and webpack.config.js not likely to change between dev builds
COPY package.json webpack.config.js package-lock.json /usr/src/app/
RUN npm install
# NOTE: assets/ likely to change between dev builds
COPY assets /usr/src/app/assets
RUN npm run prod
# This is to find and remove symlinks that break some Docker builds.
# We need these later we'll just uncompress them
# Put them in node_modules as this directory isn't masked by docker-compose
# Also remove src and the symlinks afterward
RUN apt-get update && \
apt-get install -y --no-install-recommends tar && \
find node_modules -type l -print0 | tar -zcvf node_modules/all_symlinks.tgz --remove-files --null -T - && \
rm -rf /usr/src/app/assets/src
# build node libraries for production mode
FROM node:18-bookworm-slim AS node-prod-deps
WORKDIR /usr/src/app
COPY --from=node-webpack /usr/src/app /usr/src/app
RUN npm prune --production && \
# This is needed to clean up the examples files as these cause collectstatic to fail (and take up extra space)
find node_modules -type d -name "examples" -print0 | xargs -0 rm -rf
# FROM directive instructing base image to build upon
FROM python:3.10-slim-bookworm AS app
# EXPOSE port 5000 to allow communication to/from server
EXPOSE 5000
WORKDIR /code
# NOTE: requirements.txt not likely to change between dev builds
COPY requirements.txt .
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential curl apt-transport-https libpq-dev netcat-traditional default-libmysqlclient-dev pkg-config jq python3-dev xmlsec1 cron git && \
apt-get upgrade -y
# Install MariaDB from the mariadb repository rather than using Debians
# https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/
RUN curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash && \
apt install -y --no-install-recommends libmariadb-dev
RUN pip install --no-cache-dir -r requirements.txt
# copy built react and node libraries for production mode
COPY --from=node-prod-deps /usr/src/app/package-lock.json package-lock.json
COPY --from=node-prod-deps /usr/src/app/webpack-stats.json webpack-stats.json
COPY --from=node-prod-deps /usr/src/app/assets assets
COPY --from=node-prod-deps /usr/src/app/node_modules node_modules
# NOTE: project files likely to change between dev builds
COPY . .
# Generate git version information
RUN /code/scripts/git_version_info.sh
# Clean up anything we don't need anymore.
# Some of these can be purged completely, some of these just remove the package
RUN apt-get purge -y git curl libcurl4 libcurl3-gnutls && \
apt-get remove -y linux-libc-dev && \
# Keep these packages
apt-mark manual libmariadb3 mariadb-common && \
apt autoremove -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*
RUN python manage.py collectstatic --verbosity 0 --noinput
# Sets the local timezone of the docker image
ARG TZ
ENV TZ ${TZ:-America/Detroit}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
CMD ["/code/start.sh"]
# done!