summaryrefslogtreecommitdiffstats
path: root/Dockerfile
diff options
context:
space:
mode:
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile450
1 files changed, 303 insertions, 147 deletions
diff --git a/Dockerfile b/Dockerfile
index ff86675..24eb5a1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,171 +1,327 @@
-# 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
+FROM alpine AS stage-alpine
+
+# alpine - Official Image | Docker Hub
+# https://hub.docker.com/_/alpine
WORKDIR /app/
-# Install all dependencies.
+# Install all dependencies, including Wget, Rust, Docusaurus, and other required packages.
+
+RUN \
+apk \
+-- \
+add \
+wget \
+gcc \
+rustup \
+npm \
+;
+
+# Install the dependencies of Docusaurus and Typescript.
+
+COPY \
+./docusaurus/package.json \
+./docusaurus/package.json
+
+RUN \
+npm \
+--prefix ./docusaurus/ \
+-- \
+install \
+;
+
+RUN \
+npm \
+--prefix ./docusaurus/ \
+-- \
+audit \
+fix \
+;
+
+COPY \
+./typescript/package.json \
+./typescript/package.json
+
+RUN \
+npm \
+--prefix ./typescript/ \
+-- \
+install \
+;
+
+RUN \
+npm \
+--prefix ./typescript/ \
+-- \
+audit \
+fix \
+;
+
+# Set up the Rust compiler.
+
+RUN \
+rustup-init \
+-y \
+-- \
+;
+
+# Download the necessary dependencies for the Rust programs.
+
+COPY \
+./rust/wolfree_download_dependencies/ \
+./rust/wolfree_download_dependencies/
+
+RUN \
+PATH="$HOME/.cargo/bin:$PATH" \
+cargo \
+-- \
+clippy \
+--manifest-path ./rust/wolfree_download_dependencies/Cargo.toml \
+-- \
+--warn clippy::all \
+--warn clippy::cargo \
+--warn clippy::nursery \
+--warn clippy::pedantic \
+--warn clippy::restriction \
+;
+
+RUN \
+PATH="$HOME/.cargo/bin:$PATH" \
+cargo \
+run \
+--manifest-path ./rust/wolfree_download_dependencies/Cargo.toml \
+-- \
+;
+
+# Cloudflare and WolframAlpha are invaluable tools for web developers,
+# providing easy access to prebuilt JavaScript files.
+# To effortlessly obtain these files, you can utilize the Wget command-line utility.
+# Cloudflare's web servers offer a vast collection of popular JavaScript libraries.
+# On the other hand,
+# WolframAlpha's web servers specifically host the essential JavaScript files for the 2-dimensional math input editor.
+
+RUN \
+wget \
+--directory-prefix=./docusaurus/static/ \
+--no-host-directories \
+--page-requisites \
+--convert-links \
+--no-verbose \
+--input-file=- \
+--base= \
+-- \
+'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js' \
+'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.map' \
+'https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.5/purify.min.js' \
+'https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.5/purify.min.js.map' \
+'https://www.wolframalpha.com/input/index.html' \
+; \
+: \
+;
+
+# We use the Sed command to extract the pathnames from the "Webpack" and "buildManifest" files.
+# After successfully parsing the pathnames, we proceed to download the files using the Wget command.
+
+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/ \
+-- \
+; \
+: \
+;
RUN \
- apk add \
- -- \
- wget \
- npm \
- gcc \
- rustup \
- ;
+sed \
+-e 's|.*sortedPages.*}..||' \
+-e 's|...self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB.*||' \
+-e 's|","|\n|g' \
+-- \
+./docusaurus/static/_next/static/*/_buildManifest.js \
+| \
+wget \
+--directory-prefix=./docusaurus/static/ \
+--no-host-directories \
+--page-requisites \
+--convert-links \
+--no-verbose \
+--input-file=- \
+--base=https://www.wolframalpha.com/_next/ \
+-- \
+; \
+: \
+;
+
+# Remove unused large files,
+# such as decorative images,
+# from the static website.
RUN \
- rustup-init -y
+truncate \
+-s 0 \
+-- \
+./docusaurus/static/_next/static/images/* \
+./docusaurus/static/_next/static/media/*.png \
+./docusaurus/static/_next/static/media/*.gif \
+;
+
+# Compile and execute the Rust program.
+# The Rust program allows customization of the static pages downloaded with Wget.
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.
+./rust/wolfree_sed_in_place/ \
+./rust/wolfree_sed_in_place/
+
+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 \
+;
+
+RUN \
+PATH="$HOME/.cargo/bin:$PATH" \
+cargo run \
+--manifest-path ./rust/wolfree_sed_in_place/Cargo.toml \
+-- \
+;
+
+# Compile the Typescript files and output the JavaScript files.
COPY \
- ./docusaurus/ \
- ./docusaurus/
+./typescript/ \
+./typescript/
RUN \
- npm run \
- --prefix ./docusaurus/ \
- -- \
- build \
- ;
+npm \
+--prefix ./typescript/ \
+-- \
+exec \
+tsc \
+--project ./typescript/ \
+;
-# Lint the source code and run the Rust program.
-# The Rust program customizes the static pages.
+# Preprocess MDX files.
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 -- ;
+./docusaurus/ \
+./docusaurus/
+
+# Run the Rust program to customize the Docusaurus pages.
+
+COPY \
+./rust/wolfree_patch_libredirect/ \
+./rust/wolfree_patch_libredirect/
+
+RUN \
+PATH="$HOME/.cargo/bin:$PATH" \
+cargo \
+-- \
+clippy \
+--manifest-path ./rust/wolfree_patch_libredirect/Cargo.toml \
+-- \
+--warn clippy::all \
+--warn clippy::cargo \
+--warn clippy::nursery \
+--warn clippy::pedantic \
+--warn clippy::restriction \
+;
+
+RUN \
+PATH="$HOME/.cargo/bin:$PATH" \
+cargo run \
+--manifest-path ./rust/wolfree_patch_libredirect/Cargo.toml \
+-- \
+;
+
+# Create a webpage that lists all repositories and instructions for self-hosting web services.
+
+COPY \
+./README.md \
+./README.md
+
+RUN \
+cat \
+-- \
+./README.md \
+>> \
+./docusaurus/docs/source.mdx \
+;
+
+# Use Docusaurus to build the static website.
+
+RUN \
+npm \
+--prefix ./docusaurus/ \
+-- \
+run \
+build \
+;
+
+# Host the static content with a webserver.
+
+CMD \
+npm \
+--prefix ./docusaurus/ \
+-- \
+run \
+serve \
+--host localhost \
+--port 80 \
+;
+
+EXPOSE 80
+
+# TODO: multi-stage
+# https://docs.docker.com/build/building/multi-stage/
+# https://docs.docker.com/build/guide/multi-stage/
# 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