Closed phaleth closed 3 years ago
I don't think that's the issue behind this, because applying custom size optimizations does result in the correct ones being applied in .perseus/Cargo.toml
(on my machine at least). It does look like you're running perseus tinker
before configuring the plugin though. To clarify, perseus tinker
doesn't activate plugins, it runs tinker-timer plugins (like this one). So you'll need to run it after you've altered lib.rs
.
Ok, great. I totally didn't get the clue that perseus tinker
should indeed modify .perseus/Cargo.toml
. Bellow is the fixed Dockerfile
and the log from VPS.
Actually, now that I think of the whole process. It'd be nice if perseus prep
would always had to be called before perseus tinker
or rather that the .perseus/
dir is somehow created first before perseus tinker
call, otherwise perseus tinker
could throw an error saying that the .perseus/
dir is missing, but that decision is up to you @arctic-hen7.
I'll close this one and try to reopen the other issue #1 and add more related info there.
Oh btw, I like when the developer says "on my machine at least", that's so funny. From my own experience the developer always has to sit on the devOps guy's lap. Anyways, I should have thought twice. Sorry about opening this issue.
Dockerfile
# get the base image
FROM rust:1.55-slim AS build
# install build dependencies
RUN apt update \
&& apt install -y --no-install-recommends lsb-release apt-transport-https \
build-essential curl
# prepare root project dir
WORKDIR /app
# download the target for wasm
RUN rustup target add wasm32-unknown-unknown
# install wasm-pack
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
# go to src dir
WORKDIR /app/simple
# install perseus-cli
RUN cargo install perseus-cli --version 0.3.0-beta.13
# clean app
RUN perseus clean
# specify deps in app config
RUN sed -i s'/perseus = .*/perseus = "0.3.0-beta.13"/' ./Cargo.toml \
&& sed -i s'/perseus-size-opt = .*/perseus-size-opt = "0.1.0"/' ./Cargo.toml \
&& cat ./Cargo.toml
# modify lib.rs
RUN sed -i s'/SizeOpts::default()/SizeOpts { wee_alloc: true, lto: false, opt_level: "s".to_string(), codegen_units: 1, }/' ./src/lib.rs \
&& sed -i s'/"Hello World!"/"世界您好 !"/' ./src/lib.rs \
&& cat ./src/lib.rs
# run plugin(s) to adjust app
RUN perseus tinker \
&& cat .perseus/Cargo.toml \
&& cat ./src/lib.rs
# deploy app
RUN perseus deploy
# prepare deployment image
FROM bitnami/minideb:buster
WORKDIR /app
COPY --from=build /app/simple/pkg /app/
ENV PERSEUS_STANDALONE=true
ENV HOST=0.0.0.0
CMD ["./server"]
Docker image build
...
Step 10/19 : RUN sed -i s'/perseus = .*/perseus = "0.3.0-beta.13"/' ./Cargo.toml && sed -i s'/perseus-size-opt = .*/perseus-size-opt = "0.1.0"/' ./Cargo.toml && cat ./Cargo.toml
---> Running in 313267457c82
[package]
name = "perseus-size-opt-example-simple"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
perseus = "0.3.0-beta.13"
sycamore = "0.6"
perseus-size-opt = "0.1.0"Removing intermediate container 313267457c82
---> 153e640b464a
Step 11/19 : RUN sed -i s'/SizeOpts::default()/SizeOpts { wee_alloc: true, lto: false, opt_level: "s".to_string(), codegen_units: 1, }/' ./src/lib.rs && sed -i s'/"Hello World!"/"世界您好 !"/' ./src/lib.rs && cat ./src/lib.rs
---> Running in 60726b48dec2
use perseus::{define_app, plugins::Plugins, ErrorPages, Template};
use perseus_size_opt::{perseus_size_opt, SizeOpts};
use sycamore::template;
define_app! {
templates: [
Template::<G>::new("index").template(|_| {
template! {
p { "世界您好 !" }
}
})
],
error_pages: ErrorPages::new(|url, status, err, _| {
template! {
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
}
}),
plugins: Plugins::new().plugin(perseus_size_opt(), SizeOpts { wee_alloc: true, lto: false, opt_level: "s".to_string(), codegen_units: 1, })
}
Removing intermediate container 60726b48dec2
---> 999599cd539c
Step 12/19 : RUN perseus tinker && cat .perseus/Cargo.toml && cat ./src/lib.rs
---> Running in 095c4ce2dda9
[package]
name = "perseus-engine"
edition = "2018"
version = "0.3.0-beta.13"
authors = []
keywords = []
categories = []
default-run = "perseus-builder"
autobins = true
autoexamples = true
autotests = true
autobenches = true
publish = true
[workspace]
members = ["server"]
[dependencies]
console_error_panic_hook = "0.1.6"
fs_extra = "1"
futures = "0.3"
lazy_static = "1"
perseus = "0.3.0-beta.13"
serde_json = "1"
sycamore-router = "0.6"
urlencoding = "2.1"
wasm-bindgen-futures = "0.4"
wee_alloc = "0.4"
[dependencies.app]
path = "../"
features = []
optional = false
package = "perseus-size-opt-example-simple"
[dependencies.serde]
version = "1"
features = ["derive"]
optional = false
[dependencies.sycamore]
version = "0.6"
features = ["ssr"]
optional = false
[dependencies.wasm-bindgen]
version = "0.2"
features = ["serde-serialize"]
optional = false
[dependencies.web-sys]
version = "0.3"
features = ["Event", "Headers", "Request", "RequestInit", "RequestMode", "Response", "ReadableStream", "Window"]
optional = false
[lib]
path = "src/lib.rs"
name = "perseus_engine"
test = true
doctest = true
bench = true
doc = true
plugin = false
proc-macro = false
harness = true
edition = "2018"
crate-type = ["cdylib", "rlib"]
required-features = []
[profile.release]
opt-level = "s"
lto = false
codegen-units = 1
[profile.release.package]
[[bin]]
path = "src/bin/build.rs"
name = "perseus-builder"
test = true
doctest = true
bench = true
doc = true
plugin = false
proc-macro = false
harness = true
required-features = []
[[bin]]
path = "src/bin/export.rs"
name = "perseus-exporter"
test = true
doctest = true
bench = true
doc = true
plugin = false
proc-macro = false
harness = true
required-features = []
[[bin]]
path = "src/bin/tinker.rs"
name = "perseus-tinker"
test = true
doctest = true
bench = true
doc = true
plugin = false
proc-macro = false
harness = true
required-features = []
use perseus::{define_app, plugins::Plugins, ErrorPages, Template};
use perseus_size_opt::{perseus_size_opt, SizeOpts};
use sycamore::template;
define_app! {
templates: [
Template::<G>::new("index").template(|_| {
template! {
p { "世界您好 !" }
}
})
],
error_pages: ErrorPages::new(|url, status, err, _| {
template! {
p { (format!("An error with HTTP code {} occurred at '{}': '{}'.", status, url, err)) }
}
}),
plugins: Plugins::new().plugin(perseus_size_opt(), SizeOpts { wee_alloc: true, lto: false, opt_level: "s".to_string(), codegen_units: 1, })
}
Removing intermediate container 095c4ce2dda9
---> 3c887b091984
Step 13/19 : RUN perseus deploy
---> Running in bc462c7b5070
Not running server because `--no-run` was provided. You can run it manually by running the following executable in `.perseus/server/`.
/app/simple/.perseus/target/release/perseus-cli-server
Deployment complete 🚀! Your app is now available for serving in the standalone folder 'pkg'! You can run it by executing the `server` binary in that folder with the `PERSEUS_STANDALONE` environment variable set to `true`.
Removing intermediate container bc462c7b5070
---> 483324e4811e
Step 14/19 : FROM bitnami/minideb:buster
---> 6ce7b3755a74
Step 15/19 : WORKDIR /app
---> Running in a12da1c21c8b
Removing intermediate container a12da1c21c8b
---> cc28adcfe317
Step 16/19 : COPY --from=build /app/simple/pkg /app/
---> 54f0082a4e79
Step 17/19 : ENV PERSEUS_STANDALONE=true
---> Running in 8ff5f3dfafa9
Removing intermediate container 8ff5f3dfafa9
---> bcf054b2f66d
Step 18/19 : ENV HOST=0.0.0.0
---> Running in 97cda72caadb
Removing intermediate container 97cda72caadb
---> 9701c3e7d512
Step 19/19 : CMD ["./server"]
---> Running in 706243c33eb7
Removing intermediate container 706243c33eb7
---> 630c8ea46299
Successfully built 630c8ea46299
Successfully tagged ...
No problem, if there's something I can make clearer in the docs, please let me know!
What's your reasoning for wanting perseus prep
to be required before perseus tinker
? I'm not sure I fully understand that yet...
It's alright, btw I'm a PLM dev by trade, so I could write really long and boring articles about this... I guess I could never provide a clear answer.
Anyway, I don't know if perseus prep
should be called before perseus tinker
during deployment, but I think that alone and even more should be something to consider. Just ask yourself what command names fit here. I think tinker
is not a very descriptive name for what could be considered as a lifecycle phase or a deployment stage of a deployment process. Often names like preprocessing
, processing
and postprocessing
are used whenever phases need to have like the most generic names. All I can say is that tinker
isn't really saying anything at all and could fit to all of those three generic stages, but only in case tinker
was a good name for lifecycle phase, which it isn't.
Maybe perseus deploy
also creates the .perseus/
dir if there isn't any. I'm not sure, but really should it be that way? The main reason processes such as a deployment process are split into phases is because of validation. Should there be any validation so those who deploy a Perseus project or any project are less likely to mess up the deployment? The answer is: Sure, if it's a multi step process.
Btw, should the source code be modified by hand before deployment? The answer is: Hell no! Really.... I'm aware wee_alloc
imposes such requirement. Maybe that's the root problem or maybe one day perseus tinker
will be by default setup such that it can run a sophisticated parser & source code modifier and so take care of all src\lib.rs
modifications reliably by itself, because say a Dockerfile
itself will never be this sophisticated. I mean how do you always reliably turn this https://github.com/arctic-hen7/perseus/blob/main/examples/tiny/src/lib.rs into this https://github.com/arctic-hen7/perseus-size-opt/blob/main/examples/simple/src/lib.rs considering there could be anything in that lib.rs
file and also the fact that the developer won't be bothered by adding all of the optimization plugin related code in particular. wee_alloc
only requires that file to be prepended, which is not such a seemingly impossible requirement.
Is perseus tinker
meant to do all the preprocessing
in the future? Then why not do it all with perseus prep
? Maybe cause perseus prep
is already taken by something that could be called perseus init
as it has more to do with development rather than deployment? I have no clear answer other than tinker
was indeed confusing for me.
Okay, yeah I can definitely understand that. perseus prep
was originally just intended for developing thr CLI itself, and I thought it'd be useful to add it in, but I can see now that it's actually quite confusing. I think I'll do a redesign of the CLI steps to make them more logical, and I'll go through the docs and try to make things clearer!
The
SizeOpts::default()
is always applied, no matter how is theSizeOpts
struct provided. This leads to an issue with low memory on a VPS becauselto
cannot be set tofalse
using this plugin.Bellow is a standalone
Dockerfile
that causes the out of memory problem on a VPS during compilation at theperseus deploy
and the log of the last two steps.Dockerfile
Docker image build