Skip to content

spin new -E: update unversioned environments if not recent#3523

Open
itowlson wants to merge 1 commit into
spinframework:mainfrom
itowlson:envs-unversioned-jit-update
Open

spin new -E: update unversioned environments if not recent#3523
itowlson wants to merge 1 commit into
spinframework:mainfrom
itowlson:envs-unversioned-jit-update

Conversation

@itowlson
Copy link
Copy Markdown
Collaborator

The spin new -E feature assumed that environments were immutable - that a new environment could get a new version. This is true for self-host platforms such as the CLI and SpinKube. However, for hosted environments it leads to a weird UI. Let us return to Bob's Discount Cloud, the premier bargain-basement Spin host. At any give time, BDC supports a specific environment. But the current thing requires users to pick a version. At first Bob tells them to write spin new -E bdc@1, which is a bit weird but uh okay; but then later Bob must raze all those docs from the Internet and get them to write spin new -E bdc@2, instead. Really Bob wants users to be able to write spin up -E bdc and get whatever is current in his Discount Cloud.

We could tackle this by forcing an update of the environments repo on every get. However, this introduces a delay. If you're on airplane wifi, that could be quite a loooooooooong delay.

This PR proposes to track the recency of the catalogue snapshot, and to update it only if 1. the env being referenced is unversioned; and 2. the snapshot is older than 1 hour. In addition, such updates will be timed out after 2 seconds to avoid slow networks making them painful.

This hopefully minimises user annoyance; and hopefully Bob's updates will not usually be time-sensitive to the hour (if they are, Bob will have to ask users to purge their envs cache, or to spin new -E some-fake-env to force a fetch: we can look at adding commands for this if need be).

(And... I realised while working on this that spin new currently always does a git fetch anyway, to force-install templates from the referenced repo. So maybe this was a pointless optimisation. But I'd like to fix that soon, so I'm not going to bother backing it out...)

Tested by pointing a build at a fork of the environments repo, dialling the recency timeout down to a few minutes, and logging when pulls did and didn't happen (as well as verifying that changes were reflected in the spin new UI).

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
Copy link
Copy Markdown
Contributor

@kate-goldenring kate-goldenring left a comment

Choose a reason for hiding this comment

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

just the unwrap handling and then LGTM

}
}

fn is_unversioned(id: &str) -> bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should update the readme of spin-environments to specify that versioning is not needed.

let git_source = GitSource::new(&url, None, &self.git_root);
if self.git_root.exists() {
git_source.pull().await
git_source.pull().await.unwrap();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we unwrapping here? This could panic on a network error

Suggested change
git_source.pull().await.unwrap();
git_source.pull().await?;

}

/// Updates if we have not updated recently, ignoring
/// failures. The scenario here is unverioned environments,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
/// failures. The scenario here is unverioned environments,
/// failures. The scenario here is unversioned environments,

}
}

fn last_update_file(&self) -> Result<PathBuf, ()> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would -> Option<PathBuf> be more idiomatic here?

Copy link
Copy Markdown
Collaborator

@fibonacci1729 fibonacci1729 left a comment

Choose a reason for hiding this comment

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

LGTM pending Kate's unwrap() and typos.

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