Skip to content

migrate to rocket 0.5.0-rc.3 #1795

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

Merged
merged 2 commits into from
Apr 7, 2023
Merged

migrate to rocket 0.5.0-rc.3 #1795

merged 2 commits into from
Apr 7, 2023

Conversation

senekor
Copy link
Contributor

@senekor senekor commented Apr 7, 2023

No description provided.

@senekor senekor requested a review from a team as a code owner April 7, 2023 15:16
@Manishearth
Copy link
Member

Dockerfile needs fixing for rust-toolchain it seems

@@ -51,7 +51,7 @@ COPY static /app/static/
COPY src/styles /app/src/styles/

ENV ROCKET_PORT 80
ENV ROCKET_ENV prod
ENV ROCKET_PROFILE release
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the changelog:

ROCKET_ENV is now ROCKET_PROFILE. A warning is emitted a launch time if the former is set.

@@ -1,3 +1,3 @@
[development]
[debug]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the changelog:

The default profile for debug builds is now debug, not dev.

Comment on lines +25 to +33
task::spawn_blocking(move || {
update_cache::<T>(generator)
// stringify the error to make it Send
.map_err(|e| e.to_string())
})
.await
.map_err(Box::new)?
// put the previously stringified error back in a box
.map_err(|e| e.as_str().into())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to make the caching more idiomatic for async, but that got very hairy very quickly... after many wasted hours, I gave up. Blocking in the foreground on a request should still only happen once for each cache entry when it's empty the first time.

