Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile refactor #153

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5f5a9ac
docs: clean up apt commands
allen-woods Jun 18, 2022
b4fb80b
docs: add follow redirects to curl commands
allen-woods Jun 18, 2022
6743ad9
docs: replace wget command, add short output filenames
allen-woods Jun 18, 2022
a62eed6
docs: prettify long or multiline commands
allen-woods Jun 18, 2022
7b08fb5
docs: replace echo commands, improve sed commands
allen-woods Jun 18, 2022
7f91c86
docs: improve esbuild and binaryen comments
allen-woods Jun 18, 2022
9426358
docs: fixed 0.3.0-0.3.3 version number out of range
allen-woods Jun 18, 2022
82f612e
docs: fix 0.3.4 dockerfiles
allen-woods Jun 18, 2022
2bf80ab
docs: fix 0.4.x/next dockerfiles
allen-woods Jun 18, 2022
0207ea8
docs: fix missing leading dash for options in call to tar
allen-woods Jun 19, 2022
e864f10
docs: fix current beta dockerfile
allen-woods Jun 19, 2022
73eb14c
docs: fix perseus-size-opt builds
allen-woods Jun 19, 2022
16135fa
docs: fix wee_alloc builds, pending error_page patch
allen-woods Jun 19, 2022
8987624
docs: fix examples path in bonnie build of 0.3.3 and 0.3.5
allen-woods Jun 19, 2022
22d7467
docs: remove mention of metadata
allen-woods Jun 19, 2022
f3e3f82
docs: add prep and tinker bonnie subcommands
allen-woods Jun 20, 2022
589033f
docs: fix failed build using cargo update --precise
allen-woods Jun 21, 2022
b97f7a2
docs: prettify curl output as progress bar
allen-woods Jun 21, 2022
224881b
docs: prevent failed build using cargo update --precise
allen-woods Jun 21, 2022
93fce8d
docs: prevent failed build using cargo update --precise
allen-woods Jun 21, 2022
d46af06
docs: prevent failed build using cargo update --precise
allen-woods Jun 21, 2022
b171f47
docs: refactor of all dockerfile examples for v0.3.0-0.3.3
allen-woods Jun 24, 2022
d9b6a82
docs: refactor of all dockerfile examples for v0.3.4
allen-woods Jun 24, 2022
75470a4
docs: refactor of all dockerfile examples for v0.4.x
allen-woods Jun 24, 2022
be0ed82
docs: refactor of all dockerfile examples for next
allen-woods Jun 24, 2022
a55ab23
docs: remove apt cli warnings via apt-get, add cargo install via git,…
allen-woods Jul 3, 2022
8772187
docs: refactor env vars and workdir to top of file.
allen-woods Jul 3, 2022
4109738
docs: merge run commands to reduce artifacts.
allen-woods Jul 3, 2022
015ae33
docs: rename base image from build to base.
allen-woods Jul 3, 2022
b61ab80
docs: refactored dockerfile into multi-stage build.
allen-woods Jul 3, 2022
a3b703d
docs: add conditional parsing of lib.rs using subshell.
allen-woods Jul 3, 2022
5e0b134
docs: fix curly brace expected, missing file_path argument to sed.
allen-woods Jul 3, 2022
cc310b7
docs: fix small syntax errors.
allen-woods Jul 4, 2022
e09257f
docs: restore es6/es2015 as target for esbuild.
allen-woods Jul 4, 2022
1d178cb
docs: migrate from simple to tiny, build perseus-size-opt from source.
allen-woods Jul 11, 2022
158de7c
docs: refactor tiny example to match 0.3.4.
allen-woods Jul 11, 2022
7c87926
docs: migrate docker deployment from cargo install to tarball of fram…
allen-woods Jul 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 83 additions & 45 deletions docs/0.3.0-0.3.3/en-US/deploying/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand All @@ -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 \
Expand All @@ -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
Expand All @@ -109,11 +132,14 @@ 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 \
ENV PERSEUS_VERSION=0.3.3 \
WEE_ALLOC_VERSION=0.4 \
ESBUILD_VERSION=0.14.7 \
BINARYEN_VERSION=104
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}
Expand Down
Loading