summaryrefslogtreecommitdiffstats
path: root/Dockerfile
blob: ff8667508947cfa75d8c4e8b1484c8e7f35a30b0 (plain) (blame)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# syntax=docker/dockerfile:1
# SPDX-License-Identifier: AGPL-3.0-or-later
# This file is part of Wolfree.
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

FROM alpine

WORKDIR /app/

# Install all dependencies.

RUN \
    apk add \
    -- \
    wget \
    npm \
    gcc \
    rustup \
    ;

RUN \
    rustup-init -y

COPY \
    ./docusaurus/package.json \
    ./docusaurus/package.json

RUN \
    npm install \
    --prefix ./docusaurus/ \
    -- \
    ;

# WolframAlpha LLC prebuilt the website and kindly deployed it on the Internet.
# We can run Wget to download the web pages and save them as static pages.

RUN \
    wget \
    --directory-prefix=./docusaurus/static/ \
    --no-host-directories \
    --page-requisites \
    --convert-links \
    --no-verbose \
    -- \
    'https://www.wolframalpha.com/input/index.html' \
    'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js' \
    'https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.5/purify.min.js' \
    ; \
    : \
    ;

RUN \
    sed \
    -e 's|.*js...static.chunks...........||' \
    -e 's|"........js.....miniCssF.*|.js\n|' \
    -e 's|:"|.|g' \
    -e 's|",|.js\n|g' \
    -- \
    ./docusaurus/static/_next/static/chunks/webpack-*.js \
    | \
    wget \
    --directory-prefix=./docusaurus/static/ \
    --no-host-directories \
    --page-requisites \
    --convert-links \
    --no-verbose \
    --input-file=- \
    --base=https://www.wolframalpha.com/_next/static/chunks/ \
    -- \
    ; \
    : \
    ;

RUN \
    sed \
    -e 's|.*return.static.css.....||' \
    -e 's|.........css.......function.*|.css\n|' \
    -e 's|[0-9]*:"||g' \
    -e 's|",|.css\n|g' \
    -- \
    ./docusaurus/static/_next/static/chunks/webpack-*.js \
    | \
    wget \
    --directory-prefix=./docusaurus/static/ \
    --no-host-directories \
    --page-requisites \
    --convert-links \
    --no-verbose \
    --input-file=- \
    --base=https://www.wolframalpha.com/_next/static/css/ \
    -- \
    ; \
    : \
    ;

# Delete unused large files on the static website.

RUN \
    truncate \
    -s 0 \
    -- \
    ./docusaurus/static/_next/static/images/* \
    ;

# Build the Docusaurus static website.

COPY \
    ./docusaurus/ \
    ./docusaurus/

RUN \
    npm run \
    --prefix ./docusaurus/ \
    -- \
    build \
    ;

# Lint the source code and run the Rust program.
# The Rust program customizes the static pages.

COPY \
    ./rust/ \
    ./rust/

RUN \
    PATH="$HOME/.cargo/bin:$PATH" \
    cargo clippy \
    --manifest-path ./rust/wolfree_libredirect_patch/Cargo.toml \
    -- \
    --warn clippy::all \
    --warn clippy::cargo \
    --warn clippy::nursery \
    --warn clippy::pedantic \
    --warn clippy::restriction \
    ;

RUN \
    PATH="$HOME/.cargo/bin:$PATH" \
    cargo clippy \
    --manifest-path ./rust/wolfree_sed_in_place/Cargo.toml \
    -- \
    --warn clippy::all \
    --warn clippy::cargo \
    --warn clippy::nursery \
    --warn clippy::pedantic \
    --warn clippy::restriction \
    ;

# Optionally, customize Wolfree instances to suit LibRedirect.
# https://github.com/libredirect/browser_extension/issues/425
# To integrate Wolfree with LibRedirect, please delete the number sign at the beginning of the following line.
# RUN PATH="$HOME/.cargo/bin:$PATH" cargo run --manifest-path ./rust/wolfree_libredirect_patch/Cargo.toml -- ;

RUN PATH="$HOME/.cargo/bin:$PATH" cargo run --manifest-path ./rust/wolfree_sed_in_place/Cargo.toml -- ;

# Optimizing builds with cache management | Docker Documentation
# https://docs.docker.com/build/cache/
# Because a change causes a rebuild for steps that follow,
# try to make expensive steps appear near the beginning of the Dockerfile.
# Steps that change often should appear near the end of the Dockerfile to avoid triggering rebuilds of layers that haven't changed.

CMD \
    npm run \
    --prefix ./docusaurus/ \
    -- \
    serve \
    --port 80 \
    --host localhost \
    ;

EXPOSE 80