-
Notifications
You must be signed in to change notification settings - Fork 300
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
Conversation
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 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
, notdev
.
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()) |
There was a problem hiding this comment.
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.
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(), |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
.
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))?; |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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.
category_en, | ||
governance, | ||
team, | ||
production, | ||
get_production, |
There was a problem hiding this comment.
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("/"); |
There was a problem hiding this comment.
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")~}} |
There was a problem hiding this comment.
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 accessparent
field of the context object, use{{lookup this "parent"}}
instead. This change applies to partial inclusion, too.
There was a problem hiding this 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 oops... can you check the logs? |
@pietroalbini I no longer have access to the website/staging heroku, can you check? |
|
@Manishearth granted back access to Heroku! |
Hmm. As far as I can tell, the handling of the The dockerfile specifies
but Heroku's Procfile overrides that...? (I have no experience with Heroku)
Not sure which is correct. Either way, I'm confused as to how that was impacted by the rocket migration. |
I don't think Heroku looks at the dockerfile at all, yeah, that's just there for local dev and CI. I think? |
I'm trying 9eeae68, seems like heroku wants it to bind to 0.0.0.0 |
http://www-staging.rust-lang.org/ seems like that worked! |
We should update the Rocket.toml with that instead of using an env var but I'll do that later |
Also we should definitely click around the website and ensure basically all of it works before deploying to prod. |
One thing from the logs:
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. |
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. |
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! |
No description provided.