-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDockerfile
More file actions
135 lines (114 loc) · 5.04 KB
/
Dockerfile
File metadata and controls
135 lines (114 loc) · 5.04 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
# syntax=docker/dockerfile:1.6
#
# IGSR front-end Dockerfile
# --------------------------------
# This builds the IGSR website and then serves it with nginx:
# - Jekyll site (Ruby 2.2 / Debian Jessie) -> /usr/share/nginx/html
# - Angular 4 portal built with Webpack 3 -> /usr/share/nginx/html/data-portal
# - nginx (stable-alpine) as the final runtime image
#
# Main tool versions (kept stable so the build stays repeatable):
# Ruby 2.2 | Bundler 1.16.0 | Jekyll (from Gemfile)
# Node 16 | Webpack 3.12.0 | TypeScript 2.4.2 | RxJS 5.4.3 | Zone.js 0.8.29
# nginx:stable-alpine
##
## Stage 1 — Build the Jekyll site (Ruby 2.2 / Debian Jessie)
##
FROM ruby:2.2 AS jekyll
# Build the site with production settings
ENV JEKYLL_ENV=production
# Jessie is end-of-life, so use the Debian archive to fetch packages
RUN set -eux; \
sed -i 's/deb.debian.org/archive.debian.org/g; s|security.debian.org|archive.debian.org|g' /etc/apt/sources.list; \
sed -i '/jessie-updates/d' /etc/apt/sources.list; \
printf 'Acquire::Check-Valid-Until "false";\nAcquire::AllowInsecureRepositories "true";\n' > /etc/apt/apt.conf.d/99archive; \
apt-get -o Acquire::Check-Valid-Until=false -o Acquire::AllowInsecureRepositories=true update; \
apt-get -y --allow-unauthenticated --no-install-recommends install \
build-essential git ca-certificates libxml2-dev libxslt1-dev zlib1g-dev nodejs; \
ln -sf /usr/bin/nodejs /usr/bin/node || true; \
rm -rf /var/lib/apt/lists/*
WORKDIR /site
COPY Gemfile Gemfile.lock ./
RUN gem install bundler -v 1.16.0 \
&& bundle _1.16.0_ config set without 'development test' \
&& bundle _1.16.0_ install
COPY . .
RUN bundle exec jekyll build --destination /out/_site
##
## Stage 2 — Angular 4 portal bundle (Webpack 3)
##
FROM node:16-buster AS portal
WORKDIR /portal
# Copy the Angular app code into the image
COPY _data-portal/ /portal/
# Copy helper scripts used during the build
COPY docker/scripts/ /portal/docker/scripts/
# Install npm dependencies, allowing the older peer dependency rules this app needs
RUN npm install --unsafe-perm --legacy-peer-deps
# Install the build tools and runtime libraries at the older versions this app expects
RUN npm i --no-save \
webpack@3.12.0 \
typescript@2.4.2 \
ts-loader@2.3.7 \
angular2-template-loader@0.6.2 \
raw-loader@0.5.1 \
rxjs@5.4.3 \
zone.js@0.8.29 \
reflect-metadata@0.1.10 \
core-js@2.4.1
# Ensure production mode is enabled and use the runtime bootstrap
RUN bash docker/scripts/fix-main-ts.sh
# Build the portal bundle using the webpack config stored in the repo
RUN set -eux; \
node node_modules/webpack/bin/webpack.js -p --config webpack.config.js; \
test -s static/build.js
# Copy browser support scripts locally so we do not rely on external URLs
RUN set -eux; \
mkdir -p /portal/vendor; \
if [ -f node_modules/core-js/client/shim.min.js ]; then \
cp node_modules/core-js/client/shim.min.js /portal/vendor/core-js.min.js; \
elif [ -f node_modules/core-js-bundle/minified.js ]; then \
cp node_modules/core-js-bundle/minified.js /portal/vendor/core-js.min.js; \
fi; \
if [ -f node_modules/reflect-metadata/Reflect.min.js ]; then \
cp node_modules/reflect-metadata/Reflect.min.js /portal/vendor/reflect-metadata.js; \
else \
cp node_modules/reflect-metadata/Reflect.js /portal/vendor/reflect-metadata.js; \
fi; \
cp node_modules/zone.js/dist/zone.js /portal/vendor/zone.js
##
## Stage 3 — Final runtime image (nginx)
##
FROM nginx:stable-alpine AS runtime
# These values are filled into the nginx config when the container starts
# API_BASE is the upstream API URL; PORT controls the nginx listen port
ENV API_BASE=http://host.docker.internal:8000
ENV PORT=80
# Copy the nginx config template; it is filled in at container start
COPY docker/nginx.conf.template /etc/nginx/templates/default.conf.template
COPY docker/scripts/inject-polyfill-snippet.sh /usr/local/bin/inject-polyfill-snippet.sh
# Bring in the built site files from earlier stages
COPY --from=jekyll /out/_site/ /usr/share/nginx/html/
RUN mkdir -p /usr/share/nginx/html/data-portal/static /usr/share/nginx/html/data-portal/vendor
COPY --from=portal /portal/static/build.js /usr/share/nginx/html/data-portal/static/build.js
COPY --from=portal /portal/vendor/ /usr/share/nginx/html/data-portal/vendor/
RUN rm -f /etc/nginx/conf.d/manual_redirects.server.conf
RUN mkdir -p /etc/nginx/snippets
COPY docker/manual_redirects.server.conf /etc/nginx/snippets/manual_redirects.inc
# Add local browser support scripts to data-portal index.html
RUN <<'SH'
set -eux
f=/usr/share/nginx/html/data-portal/index.html
[ -f "$f" ] || exit 0
# Remove any external script tags for these files
sed -i \
-e '/ajax\/libs\/core-js\/[^"]*\/shim\.min\.js/d' \
-e '/ajax\/libs\/zone\.js\/[^"]*\/zone\(\.min\)\?\.js/d' \
-e '/ajax\/libs\/reflect-metadata\/[^"]*\/Reflect\(\.min\)\?\.js/d' \
"$f" || true
# Insert the local script tags before build.js
sh /usr/local/bin/inject-polyfill-snippet.sh "$f"
SH
RUN sed -i '/sourceMappingURL/d' /usr/share/nginx/html/data-portal/vendor/*.js || true
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]