Comment on lines +12 to +20
impl CachedNamedFile {
pub fn max_age(file: NamedFile, max_age: u32) -> Self {
Self {
file,
header: Header {
name: Uncased {
string: "CacheControl".into(),
},
value: format!("max-age={max_age}").into(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CacheDirective was removed from Rocket. (A breaking change not found in the changelog 😞 ) Since this module isn't really used as generically as it was designed, I implemented a simpler, more manual version which is sufficient for how it's used.

I haven't tested it though, I might need to make sure this header actually works as intended.

use rocket::request::FromParam;

fn is_category(name: &str) -> bool {
let mut path = PathBuf::from("templates");
path.push(name);
path.push("index.hbs");
path.push("index.html.hbs");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rocket_dyn_templates (previously part of rocket_contrib) sets content type based on the second file extension. So I renamed all the templates, otherwise the html would be sent as text/plain.

Comment on lines 140 to +142
let team = rcx
.evaluate_in_block_context(name)?
.ok_or_else(|| RenderError::new(format!("Cannot find team {}", name)))?;
.evaluate(context, name)
.map_err(|e| RenderError::from_error(&format!("Cannot find team {}", name), e))?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is basically guesswork on my part. I have zero experience with handlebars, so these helper idioms are unknown to me. evaluate_in_block_context doesn't exist anymore. I found no hints about this in the changelog of handlebars and evaluate isn't even documented in the current version 😞 .

I'm guessing these teams are related to the governance pages though, and they seem to work fine (after some debugging).

render_category(category, ENGLISH.into())
}

#[get("/<locale>/<category>", rank = 11)]
#[get("/<locale>/<category>", rank = 9)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Route ranking has received breaking changes. I had to fiddle with a few of the rankings to get some pages to render (category_locale and governance_locale I think).

Maybe I'm biased because dealing with these breaking changes was my first experience dealing with the routes of this site, but relying on framework magic for routing seems like a really bad idea. This site doesn't have an egregious amount of different routes, it seems so much saner to me to just declare the routes explicitly.

I seems like Rocket's system was even abused for optional path segments, namely the locale. Something like that clearly belongs in the query params, no?

Maintaining this URL structure into the future is probably going to be really annoying, especially for static site generation.

Comment on lines +471 to +474
category_en,
governance,
team,
production,
get_production,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rocket's macros for the handler definitions seem to work differently now, they introduce modules into the scope that produce naming conflicts...

pub(crate) fn maybe_redirect(segments: Segments<'_>) -> Option<Redirect> {
let path = segments.into_path_buf(false).ok()?.to_str()?.to_string();
pub(crate) fn maybe_redirect(path: Path) -> Option<Redirect> {
let path = path.segments().collect::<Vec<_>>().join("/");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I've tested this .join("/") yet.

@@ -14,4 +14,4 @@
</header>

{{/inline}}
{{~> (parent)~}}
{{~> (lookup this "parent")~}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the handlebars changelog:

[Fixed] Breaking zero-arity subexpressions support [#433] Zero-arity subexpression no longer resolved as variable. The behaviour is now aligned with handlebarsjs. For instance, {{(parent)}} can no longer access parent field of the context object, use {{lookup this "parent"}} instead. This change applies to partial inclusion, too.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any issues with this.

Should get autodeployed to https://www-staging.rust-lang.org/ around 10 minutes after merging, we should play with that before we deploy properly

@Manishearth Manishearth merged commit edfc5a9 into rust-lang:master Apr 7, 2023
@senekor
Copy link
Contributor Author

senekor commented Apr 8, 2023

image

@Manishearth oops... can you check the logs?

@senekor senekor deleted the rocket-0.5 branch April 8, 2023 06:38
@Manishearth
Copy link
Member

@pietroalbini I no longer have access to the website/staging heroku, can you check?

@pietroalbini
Copy link
Member

2023-04-10T06:13:15.709150+00:00 app[web.1]: Rocket has launched from http://127.0.0.1:28788
2023-04-10T06:14:14.399538+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2023-04-10T06:14:14.427200+00:00 heroku[web.1]: Stopping process with SIGKILL
2023-04-10T06:14:14.601628+00:00 heroku[web.1]: Process exited with status 137
2023-04-10T06:14:14.632825+00:00 heroku[web.1]: State changed from starting to crashed

@pietroalbini
Copy link
Member

@Manishearth granted back access to Heroku!

@senekor
Copy link
Contributor Author

senekor commented Apr 10, 2023

Hmm. As far as I can tell, the handling of the ROCKET_PORT environment variable did not change. Nothing about it in the changelog, upgrade guide or configuration docs.

The dockerfile specifies

ENV ROCKET_PORT 80

but Heroku's Procfile overrides that...? (I have no experience with Heroku)

web: ROCKET_PORT=$PORT ROCKET_PROFILE=release ./target/release/www-rust-lang-org

Not sure which is correct. Either way, I'm confused as to how that was impacted by the rocket migration.

@Manishearth
Copy link
Member

I don't think Heroku looks at the dockerfile at all, yeah, that's just there for local dev and CI. I think?

@Manishearth
Copy link
Member

I'm trying 9eeae68, seems like heroku wants it to bind to 0.0.0.0

@Manishearth
Copy link
Member

http://www-staging.rust-lang.org/ seems like that worked!

@Manishearth
Copy link
Member

We should update the Rocket.toml with that instead of using an env var but I'll do that later

@Manishearth
Copy link
Member

Also we should definitely click around the website and ensure basically all of it works before deploying to prod.

@Manishearth
Copy link
Member

One thing from the logs:

2023-04-10T17:50:22.913479+00:00 app[web.1]:    >> Parameter guard `category: Category` is forwarding: "No category called <zh-TW>".

2023-04-10T17:50:23.046223+00:00 heroku[router]: at=info method=GET path="/static/styles/vendor_10880690442070639967.css" host=www-staging.rust-lang.org request_id=d7ad0c83-cb43-414f-81f6-33e4bafd572f fwd="24.7.113.20" dyno=web.1 connect=0ms service=1ms status=200 bytes=73930 protocol=http

This might be an expected warning since we have a cascade of forwards.

@senekor
Copy link
Contributor Author

senekor commented Apr 10, 2023

One thing from the logs:

2023-04-10T17:50:22.913479+00:00 app[web.1]:    >> Parameter guard `category: Category` is forwarding: "No category called <zh-TW>".

2023-04-10T17:50:23.046223+00:00 heroku[router]: at=info method=GET path="/static/styles/vendor_10880690442070639967.css" host=www-staging.rust-lang.org request_id=d7ad0c83-cb43-414f-81f6-33e4bafd572f fwd="24.7.113.20" dyno=web.1 connect=0ms service=1ms status=200 bytes=73930 protocol=http

This might be an expected warning since we have a cascade of forwards.

I think so, yes. Clicking through the website with the zh-TW locale, I can't find any route that's broken.

@senekor
Copy link
Contributor Author

senekor commented Apr 10, 2023

I clicked around, making sure I'm hitting every route at least once. Everything seems fine, so the route ranking should be working at least.

@Manishearth Manishearth mentioned this pull request Apr 11, 2023
@Manishearth
Copy link
Member

Hit the deploy button, will take a while for Heroku to actually pick it up and deploy it. I'll keep an eye out in the meantime.

Thanks for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants