-
Notifications
You must be signed in to change notification settings - Fork 4
/
Dockerfile
78 lines (63 loc) · 2.98 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
# Dockerfile to build and serve scigateway
# Build stage
FROM node:20.17.0-alpine3.20@sha256:2d07db07a2df6830718ae2a47db6fedce6745f5bcd174c398f2acdda90a11c03 as builder
WORKDIR /scigateway-build
# Enable dependency caching and share the cache between projects
ENV YARN_ENABLE_GLOBAL_CACHE=true
ENV YARN_GLOBAL_FOLDER=/root/.cache/.yarn
COPY package.json tsconfig.json yarn.lock .yarnrc.yml ./
COPY .yarn .yarn
COPY public public
RUN --mount=type=cache,target=/root/.cache/.yarn/cache \
set -eux; \
\
yarn workspaces focus --production;
COPY . .
COPY docker/settings.json public/settings.json
RUN yarn build
# Run stage
FROM httpd:2.4.62-alpine3.20@sha256:66c49302c02430619abb84240a438bcfc083015661009fcaaeaac931450f62cd
WORKDIR /usr/local/apache2/htdocs
# Put the output of the build into an apache server
COPY --from=builder /scigateway-build/build/. .
RUN set -eux; \
\
# Enable mod_rewrite \
sed -i -e 's/^#LoadModule rewrite_module/LoadModule rewrite_module/' /usr/local/apache2/conf/httpd.conf; \
# Enable mod_deflate \
sed -i -e 's/^#LoadModule deflate_module/LoadModule deflate_module/' /usr/local/apache2/conf/httpd.conf; \
echo '<Location / >' >> /usr/local/apache2/conf/httpd.conf; \
echo ' RewriteEngine on' >> /usr/local/apache2/conf/httpd.conf; \
# Don't rewrite files or directories \
echo ' RewriteCond %{REQUEST_FILENAME} -f [OR]' >> /usr/local/apache2/conf/httpd.conf; \
echo ' RewriteCond %{REQUEST_FILENAME} -d' >> /usr/local/apache2/conf/httpd.conf; \
echo ' RewriteRule ^ - [L]' >> /usr/local/apache2/conf/httpd.conf; \
# Rewrite everything else to index.html to allow html5 state links \
echo ' RewriteRule ^ index.html [QSA,L]' >> /usr/local/apache2/conf/httpd.conf; \
echo '</Location>' >> /usr/local/apache2/conf/httpd.conf; \
# Compress all files except images \
echo 'SetOutputFilter DEFLATE' >> /usr/local/apache2/conf/httpd.conf; \
echo 'SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip' >> /usr/local/apache2/conf/httpd.conf; \
# Disable caching for .json and .html files \
echo '<FilesMatch ".(json|html)$">' >> /usr/local/apache2/conf/httpd.conf; \
echo ' Header set Cache-Control "no-cache"' >> /usr/local/apache2/conf/httpd.conf; \
echo '</FilesMatch>' >> /usr/local/apache2/conf/httpd.conf; \
\
# Privileged ports are permitted to root only by default. \
# setcap to bind to privileged ports (80) as non-root. \
apk --no-cache add libcap; \
setcap 'cap_net_bind_service=+ep' /usr/local/apache2/bin/httpd; \
\
# Change ownership of logs directory \
chown www-data:www-data /usr/local/apache2/logs; \
\
# Change ownership of settings file \
chown www-data:www-data /usr/local/apache2/htdocs/settings.json;
# Switch to non-root user defined in httpd image
USER www-data
ENV AUTH_PROVIDER="icat"
ENV AUTH_URL="/api"
COPY docker/docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["httpd-foreground"]
EXPOSE 80