You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fast-insiders/client/Dockerfile

80 lines
2.5 KiB

# get the base image
FROM rust:1.69 AS build
# install build dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends lsb-release apt-transport-https \
build-essential curl wget pkg-config
# vars
ENV PERSEUS_VERSION=0.4.0 \
PERSEUS_SIZE_OPT_VERSION=0.1.9 \
ESBUILD_VERSION=0.15.18 \
BINARYEN_VERSION=112
# prepare root project dir
WORKDIR /app
# download the target for wasm
RUN rustup target add wasm32-unknown-unknown;\
cargo install wasm-pack # might not be a bad idea to fix the version of this in the future
# retrieve the src dir
COPY . .
# RUN curl https://git.albv.org/alban/fast-insiders/archive/master.tar.gz | tar -xz
# go to src dir
# WORKDIR /app/client
# install perseus-cli
RUN cargo install perseus-cli --version $PERSEUS_VERSION;\
perseus clean
# 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
#
# # modify main.rs
# RUN sed -i s'/SizeOpts::default()/SizeOpts { wee_alloc: true, lto: true, opt_level: "z".to_string(), codegen_units: 1, enable_fluent_bundle_patch: false, }/' ./src/main.rs \
# && cat ./src/main.rs
# # run plugin(s) to adjust app
# RUN perseus tinker
# single-threaded perseus CLI mode required for low memory environments
#ENV PERSEUS_CLI_SEQUENTIAL=true
# deploy app
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 \
&& ./package/bin/esbuild --version
# run esbuild against bundle.js
RUN ./package/bin/esbuild ./pkg/dist/pkg/perseus_engine.js --minify --target=es6 --outfile=./pkg/dist/pkg/perseus_engine.js --allow-overwrite \
&& ls -lha ./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 \
&& ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt --version
# run wasm-opt against bundle.wasm
RUN ./binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt -Os ./pkg/dist/pkg/perseus_engine_bg.wasm -o ./pkg/dist/pkg/perseus_engine_bg.wasm
# prepare deployment image
FROM debian:stable-slim
WORKDIR /app
COPY --from=build /app/pkg /app/
ENV HOST=0.0.0.0
CMD ["./server"]