From 5f5a9acaba733070a55461b0e159530829187e20 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 12:52:04 -0700 Subject: [PATCH 01/37] docs: clean up apt commands --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index f2ed9a7c06..0f4a963c7a 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -15,8 +15,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.3.3 \ @@ -109,8 +112,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.3.5 \ @@ -210,8 +216,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_BRANCH=main From b4fb80b8d72a5f7c12092f4f924e8b1e2fc4e675 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 12:54:01 -0700 Subject: [PATCH 02/37] docs: add follow redirects to curl commands --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 0f4a963c7a..10cfee0f9b 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -37,7 +37,7 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main | tar -xz --strip=2 perseus-size-opt-main/examples/simple # go to src dir WORKDIR /app/simple @@ -134,7 +134,7 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir WORKDIR /app/tiny @@ -238,7 +238,7 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} From 6743ad95faaf0fe0a10b5a7f9bc3bf8e482e2e7e Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 13:00:08 -0700 Subject: [PATCH 03/37] docs: replace wget command, add short output filenames --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 10cfee0f9b..509bd67abe 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -72,8 +72,9 @@ RUN perseus deploy WORKDIR /app # download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ./package/bin/esbuild --version # run esbuild against bundle.js @@ -81,8 +82,9 @@ RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js --minify --tar && ls -lha ./simple/pkg/dist/pkg # download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm @@ -176,7 +178,8 @@ RUN perseus deploy WORKDIR /app # download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && ./package/bin/esbuild --version @@ -185,8 +188,9 @@ RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js --minify --targe && ls -lha ./tiny/pkg/dist/pkg # download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm From a62eed64fbd614446e2d9867232c95aad4dd1767 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 13:03:29 -0700 Subject: [PATCH 04/37] docs: prettify long or multiline commands --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 509bd67abe..66cba1bf25 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -37,7 +37,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ + | tar -xz --strip=2 perseus-size-opt-main/examples/simple # go to src dir WORKDIR /app/simple @@ -78,7 +79,11 @@ RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./simple/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg # download and unpack binaryen @@ -88,7 +93,9 @@ RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg # prepare deployment image @@ -136,7 +143,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir WORKDIR /app/tiny @@ -184,7 +192,11 @@ RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./tiny/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg # download and unpack binaryen @@ -194,7 +206,9 @@ RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg # prepare deployment image From 7b08fb5f66081a46297d1ec70902cd3d65a5a831 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 16:00:35 -0700 Subject: [PATCH 05/37] docs: replace echo commands, improve sed commands --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 47 ++++++++++++++-------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 66cba1bf25..842903538f 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -50,13 +50,24 @@ RUN cargo install perseus-cli --version $PERSEUS_VERSION RUN perseus clean && perseus prep # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i s"/perseus-size-opt = .*/perseus-size-opt = \"${PERSEUS_SIZE_OPT_VERSION}\"/" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 ${PERSEUS_VERSION}|g; \ + s|^\(perseus-size-opt =\).*$|\1 ${PERSEUS_SIZE_OPT_VERSION}|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify lib.rs -RUN sed -i s'/SizeOpts::default()/SizeOpts { wee_alloc: true, lto: true, opt_level: "s".to_string(), codegen_units: 1, enable_fluent_bundle_patch: false, }/' ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "\ + s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ + \1(\n\ + \2\n\ + SizeOpts {\n\ + wee_alloc: true,\n\ + lto: true,\n\ + opt_level: \"s\".to_string(),\n\ + codegen_units: 1,\n\ + enable_fluent_bundle_patch: false,\n\ + }\n\ + )|" ./src/lib.rs && cat ./src/lib.rs # run plugin(s) to adjust app RUN perseus tinker \ @@ -153,14 +164,16 @@ WORKDIR /app/tiny RUN cargo install perseus-cli --version $PERSEUS_VERSION # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i "/\[dependencies\]/a wee_alloc = \"${WEE_ALLOC_VERSION}\"" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify and prepend lib.rs -RUN echo '#[global_allocator] \n\ -static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; \n\ -' | cat - ./src/lib.rs > ./src/lib.rs.tmp \ +RUN printf '%s\n' \ + "#[global_allocator]" \ + "static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;" \ + | cat - ./src/lib.rs > ./src/lib.rs.tmp \ && mv ./src/lib.rs.tmp ./src/lib.rs \ && cat ./src/lib.rs @@ -168,12 +181,12 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; \n\ RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" .perseus/Cargo.toml \ - && echo ' \n\n\ -[profile.release] \n\ -codegen-units = 1 \n\ -opt-level = "s" \n\ -lto = true ' >> .perseus/Cargo.toml \ +RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ + && printf '%s\n' \ + "[profile.release]" \ + "codegen-units = 1" \ + "opt-level = \"s\"" \ + "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments From 7f91c86f1c4d66e04ba67f2719fe807a1221d73f Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 16:38:39 -0700 Subject: [PATCH 06/37] docs: improve esbuild and binaryen comments --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 842903538f..c9a4dc3375 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -51,8 +51,8 @@ RUN perseus clean && perseus prep # specify deps in app config RUN sed -i "\ - s|^\(perseus =\).*$|\1 ${PERSEUS_VERSION}|g; \ - s|^\(perseus-size-opt =\).*$|\1 ${PERSEUS_SIZE_OPT_VERSION}|g;" \ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ ./Cargo.toml && cat ./Cargo.toml # modify lib.rs @@ -83,7 +83,7 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild +# download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ @@ -97,7 +97,7 @@ RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download and unpack binaryen +# download, unpack, and verify install of binaryen RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ @@ -170,12 +170,10 @@ RUN sed -i "\ ./Cargo.toml && cat ./Cargo.toml # modify and prepend lib.rs -RUN printf '%s\n' \ - "#[global_allocator]" \ - "static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;" \ - | cat - ./src/lib.rs > ./src/lib.rs.tmp \ - && mv ./src/lib.rs.tmp ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "1i \ + #[global_allocator]\n\ + static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;" \ + ./src/lib.rs && cat ./src/lib.rs # clean, prep and eject app RUN perseus clean && perseus prep && perseus eject @@ -198,7 +196,7 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild +# download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ @@ -212,7 +210,7 @@ RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download and unpack binaryen +# download, unpack and verify install of binaryen RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ From 9426358ae4c84001916a8ef187bb73a01f42fdb9 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 16:46:54 -0700 Subject: [PATCH 07/37] docs: fixed 0.3.0-0.3.3 version number out of range --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index c9a4dc3375..c8ab17fc36 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -139,7 +139,7 @@ RUN apt update \ lsb-release # vars -ENV PERSEUS_VERSION=0.3.5 \ +ENV PERSEUS_VERSION=0.3.3 \ WEE_ALLOC_VERSION=0.4 \ ESBUILD_VERSION=0.14.7 \ BINARYEN_VERSION=104 @@ -172,7 +172,7 @@ RUN sed -i "\ # modify and prepend lib.rs RUN sed -i "1i \ #[global_allocator]\n\ - static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;" \ + static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ ./src/lib.rs && cat ./src/lib.rs # clean, prep and eject app From 82f612e09744d2ea81ff4dec686829335513b6ad Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 16:50:16 -0700 Subject: [PATCH 08/37] docs: fix 0.3.4 dockerfiles --- .../0.3.4/en-US/reference/deploying/docker.md | 124 ++++++++++++------ 1 file changed, 81 insertions(+), 43 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 83e7c738b9..ae76c2f96d 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -15,8 +15,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.3.5 \ @@ -34,7 +37,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ + | tar -xz --strip=2 perseus-size-opt-main/examples/simple # go to src dir WORKDIR /app/simple @@ -46,13 +50,24 @@ RUN cargo install perseus-cli --version $PERSEUS_VERSION RUN perseus clean && perseus prep # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i s"/perseus-size-opt = .*/perseus-size-opt = \"${PERSEUS_SIZE_OPT_VERSION}\"/" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify lib.rs -RUN sed -i s'/SizeOpts::default()/SizeOpts { wee_alloc: true, lto: true, opt_level: "s".to_string(), codegen_units: 1, enable_fluent_bundle_patch: false, }/' ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "\ + s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ + \1(\n\ + \2\n\ + SizeOpts {\n\ + wee_alloc: true,\n\ + lto: true,\n\ + opt_level: \"s\".to_string(),\n\ + codegen_units: 1,\n\ + enable_fluent_bundle_patch: false,\n\ + }\n\ + )|" ./src/lib.rs && cat ./src/lib.rs # run plugin(s) to adjust app RUN perseus tinker \ @@ -68,22 +83,30 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +# download, unpack, and verify install of esbuild +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./simple/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +# download, unpack, and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg # prepare deployment image @@ -109,8 +132,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.3.5 \ @@ -128,7 +154,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir WORKDIR /app/tiny @@ -137,27 +164,27 @@ WORKDIR /app/tiny RUN cargo install perseus-cli --version $PERSEUS_VERSION # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i "/\[dependencies\]/a wee_alloc = \"${WEE_ALLOC_VERSION}\"" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify and prepend lib.rs -RUN echo '#[global_allocator] \n\ -static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; \n\ -' | cat - ./src/lib.rs > ./src/lib.rs.tmp \ - && mv ./src/lib.rs.tmp ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "1i \ + #[global_allocator]\n\ + static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ + ./src/lib.rs && cat ./src/lib.rs # clean, prep and eject app RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" .perseus/Cargo.toml \ - && echo ' \n\n\ -[profile.release] \n\ -codegen-units = 1 \n\ -opt-level = "s" \n\ -lto = true ' >> .perseus/Cargo.toml \ +RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ + && printf '%s\n' \ + "[profile.release]" \ + "codegen-units = 1" \ + "opt-level = \"s\"" \ + "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments @@ -169,22 +196,30 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +# download, unpack, and verify install of esbuild +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./tiny/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +# download, unpack and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg # prepare deployment image @@ -210,8 +245,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_BRANCH=main @@ -229,7 +267,7 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} From 2bf80abcd201e6f27fe2d8c54eced23a655516bb Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 16:55:24 -0700 Subject: [PATCH 09/37] docs: fix 0.4.x/next dockerfiles --- docs/next/en-US/reference/deploying/docker.md | 124 ++++++++++++------ 1 file changed, 81 insertions(+), 43 deletions(-) diff --git a/docs/next/en-US/reference/deploying/docker.md b/docs/next/en-US/reference/deploying/docker.md index 193b024e18..cc20b32d97 100644 --- a/docs/next/en-US/reference/deploying/docker.md +++ b/docs/next/en-US/reference/deploying/docker.md @@ -15,8 +15,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -34,7 +37,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ + | tar -xz --strip=2 perseus-size-opt-main/examples/simple # go to src dir WORKDIR /app/simple @@ -46,13 +50,24 @@ RUN cargo install perseus-cli --version $PERSEUS_VERSION RUN perseus clean && perseus prep # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i s"/perseus-size-opt = .*/perseus-size-opt = \"${PERSEUS_SIZE_OPT_VERSION}\"/" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify lib.rs -RUN sed -i s'/SizeOpts::default()/SizeOpts { wee_alloc: true, lto: true, opt_level: "s".to_string(), codegen_units: 1, enable_fluent_bundle_patch: false, }/' ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "\ + s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ + \1(\n\ + \2\n\ + SizeOpts {\n\ + wee_alloc: true,\n\ + lto: true,\n\ + opt_level: \"s\".to_string(),\n\ + codegen_units: 1,\n\ + enable_fluent_bundle_patch: false,\n\ + }\n\ + )|" ./src/lib.rs && cat ./src/lib.rs # run plugin(s) to adjust app RUN perseus tinker \ @@ -68,22 +83,30 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +# download, unpack, and verify install of esbuild +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./simple/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +# download, unpack, and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg # prepare deployment image @@ -109,8 +132,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -128,7 +154,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir WORKDIR /app/tiny @@ -137,27 +164,27 @@ WORKDIR /app/tiny RUN cargo install perseus-cli --version $PERSEUS_VERSION # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i "/\[dependencies\]/a wee_alloc = \"${WEE_ALLOC_VERSION}\"" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify and prepend lib.rs -RUN echo '#[global_allocator] \n\ -static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; \n\ -' | cat - ./src/lib.rs > ./src/lib.rs.tmp \ - && mv ./src/lib.rs.tmp ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "1i \ + #[global_allocator]\n\ + static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ + ./src/lib.rs && cat ./src/lib.rs # clean, prep and eject app RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" .perseus/Cargo.toml \ - && echo ' \n\n\ -[profile.release] \n\ -codegen-units = 1 \n\ -opt-level = "s" \n\ -lto = true ' >> .perseus/Cargo.toml \ +RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ + && printf '%s\n' \ + "[profile.release]" \ + "codegen-units = 1" \ + "opt-level = \"s\"" \ + "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments @@ -169,22 +196,30 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +# download, unpack, and verify install of esbuild +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./tiny/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +# download, unpack and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg # prepare deployment image @@ -210,8 +245,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_BRANCH=main @@ -229,7 +267,7 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} From 0207ea8738cc6b0a0872ec5a965c4b448522e9e7 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 17:22:32 -0700 Subject: [PATCH 10/37] docs: fix missing leading dash for options in call to tar --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 2 +- docs/0.3.4/en-US/reference/deploying/docker.md | 2 +- docs/next/en-US/reference/deploying/docker.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index c8ab17fc36..23348ca1e6 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -199,7 +199,7 @@ WORKDIR /app # download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && ./package/bin/esbuild --version # run esbuild against bundle.js diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index ae76c2f96d..f4dbccb587 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -199,7 +199,7 @@ WORKDIR /app # download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && ./package/bin/esbuild --version # run esbuild against bundle.js diff --git a/docs/next/en-US/reference/deploying/docker.md b/docs/next/en-US/reference/deploying/docker.md index cc20b32d97..29eb8cbdcc 100644 --- a/docs/next/en-US/reference/deploying/docker.md +++ b/docs/next/en-US/reference/deploying/docker.md @@ -199,7 +199,7 @@ WORKDIR /app # download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && ./package/bin/esbuild --version # run esbuild against bundle.js From e864f101fc3112300d830f07c0753aaa633d0659 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 18 Jun 2022 17:39:25 -0700 Subject: [PATCH 11/37] docs: fix current beta dockerfile --- .../0.4.x/en-US/reference/deploying/docker.md | 126 ++++++++++++------ 1 file changed, 82 insertions(+), 44 deletions(-) diff --git a/docs/0.4.x/en-US/reference/deploying/docker.md b/docs/0.4.x/en-US/reference/deploying/docker.md index 193b024e18..29eb8cbdcc 100644 --- a/docs/0.4.x/en-US/reference/deploying/docker.md +++ b/docs/0.4.x/en-US/reference/deploying/docker.md @@ -15,8 +15,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -34,7 +37,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ + | tar -xz --strip=2 perseus-size-opt-main/examples/simple # go to src dir WORKDIR /app/simple @@ -46,13 +50,24 @@ RUN cargo install perseus-cli --version $PERSEUS_VERSION RUN perseus clean && perseus prep # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i s"/perseus-size-opt = .*/perseus-size-opt = \"${PERSEUS_SIZE_OPT_VERSION}\"/" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify lib.rs -RUN sed -i s'/SizeOpts::default()/SizeOpts { wee_alloc: true, lto: true, opt_level: "s".to_string(), codegen_units: 1, enable_fluent_bundle_patch: false, }/' ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "\ + s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ + \1(\n\ + \2\n\ + SizeOpts {\n\ + wee_alloc: true,\n\ + lto: true,\n\ + opt_level: \"s\".to_string(),\n\ + codegen_units: 1,\n\ + enable_fluent_bundle_patch: false,\n\ + }\n\ + )|" ./src/lib.rs && cat ./src/lib.rs # run plugin(s) to adjust app RUN perseus tinker \ @@ -68,22 +83,30 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +# download, unpack, and verify install of esbuild +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./simple/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +# download, unpack, and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg # prepare deployment image @@ -109,8 +132,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl wget + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -128,7 +154,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir WORKDIR /app/tiny @@ -137,27 +164,27 @@ WORKDIR /app/tiny RUN cargo install perseus-cli --version $PERSEUS_VERSION # specify deps in app config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" ./Cargo.toml \ - && sed -i "/\[dependencies\]/a wee_alloc = \"${WEE_ALLOC_VERSION}\"" ./Cargo.toml \ - && cat ./Cargo.toml +RUN sed -i "\ + s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ + s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + ./Cargo.toml && cat ./Cargo.toml # modify and prepend lib.rs -RUN echo '#[global_allocator] \n\ -static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; \n\ -' | cat - ./src/lib.rs > ./src/lib.rs.tmp \ - && mv ./src/lib.rs.tmp ./src/lib.rs \ - && cat ./src/lib.rs +RUN sed -i "1i \ + #[global_allocator]\n\ + static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ + ./src/lib.rs && cat ./src/lib.rs # clean, prep and eject app RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config -RUN sed -i s"/perseus = .*/perseus = \"${PERSEUS_VERSION}\"/" .perseus/Cargo.toml \ - && echo ' \n\n\ -[profile.release] \n\ -codegen-units = 1 \n\ -opt-level = "s" \n\ -lto = true ' >> .perseus/Cargo.toml \ +RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ + && printf '%s\n' \ + "[profile.release]" \ + "codegen-units = 1" \ + "opt-level = \"s\"" \ + "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments @@ -169,22 +196,30 @@ RUN perseus deploy # go back to app dir WORKDIR /app -# download and unpack esbuild -RUN curl -O https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar xf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ +# download, unpack, and verify install of esbuild +RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && ./package/bin/esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./tiny/pkg/dist/pkg/perseus_engine.js --allow-overwrite \ +RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download and unpack binaryen -RUN wget -nv https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ +# download, unpack and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ +RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ + -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg # prepare deployment image @@ -210,8 +245,11 @@ FROM rust:1.57-slim AS build # install build dependencies RUN apt update \ - && apt install -y --no-install-recommends lsb-release apt-transport-https \ - build-essential curl + && apt -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + lsb-release # vars ENV PERSEUS_BRANCH=main @@ -229,7 +267,7 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} From 73eb14c036a8b84b650657e9769cd20fd6efa954 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 19 Jun 2022 14:11:38 -0700 Subject: [PATCH 12/37] docs: fix perseus-size-opt builds --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 60 ++++++++----- .../0.3.4/en-US/reference/deploying/docker.md | 85 ++++++++++++------- .../0.4.x/en-US/reference/deploying/docker.md | 67 +++++++++------ docs/next/en-US/reference/deploying/docker.md | 67 +++++++++------ 4 files changed, 176 insertions(+), 103 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 23348ca1e6..ba7c11288c 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -19,7 +19,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.3.3 \ @@ -37,8 +40,16 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ - | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + +# download, unpack, and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/simple @@ -46,10 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# clean and prep app -RUN perseus clean && perseus prep - -# specify deps in app config +# specify metadata and deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ @@ -69,6 +77,9 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# clean and prep app +RUN perseus clean && perseus prep + # run plugin(s) to adjust app RUN perseus tinker \ && cat .perseus/Cargo.toml \ @@ -77,8 +88,9 @@ RUN perseus tinker \ # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy # go back to app dir WORKDIR /app @@ -87,24 +99,19 @@ WORKDIR /app RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ./package/bin/esbuild --version + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg @@ -136,7 +143,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.3.3 \ @@ -154,7 +164,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir @@ -249,7 +260,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_BRANCH=main @@ -267,7 +281,9 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ + | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index f4dbccb587..145a393b1b 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -19,7 +19,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.3.5 \ @@ -37,8 +40,16 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ - | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + +# download, unpack, and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/simple @@ -46,10 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# clean and prep app -RUN perseus clean && perseus prep - -# specify deps in app config +# specify metadata and deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ @@ -69,6 +77,9 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# clean and prep app +RUN perseus clean && perseus prep + # run plugin(s) to adjust app RUN perseus tinker \ && cat .perseus/Cargo.toml \ @@ -77,8 +88,9 @@ RUN perseus tinker \ # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy # go back to app dir WORKDIR /app @@ -87,24 +99,19 @@ WORKDIR /app RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ./package/bin/esbuild --version + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg @@ -136,7 +143,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.3.5 \ @@ -154,8 +164,16 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ - | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny + +# download, unpack and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/tiny @@ -181,6 +199,7 @@ RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ + "" "" \ "[profile.release]" \ "codegen-units = 1" \ "opt-level = \"s\"" \ @@ -190,8 +209,9 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy # go back to app dir WORKDIR /app @@ -199,7 +219,7 @@ WORKDIR /app # download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ./package/bin/esbuild --version # run esbuild against bundle.js @@ -210,14 +230,8 @@ RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg @@ -249,7 +263,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_BRANCH=main @@ -267,7 +284,9 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ + | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} diff --git a/docs/0.4.x/en-US/reference/deploying/docker.md b/docs/0.4.x/en-US/reference/deploying/docker.md index 29eb8cbdcc..cca0cee6fa 100644 --- a/docs/0.4.x/en-US/reference/deploying/docker.md +++ b/docs/0.4.x/en-US/reference/deploying/docker.md @@ -19,7 +19,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -37,8 +40,16 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ - | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + +# download, unpack, and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/simple @@ -46,10 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# clean and prep app -RUN perseus clean && perseus prep - -# specify deps in app config +# specify metadata and deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ @@ -69,6 +77,9 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# clean and prep app +RUN perseus clean && perseus prep + # run plugin(s) to adjust app RUN perseus tinker \ && cat .perseus/Cargo.toml \ @@ -77,8 +88,9 @@ RUN perseus tinker \ # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy # go back to app dir WORKDIR /app @@ -87,24 +99,19 @@ WORKDIR /app RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ./package/bin/esbuild --version + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg @@ -136,7 +143,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -154,7 +164,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir @@ -190,8 +201,11 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export OPENSSL_DIR=$( which openssl | sed 's|^\([^ ]\{1,\}\)openssl$|\1|' ) \ + && export OPENSSL_INCLUDE_DIR=/usr/include/openssl/ \ + && export OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/ \ + && perseus deploy # go back to app dir WORKDIR /app @@ -249,7 +263,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_BRANCH=main @@ -267,7 +284,9 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ + | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} diff --git a/docs/next/en-US/reference/deploying/docker.md b/docs/next/en-US/reference/deploying/docker.md index 29eb8cbdcc..cca0cee6fa 100644 --- a/docs/next/en-US/reference/deploying/docker.md +++ b/docs/next/en-US/reference/deploying/docker.md @@ -19,7 +19,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -37,8 +40,16 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/main \ - | tar -xz --strip=2 perseus-size-opt-main/examples/simple +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + +# download, unpack, and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/simple @@ -46,10 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# clean and prep app -RUN perseus clean && perseus prep - -# specify deps in app config +# specify metadata and deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ @@ -69,6 +77,9 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# clean and prep app +RUN perseus clean && perseus prep + # run plugin(s) to adjust app RUN perseus tinker \ && cat .perseus/Cargo.toml \ @@ -77,8 +88,9 @@ RUN perseus tinker \ # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy # go back to app dir WORKDIR /app @@ -87,24 +99,19 @@ WORKDIR /app RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ./package/bin/esbuild --version + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./simple/pkg/dist/pkg -# download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./simple/pkg/dist/pkg @@ -136,7 +143,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_VERSION=0.4.0-beta.1 \ @@ -154,7 +164,8 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny # go to src dir @@ -190,8 +201,11 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export OPENSSL_DIR=$( which openssl | sed 's|^\([^ ]\{1,\}\)openssl$|\1|' ) \ + && export OPENSSL_INCLUDE_DIR=/usr/include/openssl/ \ + && export OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/ \ + && perseus deploy # go back to app dir WORKDIR /app @@ -249,7 +263,10 @@ RUN apt update \ apt-transport-https \ build-essential \ curl \ - lsb-release + libssl-dev \ + lsb-release \ + openssl \ + pkg-config # vars ENV PERSEUS_BRANCH=main @@ -267,7 +284,9 @@ RUN cargo install wasm-pack RUN cargo install bonnie # retrieve the branch dir -RUN curl -L https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} | tar -xz +RUN curl -L \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ + | tar -xz # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} From 16135fafcaaeecd10461916bb78ce7517b0c98a6 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 19 Jun 2022 14:30:33 -0700 Subject: [PATCH 13/37] docs: fix wee_alloc builds, pending error_page patch --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 30 +++++++++++-------- .../0.3.4/en-US/reference/deploying/docker.md | 5 ++-- .../0.4.x/en-US/reference/deploying/docker.md | 29 +++++++++--------- docs/next/en-US/reference/deploying/docker.md | 29 +++++++++--------- 4 files changed, 50 insertions(+), 43 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index ba7c11288c..627448e600 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -166,7 +166,14 @@ RUN cargo install wasm-pack # retrieve the src dir RUN curl -L \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ - | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny + | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny + +# download, unpack and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/tiny @@ -192,6 +199,7 @@ RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ + "" "" \ "[profile.release]" \ "codegen-units = 1" \ "opt-level = \"s\"" \ @@ -201,8 +209,9 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app -RUN perseus deploy +# export variables required by wasm-bindgen and deploy app +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy # go back to app dir WORKDIR /app @@ -210,25 +219,20 @@ WORKDIR /app # download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && ./package/bin/esbuild --version + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 145a393b1b..773d00d698 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -220,10 +220,11 @@ WORKDIR /app RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ./package/bin/esbuild --version + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ diff --git a/docs/0.4.x/en-US/reference/deploying/docker.md b/docs/0.4.x/en-US/reference/deploying/docker.md index cca0cee6fa..8a7fb273a8 100644 --- a/docs/0.4.x/en-US/reference/deploying/docker.md +++ b/docs/0.4.x/en-US/reference/deploying/docker.md @@ -166,7 +166,14 @@ RUN cargo install wasm-pack # retrieve the src dir RUN curl -L \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ - | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny + | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny + +# download, unpack and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/tiny @@ -192,6 +199,7 @@ RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ + "" "" \ "[profile.release]" \ "codegen-units = 1" \ "opt-level = \"s\"" \ @@ -202,9 +210,7 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml #ENV PERSEUS_CLI_SEQUENTIAL=true # export variables required by wasm-bindgen and deploy app -RUN export OPENSSL_DIR=$( which openssl | sed 's|^\([^ ]\{1,\}\)openssl$|\1|' ) \ - && export OPENSSL_INCLUDE_DIR=/usr/include/openssl/ \ - && export OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/ \ +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy # go back to app dir @@ -213,25 +219,20 @@ WORKDIR /app # download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && ./package/bin/esbuild --version + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg diff --git a/docs/next/en-US/reference/deploying/docker.md b/docs/next/en-US/reference/deploying/docker.md index cca0cee6fa..8a7fb273a8 100644 --- a/docs/next/en-US/reference/deploying/docker.md +++ b/docs/next/en-US/reference/deploying/docker.md @@ -166,7 +166,14 @@ RUN cargo install wasm-pack # retrieve the src dir RUN curl -L \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ - | tar -xz --strip=2 perseus-${PERSEUS_VERSION}/examples/tiny + | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny + +# download, unpack and verify install of binaryen +RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version # go to src dir WORKDIR /app/tiny @@ -192,6 +199,7 @@ RUN perseus clean && perseus prep && perseus eject # adjust and append perseus config RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ + "" "" \ "[profile.release]" \ "codegen-units = 1" \ "opt-level = \"s\"" \ @@ -202,9 +210,7 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml #ENV PERSEUS_CLI_SEQUENTIAL=true # export variables required by wasm-bindgen and deploy app -RUN export OPENSSL_DIR=$( which openssl | sed 's|^\([^ ]\{1,\}\)openssl$|\1|' ) \ - && export OPENSSL_INCLUDE_DIR=/usr/include/openssl/ \ - && export OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/ \ +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy # go back to app dir @@ -213,25 +219,20 @@ WORKDIR /app # download, unpack, and verify install of esbuild RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && ./package/bin/esbuild --version + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version # run esbuild against bundle.js -RUN ./package/bin/esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ --minify \ --target=es6 \ --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./tiny/pkg/dist/pkg -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version - # run wasm-opt against bundle.wasm -RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt \ +RUN wasm-opt \ -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./tiny/pkg/dist/pkg From 8987624eedd4fc7c654782bf808ae1c313704349 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 19 Jun 2022 15:55:43 -0700 Subject: [PATCH 14/37] docs: fix examples path in bonnie build of 0.3.3 and 0.3.5 --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 10 +++++----- docs/0.3.4/en-US/reference/deploying/docker.md | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 627448e600..3f71d0a12e 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -266,6 +266,8 @@ RUN apt update \ curl \ libssl-dev \ lsb-release \ + nodejs \ + npm \ openssl \ pkg-config @@ -296,16 +298,14 @@ WORKDIR /app/perseus-${PERSEUS_BRANCH} RUN bonnie setup # clean app -RUN bonnie dev example tiny clean - -# go to the branch dir -WORKDIR /app/perseus-${PERSEUS_BRANCH} +RUN bonnie dev examples tiny clean # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true # deploy app -RUN bonnie dev example tiny deploy +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && bonnie dev examples tiny deploy # move branch dir RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 773d00d698..d6d2c276b2 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -266,6 +266,8 @@ RUN apt update \ curl \ libssl-dev \ lsb-release \ + nodejs \ + npm \ openssl \ pkg-config @@ -296,16 +298,14 @@ WORKDIR /app/perseus-${PERSEUS_BRANCH} RUN bonnie setup # clean app -RUN bonnie dev example tiny clean - -# go to the branch dir -WORKDIR /app/perseus-${PERSEUS_BRANCH} +RUN bonnie dev examples comprehensive tiny clean # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true # deploy app -RUN bonnie dev example tiny deploy +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && bonnie dev examples comprehensive tiny deploy # move branch dir RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch @@ -315,7 +315,7 @@ FROM debian:stable-slim WORKDIR /app -COPY --from=build /app/perseus-branch/examples/tiny/pkg /app/ +COPY --from=build /app/perseus-branch/examples/comprehensive/tiny/pkg /app/ ENV HOST=0.0.0.0 From 22d7467a830f68e4ba595a9eedfd8e62516c5b18 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 19 Jun 2022 16:26:49 -0700 Subject: [PATCH 15/37] docs: remove mention of metadata --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 6 +++--- docs/0.3.4/en-US/reference/deploying/docker.md | 6 +++--- docs/0.4.x/en-US/reference/deploying/docker.md | 2 +- docs/next/en-US/reference/deploying/docker.md | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 3f71d0a12e..2417d91ba5 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -57,7 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify metadata and deps in app config +# specify deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ @@ -298,14 +298,14 @@ WORKDIR /app/perseus-${PERSEUS_BRANCH} RUN bonnie setup # clean app -RUN bonnie dev examples tiny clean +RUN bonnie dev example tiny clean # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true # deploy app RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ - && bonnie dev examples tiny deploy + && bonnie dev example tiny deploy # move branch dir RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index d6d2c276b2..38b509828b 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -57,7 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify metadata and deps in app config +# specify deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ @@ -298,14 +298,14 @@ WORKDIR /app/perseus-${PERSEUS_BRANCH} RUN bonnie setup # clean app -RUN bonnie dev examples comprehensive tiny clean +RUN bonnie dev example comprehensive tiny clean # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true # deploy app RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ - && bonnie dev examples comprehensive tiny deploy + && bonnie dev example comprehensive tiny deploy # move branch dir RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch diff --git a/docs/0.4.x/en-US/reference/deploying/docker.md b/docs/0.4.x/en-US/reference/deploying/docker.md index 8a7fb273a8..d7ce6645b7 100644 --- a/docs/0.4.x/en-US/reference/deploying/docker.md +++ b/docs/0.4.x/en-US/reference/deploying/docker.md @@ -57,7 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify metadata and deps in app config +# specify deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ diff --git a/docs/next/en-US/reference/deploying/docker.md b/docs/next/en-US/reference/deploying/docker.md index 8a7fb273a8..d7ce6645b7 100644 --- a/docs/next/en-US/reference/deploying/docker.md +++ b/docs/next/en-US/reference/deploying/docker.md @@ -57,7 +57,7 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify metadata and deps in app config +# specify deps in app config RUN sed -i "\ s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ From f3e3f824530d7103fe776282367e0b872ac0f921 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 19 Jun 2022 17:54:04 -0700 Subject: [PATCH 16/37] docs: add prep and tinker bonnie subcommands --- .../0.3.4/en-US/reference/deploying/docker.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 38b509828b..1e89c35fb0 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -272,7 +272,9 @@ RUN apt update \ pkg-config # vars -ENV PERSEUS_BRANCH=main +ENV PERSEUS_STABLE_VERSION=0.3.5 \ + SYCAMORE_STABLE_VERSION=0.7.1 \ + PERSEUS_BRANCH=main # prepare root project dir WORKDIR /app @@ -294,16 +296,29 @@ RUN curl -L \ # go to branch dir WORKDIR /app/perseus-${PERSEUS_BRANCH} +# NOTE: +# +# Use of PERSEUS_STABLE_VERSION and SYCAMORE_STABLE_VERSION +# might be necessary to make adjustments to Cargo.toml before +# attempting to setup, clean, prep, tinker, and deploy the +# branch. + # install perseus-cli from branch RUN bonnie setup # clean app RUN bonnie dev example comprehensive tiny clean +# prep app +RUN bonnie dev example comprehensive tiny prep + +# run plugin(s) to adjust app +RUN bonnie dev example comprehensive tiny tinker + # single-threaded perseus CLI mode required for low memory environments #ENV PERSEUS_CLI_SEQUENTIAL=true -# deploy app +# serve app RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && bonnie dev example comprehensive tiny deploy From 589033faca97fcb4eb130f4ab488b7104cd3b4cf Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Mon, 20 Jun 2022 20:00:18 -0700 Subject: [PATCH 17/37] docs: fix failed build using cargo update --precise --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index 2417d91ba5..a414413df6 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -40,12 +40,12 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L \ +RUN curl -sL# \ https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple # download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +RUN curl -sL#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ @@ -57,10 +57,10 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify deps in app config +# specify precise versions for deps in app config RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ ./Cargo.toml && cat ./Cargo.toml # modify lib.rs @@ -77,6 +77,10 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# update dependencies to required versions +RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ + && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} + # clean and prep app RUN perseus clean && perseus prep @@ -96,7 +100,7 @@ RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ WORKDIR /app # download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ +RUN curl -sL#o esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ From b97f7a2610b057d7bd97db4d5f58ddd3f3d15ab1 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Mon, 20 Jun 2022 20:13:05 -0700 Subject: [PATCH 18/37] docs: prettify curl output as progress bar --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index a414413df6..f514b7f42e 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -40,12 +40,12 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -sL# \ +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple # download, unpack, and verify install of binaryen -RUN curl -sL#o binaryen-${BINARYEN_VERSION}.tar.gz \ +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ @@ -100,7 +100,7 @@ RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ WORKDIR /app # download, unpack, and verify install of esbuild -RUN curl -sL#o esbuild-${ESBUILD_VERSION}.tar.gz \ +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ From 224881be2e6214b3fbec18934eb1b4b0f3c7966b Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Mon, 20 Jun 2022 20:16:28 -0700 Subject: [PATCH 19/37] docs: prevent failed build using cargo update --precise --- docs/0.3.4/en-US/reference/deploying/docker.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 1e89c35fb0..395fdfb149 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -40,12 +40,12 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L \ +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple # download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ @@ -57,10 +57,10 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify deps in app config +# specify precise versions for deps in app config RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ ./Cargo.toml && cat ./Cargo.toml # modify lib.rs @@ -77,6 +77,10 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# update dependencies to required versions +RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ + && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} + # clean and prep app RUN perseus clean && perseus prep @@ -96,7 +100,7 @@ RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ WORKDIR /app # download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ From 93fce8d149053e38af3cdcd5dbb3f56661ae484b Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Mon, 20 Jun 2022 20:18:57 -0700 Subject: [PATCH 20/37] docs: prevent failed build using cargo update --precise --- docs/0.4.x/en-US/reference/deploying/docker.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/0.4.x/en-US/reference/deploying/docker.md b/docs/0.4.x/en-US/reference/deploying/docker.md index d7ce6645b7..4682126d73 100644 --- a/docs/0.4.x/en-US/reference/deploying/docker.md +++ b/docs/0.4.x/en-US/reference/deploying/docker.md @@ -40,12 +40,12 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L \ +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple # download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ @@ -57,10 +57,10 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify deps in app config +# specify precise versions for deps in app config RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ ./Cargo.toml && cat ./Cargo.toml # modify lib.rs @@ -77,6 +77,10 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# update dependencies to required versions +RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ + && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} + # clean and prep app RUN perseus clean && perseus prep @@ -96,7 +100,7 @@ RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ WORKDIR /app # download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ From d46af068e73410e449f3888afb336fedfc1cf7ee Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Mon, 20 Jun 2022 20:20:20 -0700 Subject: [PATCH 21/37] docs: prevent failed build using cargo update --precise --- docs/next/en-US/reference/deploying/docker.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/next/en-US/reference/deploying/docker.md b/docs/next/en-US/reference/deploying/docker.md index d7ce6645b7..4682126d73 100644 --- a/docs/next/en-US/reference/deploying/docker.md +++ b/docs/next/en-US/reference/deploying/docker.md @@ -40,12 +40,12 @@ RUN rustup target add wasm32-unknown-unknown RUN cargo install wasm-pack # retrieve the src dir -RUN curl -L \ +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple # download, unpack, and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ @@ -57,10 +57,10 @@ WORKDIR /app/simple # install perseus-cli RUN cargo install perseus-cli --version $PERSEUS_VERSION -# specify deps in app config +# specify precise versions for deps in app config RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ ./Cargo.toml && cat ./Cargo.toml # modify lib.rs @@ -77,6 +77,10 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs +# update dependencies to required versions +RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ + && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} + # clean and prep app RUN perseus clean && perseus prep @@ -96,7 +100,7 @@ RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ WORKDIR /app # download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ From b171f477a3ba434e43af1e1dd223683679133fe1 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Thu, 23 Jun 2022 18:29:34 -0700 Subject: [PATCH 22/37] docs: refactor of all dockerfile examples for v0.3.0-0.3.3 --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 354 ++++++++++++++------- 1 file changed, 231 insertions(+), 123 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index f514b7f42e..d7302acb58 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -10,10 +10,10 @@ Before proceeding with this section, you should be familiar with Docker's [multi Production example using the size optimizations plugin ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -24,46 +24,62 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.3.3 \ PERSEUS_SIZE_OPT_VERSION=0.1.7 \ + SYCAMORE_VERSION=0.7.1 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `perseus-cli`. +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# retrieve the src dir -RUN curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# download, unpack, and verify install of binaryen +# Download, unpack, symlink, and verify install of `binaryen`. RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/simple +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + +# Work from the src of the project. +WORKDIR /app/simple -# specify precise versions for deps in app config +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify lib.rs +# Modify the src of the project to implement size optimizations in `lib.rs`. RUN sed -i "\ s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ \1(\n\ @@ -77,58 +93,61 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs -# update dependencies to required versions -RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ - && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p perseus-size-opt --precise $PERSEUS_SIZE_OPT_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION -# clean and prep app -RUN perseus clean && perseus prep +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project. +RUN perseus clean \ + && perseus prep -# run plugin(s) to adjust app +# Run plugin(s) to adjust the project prior to deployment. RUN perseus tinker \ && cat .perseus/Cargo.toml \ && cat ./src/lib.rs -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# export variables required by wasm-bindgen and deploy app +# Export environment variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./simple/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./simple/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/simple/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -138,10 +157,10 @@ CMD ["./server"] Production examples using `wee_alloc` manually ```dockerfile -# get the base image +# Pull the base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -152,55 +171,79 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.3.3 \ - WEE_ALLOC_VERSION=0.4 \ + SYCAMORE_VERSION=0.7.1 \ + WEE_ALLOC_VERSION=0.4.5 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && target add wasm32-unknown-unknown -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `perseus-cli` +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# retrieve the src dir -RUN curl -L \ +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION + +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/tiny +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Work from the src of the project. +WORKDIR /app/tiny -# specify deps in app config +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|; + s|^\(\[dependencies\]\)$|\1\nwee_alloc = \"=${WEE_ALLOC_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify and prepend lib.rs +# Prepend modifications to the src of the project to implement `wee_alloc` in `lib.rs`. RUN sed -i "1i \ #[global_allocator]\n\ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ ./src/lib.rs && cat ./src/lib.rs -# clean, prep and eject app -RUN perseus clean && perseus prep && perseus eject +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION \ + && cargo update -p wee_alloc --precise $WEE_ALLOC_VERSION -# adjust and append perseus config +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project prior to ejecting it from the CLI. +RUN perseus clean \ + && perseus prep \ + && perseus eject + +# Append necessary modifications to the `Cargo.toml` file in the prepared project. RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ "" "" \ @@ -210,46 +253,46 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# export variables required by wasm-bindgen and deploy app +# Export variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./tiny/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./tiny/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/tiny/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -259,10 +302,10 @@ CMD ["./server"] Test example for deploying a specific branch from the Perseus repository ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -275,54 +318,119 @@ RUN apt update \ openssl \ pkg-config -# vars -ENV PERSEUS_BRANCH=main +# Export environment variables. +ENV PERSEUS_BRANCH=main \ + EXAMPLE_CATEGORY=comprehensive \ + EXAMPLE_NAME=tiny \ + BONNIE_VERSION=0.3.2 \ + BINARYEN_VERSION=104 \ + ESBUILD_VERSION=0.14.7 \ + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown + +# Install crate `bonnie`. +RUN cargo install bonnie --version $BONNIE_VERSION + +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION + +# Install dependencies required by package `perseus-website`. +RUN npm i -g browser-sync concurrently serve tailwindcss -# install wasm-pack -RUN cargo install wasm-pack +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version -# install bonnie -RUN cargo install bonnie +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# retrieve the branch dir -RUN curl -L \ +# Retrieve the current state of a branch in the `perseus` repo. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ | tar -xz -# go to branch dir +# Work from the requested branch of `perseus`. WORKDIR /app/perseus-${PERSEUS_BRANCH} -# install perseus-cli from branch +# Perform the following steps: +# - Patch `bonnie.toml` to remove backticks. +# - These break echoed strings and cause builds to fail. +# - Instruct `cargo` to only compile the binary target `perseus`. +# - Prevents "no space left on device" error in `docker`. +RUN sed -i "\ + s|\(cargo build\)|\1 --bin perseus|; \ + s|\`|'|g" ./bonnie.toml + +# Compile and install `perseus-cli` as defined by the current state of the repo's branch. RUN bonnie setup -# clean app -RUN bonnie dev example tiny clean +# Clean any pre-existing generated `./perseus` subdirectory from the project. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME clean + +# Prepare the project prior to deployment. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME prep -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs -# deploy app +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true + +# Export variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ - && bonnie dev example tiny deploy + && bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME deploy + +# Work from the path containing the deployed app. +WORKDIR /app/perseus-${PERSEUS_BRANCH}/examples/${EXAMPLE_CATEGORY}/${EXAMPLE_NAME} -# move branch dir +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ + && ls -lha ./pkg/dist/pkg + +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. +RUN wasm-opt \ + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg + +# Rename the dynamic path containing the deployed app to a static path. RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app -COPY --from=build /app/perseus-branch/examples/tiny/pkg /app/ +# Copy the deployed app into its chosen install path. +COPY --from=build /app/perseus-branch/examples/comprehensive/tiny/pkg /app/ +# Bind the container to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of `8080`. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` From d9b6a82d9445a48b6527b4bf607e86a8b17c3293 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Thu, 23 Jun 2022 18:32:00 -0700 Subject: [PATCH 23/37] docs: refactor of all dockerfile examples for v0.3.4 --- .../0.3.4/en-US/reference/deploying/docker.md | 361 +++++++++++------- 1 file changed, 227 insertions(+), 134 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 395fdfb149..2799455ee2 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -10,10 +10,10 @@ Before proceeding with this section, you should be familiar with Docker's [multi Production example using the size optimizations plugin ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -24,46 +24,62 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.3.5 \ PERSEUS_SIZE_OPT_VERSION=0.1.7 \ + SYCAMORE_VERSION=0.7.1 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `perseus-cli`. +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# retrieve the src dir -RUN curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# download, unpack, and verify install of binaryen +# Download, unpack, symlink, and verify install of `binaryen`. RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/simple +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple -# specify precise versions for deps in app config +# Work from the src of the project. +WORKDIR /app/simple + +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify lib.rs +# Modify the src of the project to implement size optimizations in `lib.rs`. RUN sed -i "\ s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ \1(\n\ @@ -77,58 +93,61 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs -# update dependencies to required versions -RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ - && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p perseus-size-opt --precise $PERSEUS_SIZE_OPT_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION -# clean and prep app -RUN perseus clean && perseus prep +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project. +RUN perseus clean \ + && perseus prep -# run plugin(s) to adjust app +# Run plugin(s) to adjust the project prior to deployment. RUN perseus tinker \ && cat .perseus/Cargo.toml \ && cat ./src/lib.rs -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# export variables required by wasm-bindgen and deploy app +# Export environment variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./simple/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./simple/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/simple/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -138,10 +157,10 @@ CMD ["./server"] Production examples using `wee_alloc` manually ```dockerfile -# get the base image +# Pull the base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -152,55 +171,79 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.3.5 \ - WEE_ALLOC_VERSION=0.4 \ + SYCAMORE_VERSION=0.7.1 \ + WEE_ALLOC_VERSION=0.4.5 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && target add wasm32-unknown-unknown + +# Install crate `perseus-cli` +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# retrieve the src dir -RUN curl -L \ +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/tiny +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Work from the src of the project. +WORKDIR /app/tiny -# specify deps in app config +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|; + s|^\(\[dependencies\]\)$|\1\nwee_alloc = \"=${WEE_ALLOC_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify and prepend lib.rs +# Prepend modifications to the src of the project to implement `wee_alloc` in `lib.rs`. RUN sed -i "1i \ #[global_allocator]\n\ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ ./src/lib.rs && cat ./src/lib.rs -# clean, prep and eject app -RUN perseus clean && perseus prep && perseus eject +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION \ + && cargo update -p wee_alloc --precise $WEE_ALLOC_VERSION + +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project prior to ejecting it from the CLI. +RUN perseus clean \ + && perseus prep \ + && perseus eject -# adjust and append perseus config +# Append necessary modifications to the `Cargo.toml` file in the prepared project. RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ "" "" \ @@ -210,46 +253,46 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs -# export variables required by wasm-bindgen and deploy app +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true + +# Export variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./tiny/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./tiny/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/tiny/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -259,10 +302,10 @@ CMD ["./server"] Test example for deploying a specific branch from the Perseus repository ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -275,69 +318,119 @@ RUN apt update \ openssl \ pkg-config -# vars -ENV PERSEUS_STABLE_VERSION=0.3.5 \ - SYCAMORE_STABLE_VERSION=0.7.1 \ - PERSEUS_BRANCH=main +# Export environment variables. +ENV PERSEUS_BRANCH=main \ + EXAMPLE_CATEGORY=comprehensive \ + EXAMPLE_NAME=tiny \ + BONNIE_VERSION=0.3.2 \ + BINARYEN_VERSION=104 \ + ESBUILD_VERSION=0.14.7 \ + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown + +# Install crate `bonnie`. +RUN cargo install bonnie --version $BONNIE_VERSION -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# install bonnie -RUN cargo install bonnie +# Install dependencies required by package `perseus-website`. +RUN npm i -g browser-sync concurrently serve tailwindcss -# retrieve the branch dir -RUN curl -L \ +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version + +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version + +# Retrieve the current state of a branch in the `perseus` repo. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ | tar -xz -# go to branch dir +# Work from the requested branch of `perseus`. WORKDIR /app/perseus-${PERSEUS_BRANCH} -# NOTE: -# -# Use of PERSEUS_STABLE_VERSION and SYCAMORE_STABLE_VERSION -# might be necessary to make adjustments to Cargo.toml before -# attempting to setup, clean, prep, tinker, and deploy the -# branch. +# Perform the following steps: +# - Patch `bonnie.toml` to remove backticks. +# - These break echoed strings and cause builds to fail. +# - Instruct `cargo` to only compile the binary target `perseus`. +# - Prevents "no space left on device" error in `docker`. +RUN sed -i "\ + s|\(cargo build\)|\1 --bin perseus|; \ + s|\`|'|g" ./bonnie.toml -# install perseus-cli from branch +# Compile and install `perseus-cli` as defined by the current state of the repo's branch. RUN bonnie setup -# clean app -RUN bonnie dev example comprehensive tiny clean +# Clean any pre-existing generated `./perseus` subdirectory from the project. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME clean -# prep app -RUN bonnie dev example comprehensive tiny prep +# Prepare the project prior to deployment. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME prep -# run plugin(s) to adjust app -RUN bonnie dev example comprehensive tiny tinker +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# serve app +# Export variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ - && bonnie dev example comprehensive tiny deploy + && bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME deploy + +# Work from the path containing the deployed app. +WORKDIR /app/perseus-${PERSEUS_BRANCH}/examples/${EXAMPLE_CATEGORY}/${EXAMPLE_NAME} -# move branch dir +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ + && ls -lha ./pkg/dist/pkg + +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. +RUN wasm-opt \ + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg + +# Rename the dynamic path containing the deployed app to a static path. RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the deployed app into its chosen install path. COPY --from=build /app/perseus-branch/examples/comprehensive/tiny/pkg /app/ +# Bind the container to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of `8080`. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` From 75470a45f90cae02dd8aae5e70e9232b24e274bd Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Thu, 23 Jun 2022 18:34:23 -0700 Subject: [PATCH 24/37] docs: refactor of all dockerfile examples for v0.4.x --- .../0.4.x/en-US/reference/deploying/docker.md | 358 ++++++++++++------ 1 file changed, 233 insertions(+), 125 deletions(-) diff --git a/docs/0.4.x/en-US/reference/deploying/docker.md b/docs/0.4.x/en-US/reference/deploying/docker.md index 4682126d73..b09268509b 100644 --- a/docs/0.4.x/en-US/reference/deploying/docker.md +++ b/docs/0.4.x/en-US/reference/deploying/docker.md @@ -10,10 +10,10 @@ Before proceeding with this section, you should be familiar with Docker's [multi Production example using the size optimizations plugin ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -24,46 +24,62 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.4.0-beta.1 \ PERSEUS_SIZE_OPT_VERSION=0.1.7 \ + SYCAMORE_VERSION=0.8.0-beta.6 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `perseus-cli`. +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# retrieve the src dir -RUN curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# download, unpack, and verify install of binaryen +# Download, unpack, symlink, and verify install of `binaryen`. RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/simple +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + +# Work from the src of the project. +WORKDIR /app/simple -# specify precise versions for deps in app config +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify lib.rs +# Modify the src of the project to implement size optimizations in `lib.rs`. RUN sed -i "\ s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ \1(\n\ @@ -77,58 +93,61 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs -# update dependencies to required versions -RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ - && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p perseus-size-opt --precise $PERSEUS_SIZE_OPT_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION -# clean and prep app -RUN perseus clean && perseus prep +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project. +RUN perseus clean \ + && perseus prep -# run plugin(s) to adjust app +# Run plugin(s) to adjust the project prior to deployment. RUN perseus tinker \ && cat .perseus/Cargo.toml \ && cat ./src/lib.rs -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# export variables required by wasm-bindgen and deploy app +# Export environment variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./simple/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./simple/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/simple/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -138,10 +157,10 @@ CMD ["./server"] Production examples using `wee_alloc` manually ```dockerfile -# get the base image +# Pull the base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -152,55 +171,79 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.4.0-beta.1 \ - WEE_ALLOC_VERSION=0.4 \ + SYCAMORE_VERSION=0.8.0-beta.6 \ + WEE_ALLOC_VERSION=0.4.5 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && target add wasm32-unknown-unknown -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `perseus-cli` +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# retrieve the src dir -RUN curl -L \ +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION + +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/tiny +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Work from the src of the project. +WORKDIR /app/tiny -# specify deps in app config +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|; + s|^\(\[dependencies\]\)$|\1\nwee_alloc = \"=${WEE_ALLOC_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify and prepend lib.rs +# Prepend modifications to the src of the project to implement `wee_alloc` in `lib.rs`. RUN sed -i "1i \ #[global_allocator]\n\ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ ./src/lib.rs && cat ./src/lib.rs -# clean, prep and eject app -RUN perseus clean && perseus prep && perseus eject +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION \ + && cargo update -p wee_alloc --precise $WEE_ALLOC_VERSION -# adjust and append perseus config +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project prior to ejecting it from the CLI. +RUN perseus clean \ + && perseus prep \ + && perseus eject + +# Append necessary modifications to the `Cargo.toml` file in the prepared project. RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ "" "" \ @@ -210,46 +253,46 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# export variables required by wasm-bindgen and deploy app +# Export variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./tiny/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./tiny/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/tiny/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -259,10 +302,10 @@ CMD ["./server"] Test example for deploying a specific branch from the Perseus repository ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -270,59 +313,124 @@ RUN apt update \ curl \ libssl-dev \ lsb-release \ + nodejs \ + npm \ openssl \ pkg-config -# vars -ENV PERSEUS_BRANCH=main +# Export environment variables. +ENV PERSEUS_BRANCH=main \ + EXAMPLE_CATEGORY=comprehensive \ + EXAMPLE_NAME=tiny \ + BONNIE_VERSION=0.3.2 \ + BINARYEN_VERSION=104 \ + ESBUILD_VERSION=0.14.7 \ + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown + +# Install crate `bonnie`. +RUN cargo install bonnie --version $BONNIE_VERSION -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# install bonnie -RUN cargo install bonnie +# Install dependencies required by package `perseus-website`. +RUN npm i -g browser-sync concurrently serve tailwindcss + +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version -# retrieve the branch dir -RUN curl -L \ +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version + +# Retrieve the current state of a branch in the `perseus` repo. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ | tar -xz -# go to branch dir +# Work from the requested branch of `perseus`. WORKDIR /app/perseus-${PERSEUS_BRANCH} -# install perseus-cli from branch +# Perform the following steps: +# - Patch `bonnie.toml` to remove backticks. +# - These break echoed strings and cause builds to fail. +# - Instruct `cargo` to only compile the binary target `perseus`. +# - Prevents "no space left on device" error in `docker`. +RUN sed -i "\ + s|\(cargo build\)|\1 --bin perseus|; \ + s|\`|'|g" ./bonnie.toml + +# Compile and install `perseus-cli` as defined by the current state of the repo's branch. RUN bonnie setup -# clean app -RUN bonnie dev example tiny clean +# Clean any pre-existing generated `./perseus` subdirectory from the project. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME clean -# go to the branch dir -WORKDIR /app/perseus-${PERSEUS_BRANCH} +# Prepare the project prior to deployment. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME prep -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs -# deploy app -RUN bonnie dev example tiny deploy +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# move branch dir +# Export variables required by `wasm-bindgen` and deploy the app from the project. +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME deploy + +# Work from the path containing the deployed app. +WORKDIR /app/perseus-${PERSEUS_BRANCH}/examples/${EXAMPLE_CATEGORY}/${EXAMPLE_NAME} + +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ + && ls -lha ./pkg/dist/pkg + +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. +RUN wasm-opt \ + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg + +# Rename the dynamic path containing the deployed app to a static path. RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app -COPY --from=build /app/perseus-branch/examples/tiny/pkg /app/ +# Copy the deployed app into its chosen install path. +COPY --from=build /app/perseus-branch/examples/comprehensive/tiny/pkg /app/ +# Bind the container to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of `8080`. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` From be0ed82cedee6cf4494375ffe7ad5cf57f24dc5b Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Thu, 23 Jun 2022 18:35:25 -0700 Subject: [PATCH 25/37] docs: refactor of all dockerfile examples for next --- docs/next/en-US/reference/deploying/docker.md | 358 ++++++++++++------ 1 file changed, 233 insertions(+), 125 deletions(-) diff --git a/docs/next/en-US/reference/deploying/docker.md b/docs/next/en-US/reference/deploying/docker.md index 4682126d73..b09268509b 100644 --- a/docs/next/en-US/reference/deploying/docker.md +++ b/docs/next/en-US/reference/deploying/docker.md @@ -10,10 +10,10 @@ Before proceeding with this section, you should be familiar with Docker's [multi Production example using the size optimizations plugin ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -24,46 +24,62 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.4.0-beta.1 \ PERSEUS_SIZE_OPT_VERSION=0.1.7 \ + SYCAMORE_VERSION=0.8.0-beta.6 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `perseus-cli`. +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# retrieve the src dir -RUN curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# download, unpack, and verify install of binaryen +# Download, unpack, symlink, and verify install of `binaryen`. RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/simple +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + +# Work from the src of the project. +WORKDIR /app/simple -# specify precise versions for deps in app config +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|g; \ - s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify lib.rs +# Modify the src of the project to implement size optimizations in `lib.rs`. RUN sed -i "\ s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ \1(\n\ @@ -77,58 +93,61 @@ RUN sed -i "\ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs -# update dependencies to required versions -RUN cargo update -p perseus --precise ${PERSEUS_VERSION} \ - && cargo update -p perseus-size-opt --precise ${PERSEUS_SIZE_OPT_VERSION} +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p perseus-size-opt --precise $PERSEUS_SIZE_OPT_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION -# clean and prep app -RUN perseus clean && perseus prep +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project. +RUN perseus clean \ + && perseus prep -# run plugin(s) to adjust app +# Run plugin(s) to adjust the project prior to deployment. RUN perseus tinker \ && cat .perseus/Cargo.toml \ && cat ./src/lib.rs -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# export variables required by wasm-bindgen and deploy app +# Export environment variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./simple/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./simple/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./simple/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./simple/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./simple/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/simple/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -138,10 +157,10 @@ CMD ["./server"] Production examples using `wee_alloc` manually ```dockerfile -# get the base image +# Pull the base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -152,55 +171,79 @@ RUN apt update \ openssl \ pkg-config -# vars +# Export environment variables. ENV PERSEUS_VERSION=0.4.0-beta.1 \ - WEE_ALLOC_VERSION=0.4 \ + SYCAMORE_VERSION=0.8.0-beta.6 \ + WEE_ALLOC_VERSION=0.4.5 \ + BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ - BINARYEN_VERSION=104 + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Perform the following steps: +# - Install latest `rust` from `stable` release channel. +# - Set `rust:stable` as default toolchain. +# - Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && target add wasm32-unknown-unknown -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `perseus-cli` +RUN cargo install perseus-cli --version $PERSEUS_VERSION -# retrieve the src dir -RUN curl -L \ +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION + +# Retrieve the src of the project and remove unnecessary boilerplate. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ | tar -xz --strip=3 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny -# download, unpack and verify install of binaryen -RUN curl -Lo binaryen-${BINARYEN_VERSION}.tar.gz \ +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version -# go to src dir -WORKDIR /app/tiny +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version -# install perseus-cli -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Work from the src of the project. +WORKDIR /app/tiny -# specify deps in app config +# Specify precise dependency versions in the project's `Cargo.toml` file. RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g; \ - s|^\(\[dependencies\]\)$|\1\n wee_alloc = \"${WEE_ALLOC_VERSION}\"|g;" \ + s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|; + s|^\(\[dependencies\]\)$|\1\nwee_alloc = \"=${WEE_ALLOC_VERSION}\"|;" \ ./Cargo.toml && cat ./Cargo.toml -# modify and prepend lib.rs +# Prepend modifications to the src of the project to implement `wee_alloc` in `lib.rs`. RUN sed -i "1i \ #[global_allocator]\n\ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;\n" \ ./src/lib.rs && cat ./src/lib.rs -# clean, prep and eject app -RUN perseus clean && perseus prep && perseus eject +# Update dependencies to their precise, required versions. +RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION \ + && cargo update -p wee_alloc --precise $WEE_ALLOC_VERSION -# adjust and append perseus config +# Clean any pre-existing generated `./perseus` subdirectory from the project, +# then prepare the project prior to ejecting it from the CLI. +RUN perseus clean \ + && perseus prep \ + && perseus eject + +# Append necessary modifications to the `Cargo.toml` file in the prepared project. RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml \ && printf '%s\n' \ "" "" \ @@ -210,46 +253,46 @@ RUN sed -i "s|^\(perseus =\).*$|\1 \"${PERSEUS_VERSION}\"|g" .perseus/Cargo.toml "lto = true" >> .perseus/Cargo.toml \ && cat .perseus/Cargo.toml -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# export variables required by wasm-bindgen and deploy app +# Export variables required by `wasm-bindgen` and deploy the app from the project. RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy -# go back to app dir -WORKDIR /app - -# download, unpack, and verify install of esbuild -RUN curl -Lo esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version - -# run esbuild against bundle.js -RUN esbuild ./tiny/pkg/dist/pkg/perseus_engine.js \ +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ - --outfile=./tiny/pkg/dist/pkg/perseus_engine.js \ + --target=esnext \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./tiny/pkg/dist/pkg + && ls -lha ./pkg/dist/pkg -# run wasm-opt against bundle.wasm +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. RUN wasm-opt \ - -Os ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./tiny/pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./tiny/pkg/dist/pkg + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app +# Copy the app into its chosen install path. COPY --from=build /app/tiny/pkg /app/ +# Bind the server to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of 8080. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` @@ -259,10 +302,10 @@ CMD ["./server"] Test example for deploying a specific branch from the Perseus repository ```dockerfile -# get the base image +# Pull base image. FROM rust:1.57-slim AS build -# install build dependencies +# Install build dependencies. RUN apt update \ && apt -y install --no-install-recommends \ apt-transport-https \ @@ -270,59 +313,124 @@ RUN apt update \ curl \ libssl-dev \ lsb-release \ + nodejs \ + npm \ openssl \ pkg-config -# vars -ENV PERSEUS_BRANCH=main +# Export environment variables. +ENV PERSEUS_BRANCH=main \ + EXAMPLE_CATEGORY=comprehensive \ + EXAMPLE_NAME=tiny \ + BONNIE_VERSION=0.3.2 \ + BINARYEN_VERSION=104 \ + ESBUILD_VERSION=0.14.7 \ + WASM_PACK_VERSION=0.10.3 \ + RUST_RELEASE_CHANNEL=stable -# prepare root project dir +# Work from the root of the project. WORKDIR /app -# download the target for wasm -RUN rustup target add wasm32-unknown-unknown +# Download the target for `wasm`. +RUN rustup install $RUST_RELEASE_CHANNEL \ + && rustup default $RUST_RELEASE_CHANNEL \ + && rustup target add wasm32-unknown-unknown + +# Install crate `bonnie`. +RUN cargo install bonnie --version $BONNIE_VERSION -# install wasm-pack -RUN cargo install wasm-pack +# Install crate `wasm-pack`. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION -# install bonnie -RUN cargo install bonnie +# Install dependencies required by package `perseus-website`. +RUN npm i -g browser-sync concurrently serve tailwindcss + +# Download, unpack, symlink, and verify install of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && wasm-opt --version -# retrieve the branch dir -RUN curl -L \ +# Download, unpack, symlink, and verify install of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + && esbuild --version + +# Retrieve the current state of a branch in the `perseus` repo. +RUN curl -L# \ https://codeload.github.com/arctic-hen7/perseus/tar.gz/${PERSEUS_BRANCH} \ | tar -xz -# go to branch dir +# Work from the requested branch of `perseus`. WORKDIR /app/perseus-${PERSEUS_BRANCH} -# install perseus-cli from branch +# Perform the following steps: +# - Patch `bonnie.toml` to remove backticks. +# - These break echoed strings and cause builds to fail. +# - Instruct `cargo` to only compile the binary target `perseus`. +# - Prevents "no space left on device" error in `docker`. +RUN sed -i "\ + s|\(cargo build\)|\1 --bin perseus|; \ + s|\`|'|g" ./bonnie.toml + +# Compile and install `perseus-cli` as defined by the current state of the repo's branch. RUN bonnie setup -# clean app -RUN bonnie dev example tiny clean +# Clean any pre-existing generated `./perseus` subdirectory from the project. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME clean -# go to the branch dir -WORKDIR /app/perseus-${PERSEUS_BRANCH} +# Prepare the project prior to deployment. +RUN bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME prep -# single-threaded perseus CLI mode required for low memory environments -#ENV PERSEUS_CLI_SEQUENTIAL=true +# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). +RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs -# deploy app -RUN bonnie dev example tiny deploy +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# move branch dir +# Export variables required by `wasm-bindgen` and deploy the app from the project. +RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && bonnie dev example $EXAMPLE_CATEGORY $EXAMPLE_NAME deploy + +# Work from the path containing the deployed app. +WORKDIR /app/perseus-${PERSEUS_BRANCH}/examples/${EXAMPLE_CATEGORY}/${EXAMPLE_NAME} + +# Run `esbuild` against `bundle.js` to optimize it into minified format. +RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ + --minify \ + --target=es6 \ + --outfile=./pkg/dist/pkg/perseus_engine.js \ + --allow-overwrite \ + && ls -lha ./pkg/dist/pkg + +# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. +RUN wasm-opt \ + -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ + -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ + && ls -lha ./pkg/dist/pkg + +# Rename the dynamic path containing the deployed app to a static path. RUN mv /app/perseus-${PERSEUS_BRANCH} /app/perseus-branch -# prepare deployment image +# Prepare the final image where the app will be deployed. FROM debian:stable-slim +# Work from a chosen install path for the deployed app. WORKDIR /app -COPY --from=build /app/perseus-branch/examples/tiny/pkg /app/ +# Copy the deployed app into its chosen install path. +COPY --from=build /app/perseus-branch/examples/comprehensive/tiny/pkg /app/ +# Bind the container to `localhost`. ENV HOST=0.0.0.0 +# Bind the container to the default port of `8080`. +ENV PORT=8080 + +# Configure the container to automatically serve the deployed app while running. CMD ["./server"] ``` From a55ab238eb4ef2f860f8e135e68ae8fcfb6d789c Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 2 Jul 2022 20:11:18 -0700 Subject: [PATCH 26/37] docs: remove apt cli warnings via apt-get, add cargo install via git, add patching of clippy error via gawk. --- docs/0.3.4/en-US/reference/deploying/docker.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 2799455ee2..f8cdf7ea8b 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -14,11 +14,13 @@ Before proceeding with this section, you should be familiar with Docker's [multi FROM rust:1.57-slim AS build # Install build dependencies. -RUN apt update \ - && apt -y install --no-install-recommends \ +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ apt-transport-https \ build-essential \ curl \ + gawk \ + git \ libssl-dev \ lsb-release \ openssl \ @@ -31,7 +33,8 @@ ENV PERSEUS_VERSION=0.3.5 \ BINARYEN_VERSION=104 \ ESBUILD_VERSION=0.14.7 \ WASM_PACK_VERSION=0.10.3 \ - RUST_RELEASE_CHANNEL=stable + RUST_RELEASE_CHANNEL=stable \ + CARGO_NET_GIT_FETCH_WITH_CLI=true # Work from the root of the project. WORKDIR /app @@ -109,7 +112,9 @@ RUN perseus tinker \ && cat ./src/lib.rs # Patch `clippy` inner attribute syntax error in `lib.rs` (if found). -RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs +RUN awk -i inplace \ + -v inner_attr="$(sed '3q;d' ./.perseus/src/lib.rs)" \ + 'NR==1 { print inner_attr } NR!=3 { print }' ./.perseus/src/lib.rs # Single-threaded perseus CLI mode required for low memory environments. # ENV PERSEUS_CLI_SEQUENTIAL=true From 877218799633b933bf256c15d820b9a6889e02dc Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 2 Jul 2022 20:13:42 -0700 Subject: [PATCH 27/37] docs: refactor env vars and workdir to top of file. --- .../0.3.4/en-US/reference/deploying/docker.md | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index f8cdf7ea8b..60d9ea8391 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -13,19 +13,6 @@ Before proceeding with this section, you should be familiar with Docker's [multi # Pull base image. FROM rust:1.57-slim AS build -# Install build dependencies. -RUN apt-get update \ - && apt-get -y install --no-install-recommends \ - apt-transport-https \ - build-essential \ - curl \ - gawk \ - git \ - libssl-dev \ - lsb-release \ - openssl \ - pkg-config - # Export environment variables. ENV PERSEUS_VERSION=0.3.5 \ PERSEUS_SIZE_OPT_VERSION=0.1.7 \ @@ -39,6 +26,19 @@ ENV PERSEUS_VERSION=0.3.5 \ # Work from the root of the project. WORKDIR /app +# Install build dependencies. +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + apt-transport-https \ + build-essential \ + curl \ + gawk \ + git \ + libssl-dev \ + lsb-release \ + openssl \ + pkg-config + # Perform the following steps: # - Install latest `rust` from `stable` release channel. # - Set `rust:stable` as default toolchain. From 4109738a733e9fd2f106684169dc43bf8ab079df Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 2 Jul 2022 20:15:13 -0700 Subject: [PATCH 28/37] docs: merge run commands to reduce artifacts. --- docs/0.3.4/en-US/reference/deploying/docker.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 60d9ea8391..45e8a5df3a 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -37,13 +37,8 @@ RUN apt-get update \ libssl-dev \ lsb-release \ openssl \ - pkg-config - -# Perform the following steps: -# - Install latest `rust` from `stable` release channel. -# - Set `rust:stable` as default toolchain. -# - Download the target for `wasm`. -RUN rustup install $RUST_RELEASE_CHANNEL \ + pkg-config \ + && rustup install $RUST_RELEASE_CHANNEL \ && rustup default $RUST_RELEASE_CHANNEL \ && rustup target add wasm32-unknown-unknown From 015ae338daf5036bac877af45446d660239a2c03 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sat, 2 Jul 2022 20:16:10 -0700 Subject: [PATCH 29/37] docs: rename base image from build to base. --- docs/0.3.4/en-US/reference/deploying/docker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 45e8a5df3a..25dd7b9bc3 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -11,7 +11,7 @@ Before proceeding with this section, you should be familiar with Docker's [multi ```dockerfile # Pull base image. -FROM rust:1.57-slim AS build +FROM rust:1.57-slim AS base # Export environment variables. ENV PERSEUS_VERSION=0.3.5 \ From b61ab80766ed42135e31a0d8fa052893ea130cf4 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 3 Jul 2022 02:13:32 -0700 Subject: [PATCH 30/37] docs: refactored dockerfile into multi-stage build. --- .../0.3.4/en-US/reference/deploying/docker.md | 140 ++++++++++-------- 1 file changed, 81 insertions(+), 59 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 25dd7b9bc3..c5ea16a966 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -23,8 +23,8 @@ ENV PERSEUS_VERSION=0.3.5 \ RUST_RELEASE_CHANNEL=stable \ CARGO_NET_GIT_FETCH_WITH_CLI=true -# Work from the root of the project. -WORKDIR /app +# Work from the root of the container. +WORKDIR / # Install build dependencies. RUN apt-get update \ @@ -42,43 +42,83 @@ RUN apt-get update \ && rustup default $RUST_RELEASE_CHANNEL \ && rustup target add wasm32-unknown-unknown -# Install crate `perseus-cli`. -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Create a build stage for `perseus-cli` that we can run in parallel. +FROM base as perseus -# Install crate `wasm-pack`. -RUN cargo install wasm-pack --version $WASM_PACK_VERSION +# Work from the desired install path for `perseus-cli`. +WORKDIR /perseus -# Download, unpack, symlink, and verify install of `binaryen`. +# Install crate `perseus-cli` into the work path. +RUN cargo install perseus-cli --version $PERSEUS_VERSION \ + && mv /usr/local/cargo/bin/perseus . + +# Create a build stage for `wasm-pack` that we can run in parallel. +FROM base as wasm-pack + +# Work from the install path for `wasm-pack`. +WORKDIR /wasm-pack + +# Install crate `wasm-pack` into the work path. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION \ + && mv /usr/local/cargo/bin/wasm-pack . + +# Create a build stage for `binaryen` we can run in parallel. +FROM base as binaryen + +# Work from the install path for `binaryen`. +WORKDIR /binaryen + +# Download, extract, and remove compressed tar of `binaryen`. RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ - && wasm-opt --version + && tar --strip-components=1 -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && rm -f binaryen-${BINARYEN_VERSION}.tar.gz -# Download, unpack, symlink, and verify install of `esbuild`. + # && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + # && wasm-opt --version + +# Create a build stage for `esbuild` we can run in parallel. +FROM base as esbuild + +# Work from the install path for `esbuild`. +WORKDIR /esbuild + +# Download, extract, and remove compressed tar of `esbuild`. RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version + && tar --strip-components=1 -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && rm -f esbuild-${ESBUILD_VERSION}.tar.gz -# Retrieve the src of the project and remove unnecessary boilerplate. -RUN curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple + # && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ + # && esbuild --version -# Work from the src of the project. -WORKDIR /app/simple +# Create a build stage for building our app. +FROM base as builder -# Specify precise dependency versions in the project's `Cargo.toml` file. -RUN sed -i "\ +# Copy the tools we previously prepared in parallel. +COPY --from=perseus /perseus/perseus /usr/bin/ +COPY --from=wasm-pack /wasm-pack/wasm-pack /usr/bin/ +COPY --from=binaryen /binaryen/ /binaryen/ +COPY --from=esbuild /esbuild/ /esbuild/ + +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true + +# Work from the root of the project. +WORKDIR /app + +# Run all required commands to build and deploy the project. +RUN ln -s /binaryen/bin/wasm-opt /usr/bin/wasm-opt \ + && ln -s /esbuild/bin/esbuild /usr/bin/esbuild \ + && curl -L# \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip-components=3 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple \ + && sed -i "\ s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|; \ s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" \ - ./Cargo.toml && cat ./Cargo.toml - -# Modify the src of the project to implement size optimizations in `lib.rs`. -RUN sed -i "\ + ./Cargo.toml && cat ./Cargo.toml \ + && sed -i "\ s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ \1(\n\ \2\n\ @@ -89,45 +129,27 @@ RUN sed -i "\ codegen_units: 1,\n\ enable_fluent_bundle_patch: false,\n\ }\n\ - )|" ./src/lib.rs && cat ./src/lib.rs - -# Update dependencies to their precise, required versions. -RUN cargo update -p perseus --precise $PERSEUS_VERSION \ + )|" ./src/lib.rs && cat ./src/lib.rs \ + && cargo update -p perseus --precise $PERSEUS_VERSION \ && cargo update -p perseus-size-opt --precise $PERSEUS_SIZE_OPT_VERSION \ - && cargo update -p sycamore --precise $SYCAMORE_VERSION - -# Clean any pre-existing generated `./perseus` subdirectory from the project, -# then prepare the project. -RUN perseus clean \ - && perseus prep - -# Run plugin(s) to adjust the project prior to deployment. -RUN perseus tinker \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION \ + && perseus clean \ + && perseus prep \ + && perseus tinker \ && cat .perseus/Cargo.toml \ - && cat ./src/lib.rs - -# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). -RUN awk -i inplace \ + && cat ./src/lib.rs \ + && awk -i inplace \ -v inner_attr="$(sed '3q;d' ./.perseus/src/lib.rs)" \ - 'NR==1 { print inner_attr } NR!=3 { print }' ./.perseus/src/lib.rs - -# Single-threaded perseus CLI mode required for low memory environments. -# ENV PERSEUS_CLI_SEQUENTIAL=true - -# Export environment variables required by `wasm-bindgen` and deploy the app from the project. -RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ - && perseus deploy - -# Run `esbuild` against `bundle.js` to optimize it into minified format. -RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ + 'NR==1 { print inner_attr } NR!=3 { print }' ./.perseus/src/lib.rs \ + && export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy \ + && esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ --target=esnext \ --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./pkg/dist/pkg - -# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. -RUN wasm-opt \ + && ls -lha ./pkg/dist/pkg \ + && wasm-opt \ -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./pkg/dist/pkg @@ -139,7 +161,7 @@ FROM debian:stable-slim WORKDIR /app # Copy the app into its chosen install path. -COPY --from=build /app/simple/pkg /app/ +COPY --from=builder /app/pkg /app/ # Bind the server to `localhost`. ENV HOST=0.0.0.0 From a3b703da9775a334eb0d552685d1a5d4f8e8f117 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 3 Jul 2022 13:41:45 -0700 Subject: [PATCH 31/37] docs: add conditional parsing of lib.rs using subshell. --- .../0.3.4/en-US/reference/deploying/docker.md | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index c5ea16a966..e41fe4d69b 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -45,7 +45,7 @@ RUN apt-get update \ # Create a build stage for `perseus-cli` that we can run in parallel. FROM base as perseus -# Work from the desired install path for `perseus-cli`. +# Work from the chosen install path for `perseus-cli`. WORKDIR /perseus # Install crate `perseus-cli` into the work path. @@ -55,7 +55,7 @@ RUN cargo install perseus-cli --version $PERSEUS_VERSION \ # Create a build stage for `wasm-pack` that we can run in parallel. FROM base as wasm-pack -# Work from the install path for `wasm-pack`. +# Work from the chosen install path for `wasm-pack`. WORKDIR /wasm-pack # Install crate `wasm-pack` into the work path. @@ -65,7 +65,7 @@ RUN cargo install wasm-pack --version $WASM_PACK_VERSION \ # Create a build stage for `binaryen` we can run in parallel. FROM base as binaryen -# Work from the install path for `binaryen`. +# Work from the chosen install path for `binaryen`. WORKDIR /binaryen # Download, extract, and remove compressed tar of `binaryen`. @@ -80,7 +80,7 @@ RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ # Create a build stage for `esbuild` we can run in parallel. FROM base as esbuild -# Work from the install path for `esbuild`. +# Work from the chosen install path for `esbuild`. WORKDIR /esbuild # Download, extract, and remove compressed tar of `esbuild`. @@ -98,8 +98,10 @@ FROM base as builder # Copy the tools we previously prepared in parallel. COPY --from=perseus /perseus/perseus /usr/bin/ COPY --from=wasm-pack /wasm-pack/wasm-pack /usr/bin/ -COPY --from=binaryen /binaryen/ /binaryen/ -COPY --from=esbuild /esbuild/ /esbuild/ +COPY --from=binaryen /binaryen/bin/ /usr/bin/ +COPY --from=binaryen /binaryen/include/ /usr/include/ +COPY --from=binaryen /binaryen/lib/ /usr/lib/ +COPY --from=esbuild /esbuild/bin/esbuild /usr/bin/ # Single-threaded perseus CLI mode required for low memory environments. # ENV PERSEUS_CLI_SEQUENTIAL=true @@ -108,8 +110,8 @@ COPY --from=esbuild /esbuild/ /esbuild/ WORKDIR /app # Run all required commands to build and deploy the project. -RUN ln -s /binaryen/bin/wasm-opt /usr/bin/wasm-opt \ - && ln -s /esbuild/bin/esbuild /usr/bin/esbuild \ +RUN . /etc/profile \ + && ./usr/local/cargo/env \ && curl -L# \ https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip-components=3 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple \ @@ -138,9 +140,25 @@ RUN ln -s /binaryen/bin/wasm-opt /usr/bin/wasm-opt \ && perseus tinker \ && cat .perseus/Cargo.toml \ && cat ./src/lib.rs \ - && awk -i inplace \ - -v inner_attr="$(sed '3q;d' ./.perseus/src/lib.rs)" \ - 'NR==1 { print inner_attr } NR!=3 { print }' ./.perseus/src/lib.rs \ + && ( \ + parse_file() { \ + local file_path="./.perseus/src/lib.rs" \ + local line_num=1 \ + while IFS= read -r line; do \ + if [ ! -z "$( sed "${line_num}q;d" | grep -e 'clippy' )" ]; then \ + break; \ + fi \ + line_num = $(( $line_num + 1 )) \ + done < $file_path \ + if [ $line_num -ne 1 ]; then \ + awk -i inplace \ + -v line_num=$line_num \ + -v inner_attr="$( sed "${line_num}q;d" ${file_path} )" \ + 'NR==1 { print inner_attr } NR!=line_num { print }' $file_path \ + fi \ + } \ + parse_file \ + ) \ && export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy \ && esbuild ./pkg/dist/pkg/perseus_engine.js \ From 5e0b1347cfeafd44438cba2e8702fbe8a57827ce Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 3 Jul 2022 14:55:17 -0700 Subject: [PATCH 32/37] docs: fix curly brace expected, missing file_path argument to sed. --- .../0.3.4/en-US/reference/deploying/docker.md | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index e41fe4d69b..587bc3e76b 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -110,8 +110,7 @@ COPY --from=esbuild /esbuild/bin/esbuild /usr/bin/ WORKDIR /app # Run all required commands to build and deploy the project. -RUN . /etc/profile \ - && ./usr/local/cargo/env \ +RUN . /etc/profile && . /usr/local/cargo/env \ && curl -L# \ https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip-components=3 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple \ @@ -141,22 +140,25 @@ RUN . /etc/profile \ && cat .perseus/Cargo.toml \ && cat ./src/lib.rs \ && ( \ - parse_file() { \ + parse_file() \{ \ local file_path="./.perseus/src/lib.rs" \ local line_num=1 \ - while IFS= read -r line; do \ - if [ ! -z "$( sed "${line_num}q;d" | grep -e 'clippy' )" ]; then \ - break; \ + while IFS= read -r line \ + do \ + if [ ! -z "$( sed "${line_num}q;d" ${file_path} | grep -e 'clippy' )" ] \ + then \ + break \ fi \ - line_num = $(( $line_num + 1 )) \ + line_num=$(( $line_num + 1 )) \ done < $file_path \ - if [ $line_num -ne 1 ]; then \ + if [ $line_num -ne 1 ] \ + then \ awk -i inplace \ -v line_num=$line_num \ -v inner_attr="$( sed "${line_num}q;d" ${file_path} )" \ 'NR==1 { print inner_attr } NR!=line_num { print }' $file_path \ fi \ - } \ + \} \ parse_file \ ) \ && export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ From cc310b77a4f165d0abc913ee61b33cb9153fe00c Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 3 Jul 2022 19:24:07 -0700 Subject: [PATCH 33/37] docs: fix small syntax errors. --- .../0.3.4/en-US/reference/deploying/docker.md | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 587bc3e76b..6fe1e5165c 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -137,30 +137,31 @@ RUN . /etc/profile && . /usr/local/cargo/env \ && perseus clean \ && perseus prep \ && perseus tinker \ - && cat .perseus/Cargo.toml \ + && cat ./.perseus/Cargo.toml \ && cat ./src/lib.rs \ - && ( \ - parse_file() \{ \ - local file_path="./.perseus/src/lib.rs" \ - local line_num=1 \ - while IFS= read -r line \ - do \ - if [ ! -z "$( sed "${line_num}q;d" ${file_path} | grep -e 'clippy' )" ] \ - then \ - break \ - fi \ - line_num=$(( $line_num + 1 )) \ - done < $file_path \ - if [ $line_num -ne 1 ] \ - then \ - awk -i inplace \ - -v line_num=$line_num \ - -v inner_attr="$( sed "${line_num}q;d" ${file_path} )" \ - 'NR==1 { print inner_attr } NR!=line_num { print }' $file_path \ - fi \ - \} \ - parse_file \ - ) \ + && printf '%s\n' \ + '#!/bin/sh' \ + 'parse_file () {' \ + ' local file_path=./.perseus/src/lib.rs' \ + ' local line_num=1' \ + ' while IFS= read -r lib_line' \ + ' do' \ + ' if [ ! -z $( echo ${lib_line} | cut -d " " -f 1 | grep -e "clippy" ) ]' \ + ' then' \ + ' break' \ + ' fi' \ + ' line_num=$(( $line_num + 1 ))' \ + ' done < $file_path' \ + ' if [ $line_num -ne 1 ]' \ + ' then' \ + ' awk -i inplace '"\\" \ + ' -v line_num=$line_num '"\\" \ + ' -v inner_attr=$( sed "${line_num}q;d" $file_path | cut -d " " -f 1 ) '"\\" \ + ' "NR==1 { print inner_attr } NR!=line_num { print }" $file_path' \ + ' fi' \ + '}' \ + 'parse_file' > ./parse_file.sh \ + && chmod +x ./parse_file.sh && . ./parse_file.sh && rm -f ./parse_file.sh \ && export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ && perseus deploy \ && esbuild ./pkg/dist/pkg/perseus_engine.js \ From e09257fe12b17432718395a2109170c581c2b1d4 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Sun, 3 Jul 2022 19:54:27 -0700 Subject: [PATCH 34/37] docs: restore es6/es2015 as target for esbuild. --- docs/0.3.4/en-US/reference/deploying/docker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index 6fe1e5165c..c1443407be 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -166,7 +166,7 @@ RUN . /etc/profile && . /usr/local/cargo/env \ && perseus deploy \ && esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=esnext \ + --target=es6 \ --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./pkg/dist/pkg \ From 1d178cb9785b3e7bf8ea7a9a8014c1f18bbb1a77 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Mon, 11 Jul 2022 02:17:17 -0700 Subject: [PATCH 35/37] docs: migrate from simple to tiny, build perseus-size-opt from source. --- .../0.3.4/en-US/reference/deploying/docker.md | 84 +++++++++++++------ 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index c1443407be..e5311083df 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -13,15 +13,27 @@ Before proceeding with this section, you should be familiar with Docker's [multi # Pull base image. FROM rust:1.57-slim AS base +# Define optional command-line build arguments. +ARG PERSEUS_VERSION \ + PERSEUS_SIZE_OPT_VERSION \ + SYCAMORE_VERSION \ + BINARYEN_VERSION \ + ESBUILD_VERSION \ + ESBUILD_TARGET \ + WASM_PACK_VERSION \ + RUST_RELEASE_CHANNEL \ + CARGO_NET_GIT_FETCH_WITH_CLI + # Export environment variables. -ENV PERSEUS_VERSION=0.3.5 \ - PERSEUS_SIZE_OPT_VERSION=0.1.7 \ - SYCAMORE_VERSION=0.7.1 \ - BINARYEN_VERSION=104 \ - ESBUILD_VERSION=0.14.7 \ - WASM_PACK_VERSION=0.10.3 \ - RUST_RELEASE_CHANNEL=stable \ - CARGO_NET_GIT_FETCH_WITH_CLI=true +ENV PERSEUS_VERSION=${PERSEUS_VERSION:-0.3.5} \ + PERSEUS_SIZE_OPT_VERSION=${PERSEUS_SIZE_OPT_VERSION:-0.1.9} \ + SYCAMORE_VERSION=${SYCAMORE_VERSION:-0.7.1} \ + BINARYEN_VERSION=${BINARYEN_VERSION:-104} \ + ESBUILD_VERSION=${ESBUILD_VERSION:-0.14.7} \ + ESBUILD_TARGET=${ESBUILD_TARGET:-es6} \ + WASM_PACK_VERSION=${WASM_PACK_VERSION:-0.10.3} \ + RUST_RELEASE_CHANNEL=${RUST_RELEASE_CHANNEL:-stable} \ + CARGO_NET_GIT_FETCH_WITH_CLI=${CARGO_NET_GIT_FETCH_WITH_CLI:-false} # Work from the root of the container. WORKDIR / @@ -38,8 +50,8 @@ RUN apt-get update \ lsb-release \ openssl \ pkg-config \ - && rustup install $RUST_RELEASE_CHANNEL \ - && rustup default $RUST_RELEASE_CHANNEL \ + && rustup install ${RUST_RELEASE_CHANNEL} \ + && rustup default ${RUST_RELEASE_CHANNEL} \ && rustup target add wasm32-unknown-unknown # Create a build stage for `perseus-cli` that we can run in parallel. @@ -52,6 +64,27 @@ WORKDIR /perseus RUN cargo install perseus-cli --version $PERSEUS_VERSION \ && mv /usr/local/cargo/bin/perseus . +# Create a build stage for `perseus-size-opt` that we can run in parallel. +FROM base as perseus-size-opt + +# Work from the chosen install path for `perseus-size-opt`. +WORKDIR /perseus-size-opt + +# Download and make adjustments to the source of `perseus-size-opt`. +RUN curl -L# https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip-components=1 \ + && rm -rf ./examples \ + && sed -i "s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|" ./Cargo.toml \ + && printf '%s\n' \ + '#!/bin/sh' \ + 'rm_workspace () {' \ + ' local a=$( grep -ne "^\[workspace\]$" ./Cargo.toml | grep -Eo "^[^:]+" )' \ + ' local b=$( grep -ne "^\]$" ./Cargo.toml | grep -Eo "^[^:]+" )' \ + ' sed -i "${a},${b}d" ./Cargo.toml' \ + '}' \ + 'rm_workspace' > ./rm_workspace.sh \ + && chmod +x ./rm_workspace.sh && . ./rm_workspace.sh && rm -f ./rm_workspace.sh + # Create a build stage for `wasm-pack` that we can run in parallel. FROM base as wasm-pack @@ -74,9 +107,6 @@ RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ && tar --strip-components=1 -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ && rm -f binaryen-${BINARYEN_VERSION}.tar.gz - # && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ - # && wasm-opt --version - # Create a build stage for `esbuild` we can run in parallel. FROM base as esbuild @@ -89,14 +119,12 @@ RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ && tar --strip-components=1 -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ && rm -f esbuild-${ESBUILD_VERSION}.tar.gz - # && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - # && esbuild --version - # Create a build stage for building our app. FROM base as builder # Copy the tools we previously prepared in parallel. COPY --from=perseus /perseus/perseus /usr/bin/ +COPY --from=perseus-size-opt /perseus-size-opt /perseus-size-opt/ COPY --from=wasm-pack /wasm-pack/wasm-pack /usr/bin/ COPY --from=binaryen /binaryen/bin/ /usr/bin/ COPY --from=binaryen /binaryen/include/ /usr/include/ @@ -109,16 +137,19 @@ COPY --from=esbuild /esbuild/bin/esbuild /usr/bin/ # Work from the root of the project. WORKDIR /app -# Run all required commands to build and deploy the project. +# Build and deploy our app using the following commands. RUN . /etc/profile && . /usr/local/cargo/env \ && curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -xz --strip-components=3 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip-components=4 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny \ && sed -i "\ - s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ - s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|; \ - s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" \ - ./Cargo.toml && cat ./Cargo.toml \ + s|^\(perseus =\).*$|\1 \{ version = \"=${PERSEUS_VERSION}\", features = \[ \"hydrate\" \] \}|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" ./Cargo.toml \ + && printf '%s\n' "perseus-size-opt = { path = \"/perseus-size-opt\", version = \"=${PERSEUS_SIZE_OPT_VERSION}\" }" >> ./Cargo.toml \ + && cat ./Cargo.toml \ + && curl -L# \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -C ./src -xz --strip-components=4 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple/src \ && sed -i "\ s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ \1(\n\ @@ -132,7 +163,6 @@ RUN . /etc/profile && . /usr/local/cargo/env \ }\n\ )|" ./src/lib.rs && cat ./src/lib.rs \ && cargo update -p perseus --precise $PERSEUS_VERSION \ - && cargo update -p perseus-size-opt --precise $PERSEUS_SIZE_OPT_VERSION \ && cargo update -p sycamore --precise $SYCAMORE_VERSION \ && perseus clean \ && perseus prep \ @@ -166,7 +196,7 @@ RUN . /etc/profile && . /usr/local/cargo/env \ && perseus deploy \ && esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=es6 \ + --target=${ESBUILD_TARGET} \ --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ && ls -lha ./pkg/dist/pkg \ @@ -249,7 +279,7 @@ RUN curl -L# \ RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && ln -s $(pwd)/BINARYEN_Version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version # Download, unpack, symlink, and verify install of `esbuild`. @@ -392,7 +422,7 @@ RUN npm i -g browser-sync concurrently serve tailwindcss RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ + && ln -s $(pwd)/BINARYEN_Version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ && wasm-opt --version # Download, unpack, symlink, and verify install of `esbuild`. From 158de7c8e81da79f3cc15c7a54391a6b1b7a720d Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Mon, 11 Jul 2022 02:27:34 -0700 Subject: [PATCH 36/37] docs: refactor tiny example to match 0.3.4. --- docs/0.3.0-0.3.3/en-US/deploying/docker.md | 237 ++++++++++++++------- 1 file changed, 155 insertions(+), 82 deletions(-) diff --git a/docs/0.3.0-0.3.3/en-US/deploying/docker.md b/docs/0.3.0-0.3.3/en-US/deploying/docker.md index d7302acb58..be9c595763 100644 --- a/docs/0.3.0-0.3.3/en-US/deploying/docker.md +++ b/docs/0.3.0-0.3.3/en-US/deploying/docker.md @@ -11,76 +11,146 @@ Before proceeding with this section, you should be familiar with Docker's [multi ```dockerfile # Pull base image. -FROM rust:1.57-slim AS build +FROM rust:1.57-slim AS base + +# Define optional command-line build arguments. +ARG PERSEUS_VERSION \ + PERSEUS_SIZE_OPT_VERSION \ + SYCAMORE_VERSION \ + BINARYEN_VERSION \ + ESBUILD_VERSION \ + ESBUILD_TARGET \ + WASM_PACK_VERSION \ + RUST_RELEASE_CHANNEL \ + CARGO_NET_GIT_FETCH_WITH_CLI + +# Export environment variables. +ENV PERSEUS_VERSION=${PERSEUS_VERSION:-0.3.0} \ + PERSEUS_SIZE_OPT_VERSION=${PERSEUS_SIZE_OPT_VERSION:-0.1.7} \ + SYCAMORE_VERSION=${SYCAMORE_VERSION:-0.7.1} \ + BINARYEN_VERSION=${BINARYEN_VERSION:-104} \ + ESBUILD_VERSION=${ESBUILD_VERSION:-0.14.7} \ + ESBUILD_TARGET=${ESBUILD_TARGET:-es6} \ + WASM_PACK_VERSION=${WASM_PACK_VERSION:-0.10.3} \ + RUST_RELEASE_CHANNEL=${RUST_RELEASE_CHANNEL:-stable} \ + CARGO_NET_GIT_FETCH_WITH_CLI=${CARGO_NET_GIT_FETCH_WITH_CLI:-false} + +# Work from the root of the container. +WORKDIR / # Install build dependencies. -RUN apt update \ - && apt -y install --no-install-recommends \ +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ apt-transport-https \ build-essential \ curl \ + gawk \ + git \ libssl-dev \ lsb-release \ openssl \ - pkg-config + pkg-config \ + && rustup install ${RUST_RELEASE_CHANNEL} \ + && rustup default ${RUST_RELEASE_CHANNEL} \ + && rustup target add wasm32-unknown-unknown -# Export environment variables. -ENV PERSEUS_VERSION=0.3.3 \ - PERSEUS_SIZE_OPT_VERSION=0.1.7 \ - SYCAMORE_VERSION=0.7.1 \ - BINARYEN_VERSION=104 \ - ESBUILD_VERSION=0.14.7 \ - WASM_PACK_VERSION=0.10.3 \ - RUST_RELEASE_CHANNEL=stable +# Create a build stage for `perseus-cli` that we can run in parallel. +FROM base as perseus -# Work from the root of the project. -WORKDIR /app +# Work from the chosen install path for `perseus-cli`. +WORKDIR /perseus -# Perform the following steps: -# - Install latest `rust` from `stable` release channel. -# - Set `rust:stable` as default toolchain. -# - Download the target for `wasm`. -RUN rustup install $RUST_RELEASE_CHANNEL \ - && rustup default $RUST_RELEASE_CHANNEL \ - && rustup target add wasm32-unknown-unknown +# Install crate `perseus-cli` into the work path. +RUN cargo install perseus-cli --version $PERSEUS_VERSION \ + && mv /usr/local/cargo/bin/perseus . -# Install crate `perseus-cli`. -RUN cargo install perseus-cli --version $PERSEUS_VERSION +# Create a build stage for `perseus-size-opt` that we can run in parallel. +FROM base as perseus-size-opt -# Install crate `wasm-pack`. -RUN cargo install wasm-pack --version $WASM_PACK_VERSION +# Work from the chosen install path for `perseus-size-opt`. +WORKDIR /perseus-size-opt -# Download, unpack, symlink, and verify install of `binaryen`. +# Download and make adjustments to the source of `perseus-size-opt`. +RUN curl -L# https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -xz --strip-components=1 \ + && rm -rf ./examples \ + && sed -i "s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|" ./Cargo.toml \ + && printf '%s\n' \ + '#!/bin/sh' \ + 'rm_workspace () {' \ + ' local a=$( grep -ne "^\[workspace\]$" ./Cargo.toml | grep -Eo "^[^:]+" )' \ + ' local b=$( grep -ne "^\]$" ./Cargo.toml | grep -Eo "^[^:]+" )' \ + ' sed -i "${a},${b}d" ./Cargo.toml' \ + '}' \ + 'rm_workspace' > ./rm_workspace.sh \ + && chmod +x ./rm_workspace.sh && . ./rm_workspace.sh && rm -f ./rm_workspace.sh + +# Create a build stage for `wasm-pack` that we can run in parallel. +FROM base as wasm-pack + +# Work from the chosen install path for `wasm-pack`. +WORKDIR /wasm-pack + +# Install crate `wasm-pack` into the work path. +RUN cargo install wasm-pack --version $WASM_PACK_VERSION \ + && mv /usr/local/cargo/bin/wasm-pack . + +# Create a build stage for `binaryen` we can run in parallel. +FROM base as binaryen + +# Work from the chosen install path for `binaryen`. +WORKDIR /binaryen + +# Download, extract, and remove compressed tar of `binaryen`. RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && ln -s $(pwd)/binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt /usr/bin/wasm-opt \ - && wasm-opt --version + && tar --strip-components=1 -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && rm -f binaryen-${BINARYEN_VERSION}.tar.gz -# Download, unpack, symlink, and verify install of `esbuild`. +# Create a build stage for `esbuild` we can run in parallel. +FROM base as esbuild + +# Work from the chosen install path for `esbuild`. +WORKDIR /esbuild + +# Download, extract, and remove compressed tar of `esbuild`. RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && ln -s $(pwd)/package/bin/esbuild /usr/bin/esbuild \ - && esbuild --version + && tar --strip-components=1 -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && rm -f esbuild-${ESBUILD_VERSION}.tar.gz -# Retrieve the src of the project and remove unnecessary boilerplate. -RUN curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -xz --strip=2 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple +# Create a build stage for building our app. +FROM base as builder -# Work from the src of the project. -WORKDIR /app/simple +# Copy the tools we previously prepared in parallel. +COPY --from=perseus /perseus/perseus /usr/bin/ +COPY --from=perseus-size-opt /perseus-size-opt /perseus-size-opt/ +COPY --from=wasm-pack /wasm-pack/wasm-pack /usr/bin/ +COPY --from=binaryen /binaryen/bin/ /usr/bin/ +COPY --from=binaryen /binaryen/include/ /usr/include/ +COPY --from=binaryen /binaryen/lib/ /usr/lib/ +COPY --from=esbuild /esbuild/bin/esbuild /usr/bin/ -# Specify precise dependency versions in the project's `Cargo.toml` file. -RUN sed -i "\ - s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|; \ - s|^\(perseus-size-opt =\).*$|\1 \"=${PERSEUS_SIZE_OPT_VERSION}\"|; \ - s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" \ - ./Cargo.toml && cat ./Cargo.toml +# Single-threaded perseus CLI mode required for low memory environments. +# ENV PERSEUS_CLI_SEQUENTIAL=true -# Modify the src of the project to implement size optimizations in `lib.rs`. -RUN sed -i "\ +# Work from the root of the project. +WORKDIR /app + +# Build and deploy our app using the following commands. +RUN . /etc/profile && . /usr/local/cargo/env \ + && curl -L# \ + https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip-components=3 perseus-${PERSEUS_VERSION}/examples/tiny \ + && sed -i "\ + s|^\(perseus =\).*$|\1 \{ version = \"=${PERSEUS_VERSION}\", features = \[ \"hydrate\" \] \}|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" ./Cargo.toml \ + && printf '%s\n' "perseus-size-opt = { path = \"/perseus-size-opt\", version = \"=${PERSEUS_SIZE_OPT_VERSION}\" }" >> ./Cargo.toml \ + && cat ./Cargo.toml \ + && curl -L# \ + https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ + | tar -C ./src -xz --strip-components=4 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple/src \ + && sed -i "\ s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ \1(\n\ \2\n\ @@ -91,43 +161,46 @@ RUN sed -i "\ codegen_units: 1,\n\ enable_fluent_bundle_patch: false,\n\ }\n\ - )|" ./src/lib.rs && cat ./src/lib.rs - -# Update dependencies to their precise, required versions. -RUN cargo update -p perseus --precise $PERSEUS_VERSION \ - && cargo update -p perseus-size-opt --precise $PERSEUS_SIZE_OPT_VERSION \ - && cargo update -p sycamore --precise $SYCAMORE_VERSION - -# Clean any pre-existing generated `./perseus` subdirectory from the project, -# then prepare the project. -RUN perseus clean \ - && perseus prep - -# Run plugin(s) to adjust the project prior to deployment. -RUN perseus tinker \ - && cat .perseus/Cargo.toml \ - && cat ./src/lib.rs - -# Patch `clippy` inner attribute syntax error in `lib.rs` (if found). -RUN sed -i "s|\(#\)!\(\[allow(clippy::unused_unit)\]\)|\1\2|;" ./.perseus/src/lib.rs - -# Single-threaded perseus CLI mode required for low memory environments. -# ENV PERSEUS_CLI_SEQUENTIAL=true - -# Export environment variables required by `wasm-bindgen` and deploy the app from the project. -RUN export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ - && perseus deploy - -# Run `esbuild` against `bundle.js` to optimize it into minified format. -RUN esbuild ./pkg/dist/pkg/perseus_engine.js \ + )|" ./src/lib.rs && cat ./src/lib.rs \ + && cargo update -p perseus --precise $PERSEUS_VERSION \ + && cargo update -p sycamore --precise $SYCAMORE_VERSION \ + && perseus clean \ + && perseus prep \ + && perseus tinker \ + && cat ./.perseus/Cargo.toml \ + && cat ./src/lib.rs \ + && printf '%s\n' \ + '#!/bin/sh' \ + 'parse_file () {' \ + ' local file_path=./.perseus/src/lib.rs' \ + ' local line_num=1' \ + ' while IFS= read -r lib_line' \ + ' do' \ + ' if [ ! -z $( echo ${lib_line} | cut -d " " -f 1 | grep -e "clippy" ) ]' \ + ' then' \ + ' break' \ + ' fi' \ + ' line_num=$(( $line_num + 1 ))' \ + ' done < $file_path' \ + ' if [ $line_num -ne 1 ]' \ + ' then' \ + ' awk -i inplace '"\\" \ + ' -v line_num=$line_num '"\\" \ + ' -v inner_attr=$( sed "${line_num}q;d" $file_path | cut -d " " -f 1 ) '"\\" \ + ' "NR==1 { print inner_attr } NR!=line_num { print }" $file_path' \ + ' fi' \ + '}' \ + 'parse_file' > ./parse_file.sh \ + && chmod +x ./parse_file.sh && . ./parse_file.sh && rm -f ./parse_file.sh \ + && export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig \ + && perseus deploy \ + && esbuild ./pkg/dist/pkg/perseus_engine.js \ --minify \ - --target=esnext \ + --target=${ESBUILD_TARGET} \ --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./pkg/dist/pkg - -# Run `wasm-opt` against `bundle.wasm` to optimize it based on bytesize. -RUN wasm-opt \ + && ls -lha ./pkg/dist/pkg \ + && wasm-opt \ -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ && ls -lha ./pkg/dist/pkg @@ -139,7 +212,7 @@ FROM debian:stable-slim WORKDIR /app # Copy the app into its chosen install path. -COPY --from=build /app/simple/pkg /app/ +COPY --from=builder /app/pkg /app/ # Bind the server to `localhost`. ENV HOST=0.0.0.0 From 7c87926e7cb22ecc9db231bf33b66bd7e9b8fea3 Mon Sep 17 00:00:00 2001 From: Allen Woods Date: Tue, 19 Jul 2022 02:57:21 -0700 Subject: [PATCH 37/37] docs: migrate docker deployment from cargo install to tarball of framework source over curl. --- .../0.3.4/en-US/reference/deploying/docker.md | 186 ++++++++++-------- 1 file changed, 107 insertions(+), 79 deletions(-) diff --git a/docs/0.3.4/en-US/reference/deploying/docker.md b/docs/0.3.4/en-US/reference/deploying/docker.md index e5311083df..63e1410590 100644 --- a/docs/0.3.4/en-US/reference/deploying/docker.md +++ b/docs/0.3.4/en-US/reference/deploying/docker.md @@ -54,15 +54,29 @@ RUN apt-get update \ && rustup default ${RUST_RELEASE_CHANNEL} \ && rustup target add wasm32-unknown-unknown -# Create a build stage for `perseus-cli` that we can run in parallel. -FROM base as perseus +# Create a build stage for `binaryen` we can run in parallel. +FROM base as binaryen -# Work from the chosen install path for `perseus-cli`. -WORKDIR /perseus +# Work from the chosen install path for `binaryen`. +WORKDIR /binaryen -# Install crate `perseus-cli` into the work path. -RUN cargo install perseus-cli --version $PERSEUS_VERSION \ - && mv /usr/local/cargo/bin/perseus . +# Download, extract, and remove compressed tar of `binaryen`. +RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ + https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ + && tar --strip-components=1 -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ + && rm -f binaryen-${BINARYEN_VERSION}.tar.gz + +# Create a build stage for `esbuild` we can run in parallel. +FROM base as esbuild + +# Work from the chosen install path for `esbuild`. +WORKDIR /esbuild + +# Download, extract, and remove compressed tar of `esbuild`. +RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ + https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ + && tar --strip-components=1 -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ + && rm -f esbuild-${ESBUILD_VERSION}.tar.gz # Create a build stage for `perseus-size-opt` that we can run in parallel. FROM base as perseus-size-opt @@ -74,7 +88,7 @@ WORKDIR /perseus-size-opt RUN curl -L# https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ | tar -xz --strip-components=1 \ && rm -rf ./examples \ - && sed -i "s|^\(perseus =\).*$|\1 \"=${PERSEUS_VERSION}\"|" ./Cargo.toml \ + && sed -i "s|^\(perseus =\).*$|\1 { path = \\\"/perseus/packages/perseus\\\" }|;" ./Cargo.toml \ && printf '%s\n' \ '#!/bin/sh' \ 'rm_workspace () {' \ @@ -95,94 +109,110 @@ WORKDIR /wasm-pack RUN cargo install wasm-pack --version $WASM_PACK_VERSION \ && mv /usr/local/cargo/bin/wasm-pack . -# Create a build stage for `binaryen` we can run in parallel. -FROM base as binaryen +# Create a build stage for the codebase of the `perseus` framework that we can run in parallel. +FROM base as framework -# Work from the chosen install path for `binaryen`. -WORKDIR /binaryen +# Work from the root of the codebase. +WORKDIR /perseus -# Download, extract, and remove compressed tar of `binaryen`. -RUN curl -L#o binaryen-${BINARYEN_VERSION}.tar.gz \ - https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz \ - && tar --strip-components=1 -xzf binaryen-${BINARYEN_VERSION}.tar.gz \ - && rm -f binaryen-${BINARYEN_VERSION}.tar.gz +# Download and make adjustments to the codebase of the framework. +RUN curl -L# https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ + | tar -xz --strip-components=1 \ + && sed -i "\ + s|\(println!.*\)$|// \1|; \ + s|\.\./\.\.examples/core/basic/\.perseus|/perseus/examples/core/basic/\.perseus|g; \ + s|\(fs::remove_dir_all(dest\.join(\"\.perseus/dist\"))\.unwrap();\)|// \1|; \ + s|PERSEUS_VERSION|path = \\\\\"/perseus/packages/perseus\\\\\"|g; \ + s|PERSEUS_ACTIX_WEB_VERSION|path = \\\\\"/perseus/packages/perseus-actix-web\\\\\"|g; \ + s|PERSEUS_WARP_VERSION|path = \\\\\"/perseus/packages/perseus-warp\\\\\"|g;" \ + ./packages/perseus-cli/build.rs \ + && sed -i "\ + s|^\(perseus = {\) \(.*\) \(}\)$|\1 \2, features = \[ \"hydrate\" \] \3|; \ + s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|; \ + " ./examples/comprehensive/tiny/Cargo.toml \ + && printf '%s\n' \ + 'perseus-size-opt = { path = "/perseus-size-opt" }' >> ./examples/comprehensive/tiny/Cargo.toml \ + && rm -f ./examples/comprehensive/tiny/src/lib.rs \ + && printf '%s\n' \ + 'use perseus::{ErrorPages, Html, PerseusApp, Plugins, Template};' \ + 'use sycamore::view;' \ + '' \ + 'use perseus_size_opt::{perseus_size_opt, SizeOpts};' \ + '' \ + '#[perseus::main]' \ + 'pub fn main() -> PerseusApp {' \ + ' PerseusApp::new()' \ + ' .template(|| {' \ + ' Template::new("index").template(|_| {' \ + ' view! {' \ + ' p { "Hello World!" }' \ + ' }' \ + ' })' \ + ' })' \ + ' .error_pages(|| ErrorPages::new(|url, status, err, _| {' \ + ' view! {' \ + " p { (format!(\"An error with HTTP code {} occurred at '{}': '{}'.\", status, url, err)) }" \ + ' }' \ + ' }))' \ + ' .plugins(' \ + ' Plugins::new()' \ + ' .plugin(' \ + ' perseus_size_opt,' \ + ' SizeOpts {' \ + ' wee_alloc: true,' \ + ' lto: true,' \ + ' opt_level: "s".to_string(),' \ + ' codegen_units: 1,' \ + ' enable_fluent_bundle_patch: false,' \ + ' }' \ + ' )' \ + ' )' \ + '}' > ./examples/comprehensive/tiny/src/lib.rs \ + && sed -i "s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|" \ + ./examples/core/basic/Cargo.toml \ + && sed -i "\ + s|^\(sycamore =\).*$|\1 { version = \\\"=${SYCAMORE_VERSION}\\\", features = [ \\\"ssr\\\" ] }|; + s|^\(sycamore-router =\).*$|\1 \\\"=${SYCAMORE_VERSION}\\\"|;" \ + ./examples/core/basic/.perseus/Cargo.toml -# Create a build stage for `esbuild` we can run in parallel. -FROM base as esbuild +# Create a build stage for `perseus-cli` that we can run in parallel. +FROM framework as perseus-cli -# Work from the chosen install path for `esbuild`. -WORKDIR /esbuild +# Copy perseus-size-opt to satisfy dependencies. +COPY --from=perseus-size-opt /perseus-size-opt/ /perseus-size-opt/ -# Download, extract, and remove compressed tar of `esbuild`. -RUN curl -L#o esbuild-${ESBUILD_VERSION}.tar.gz \ - https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-${ESBUILD_VERSION}.tgz \ - && tar --strip-components=1 -xzf esbuild-${ESBUILD_VERSION}.tar.gz \ - && rm -f esbuild-${ESBUILD_VERSION}.tar.gz +# Work from the root of the package. +WORKDIR /perseus/packages/perseus-cli + +# Compile the release profile of package `perseus-cli`. +RUN cargo build --bin perseus --release # Create a build stage for building our app. -FROM base as builder +FROM framework as builder # Copy the tools we previously prepared in parallel. -COPY --from=perseus /perseus/perseus /usr/bin/ -COPY --from=perseus-size-opt /perseus-size-opt /perseus-size-opt/ -COPY --from=wasm-pack /wasm-pack/wasm-pack /usr/bin/ COPY --from=binaryen /binaryen/bin/ /usr/bin/ COPY --from=binaryen /binaryen/include/ /usr/include/ COPY --from=binaryen /binaryen/lib/ /usr/lib/ COPY --from=esbuild /esbuild/bin/esbuild /usr/bin/ +COPY --from=perseus-cli /perseus/target/release/perseus /usr/bin/ +COPY --from=perseus-size-opt /perseus-size-opt/ /perseus-size-opt/ +COPY --from=wasm-pack /wasm-pack/wasm-pack /usr/bin/ -# Single-threaded perseus CLI mode required for low memory environments. -# ENV PERSEUS_CLI_SEQUENTIAL=true - -# Work from the root of the project. -WORKDIR /app +# Work from the root of our app. +WORKDIR /perseus/examples/comprehensive/tiny -# Build and deploy our app using the following commands. +# Execute all necessary commands for deploying our app. RUN . /etc/profile && . /usr/local/cargo/env \ - && curl -L# \ - https://codeload.github.com/arctic-hen7/perseus/tar.gz/v${PERSEUS_VERSION} \ - | tar -xz --strip-components=4 perseus-${PERSEUS_VERSION}/examples/comprehensive/tiny \ - && sed -i "\ - s|^\(perseus =\).*$|\1 \{ version = \"=${PERSEUS_VERSION}\", features = \[ \"hydrate\" \] \}|; \ - s|^\(sycamore =\).*$|\1 \"=${SYCAMORE_VERSION}\"|;" ./Cargo.toml \ - && printf '%s\n' "perseus-size-opt = { path = \"/perseus-size-opt\", version = \"=${PERSEUS_SIZE_OPT_VERSION}\" }" >> ./Cargo.toml \ - && cat ./Cargo.toml \ - && curl -L# \ - https://codeload.github.com/arctic-hen7/perseus-size-opt/tar.gz/v${PERSEUS_SIZE_OPT_VERSION} \ - | tar -C ./src -xz --strip-components=4 perseus-size-opt-${PERSEUS_SIZE_OPT_VERSION}/examples/simple/src \ - && sed -i "\ - s|\(\.plugin\)(\(perseus_size_opt,\) SizeOpts::default())$|\n\ - \1(\n\ - \2\n\ - SizeOpts {\n\ - wee_alloc: true,\n\ - lto: true,\n\ - opt_level: \"s\".to_string(),\n\ - codegen_units: 1,\n\ - enable_fluent_bundle_patch: false,\n\ - }\n\ - )|" ./src/lib.rs && cat ./src/lib.rs \ - && cargo update -p perseus --precise $PERSEUS_VERSION \ - && cargo update -p sycamore --precise $SYCAMORE_VERSION \ && perseus clean \ && perseus prep \ && perseus tinker \ - && cat ./.perseus/Cargo.toml \ - && cat ./src/lib.rs \ && printf '%s\n' \ '#!/bin/sh' \ 'parse_file () {' \ ' local file_path=./.perseus/src/lib.rs' \ - ' local line_num=1' \ - ' while IFS= read -r lib_line' \ - ' do' \ - ' if [ ! -z $( echo ${lib_line} | cut -d " " -f 1 | grep -e "clippy" ) ]' \ - ' then' \ - ' break' \ - ' fi' \ - ' line_num=$(( $line_num + 1 ))' \ - ' done < $file_path' \ - ' if [ $line_num -ne 1 ]' \ + ' local line_num=$( grep -ne "clippy" $file_path | grep -Eo "^[^:]+" )' \ + ' if [ ! -z "${line_num}" ] && [ $line_num -ne 1 ]' \ ' then' \ ' awk -i inplace '"\\" \ ' -v line_num=$line_num '"\\" \ @@ -199,11 +229,9 @@ RUN . /etc/profile && . /usr/local/cargo/env \ --target=${ESBUILD_TARGET} \ --outfile=./pkg/dist/pkg/perseus_engine.js \ --allow-overwrite \ - && ls -lha ./pkg/dist/pkg \ && wasm-opt \ -Os ./pkg/dist/pkg/perseus_engine_bg.wasm \ - -o ./pkg/dist/pkg/perseus_engine_bg.wasm \ - && ls -lha ./pkg/dist/pkg + -o ./pkg/dist/pkg/perseus_engine_bg.wasm # Prepare the final image where the app will be deployed. FROM debian:stable-slim @@ -212,13 +240,13 @@ FROM debian:stable-slim WORKDIR /app # Copy the app into its chosen install path. -COPY --from=builder /app/pkg /app/ +COPY --from=builder /perseus/examples/comprehensive/tiny/pkg /app/ # Bind the server to `localhost`. -ENV HOST=0.0.0.0 +ENV PERSEUS_HOST=0.0.0.0 # Bind the container to the default port of 8080. -ENV PORT=8080 +ENV PERSEUS_PORT=8080 # Configure the container to automatically serve the deployed app while running. CMD ["./server"]