Skip to content

Commit 8f22f71

Browse files
fix: update spin deploy to patch channel rather then recreate channels
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
1 parent ee996c1 commit 8f22f71

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

src/commands/deploy.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -164,56 +164,60 @@ impl DeployCommand {
164164
});
165165

166166
let name = bindle_id.name().to_string();
167-
// Values for channel creation are determined by whether the app already exists
168-
let mut active_revision_id = None;
169-
let mut range_rule = None;
170-
let mut revision_selection_strategy = ChannelRevisionSelectionStrategy::UseRangeRule;
171167

172168
// Create or update app
173-
let app_id = match self.get_app_id(&hippo_client, name.clone()).await {
174-
Ok(app_id) => {
169+
// TODO: this process involves many calls to Hippo. Should be able to update the channel
170+
// via only `add_revision` if bindle naming schema is updated so bindles can be deterministically ordered by Hippo.
171+
let channel_id = match self.get_app_id(&hippo_client, name.clone()).await {
172+
Ok(_) => {
175173
Client::add_revision(
176174
&hippo_client,
177175
name.clone(),
178176
bindle_id.version_string().clone(),
179177
)
180178
.await?;
181-
182-
// Remove existing channel to prevent conflict
183-
// TODO: in the future, expand hippo API to update channel rather than delete and recreate
184179
let existing_channel_id = self
185180
.get_channel_id(&hippo_client, SPIN_DEPLOY_CHANNEL_NAME.to_string())
186181
.await?;
187-
Client::remove_channel(&hippo_client, existing_channel_id.to_string()).await?;
188-
active_revision_id = Some(
189-
self.get_revision_id(&hippo_client, bindle_id.version_string().clone())
190-
.await?,
191-
);
192-
revision_selection_strategy =
193-
ChannelRevisionSelectionStrategy::UseSpecifiedRevision;
194-
app_id
182+
let active_revision_id = self
183+
.get_revision_id(&hippo_client, bindle_id.version_string().clone())
184+
.await?;
185+
Client::patch_channel(
186+
&hippo_client,
187+
existing_channel_id,
188+
None,
189+
None,
190+
Some(ChannelRevisionSelectionStrategy::UseSpecifiedRevision),
191+
None,
192+
Some(active_revision_id),
193+
None,
194+
None,
195+
)
196+
.await
197+
.context("Problem patching a channel in Hippo")?;
198+
199+
existing_channel_id
195200
}
196201
Err(_) => {
197-
range_rule = Some(bindle_id.version_string());
198-
Client::add_app(&hippo_client, name.clone(), name.clone())
202+
let range_rule = Some(bindle_id.version_string());
203+
let app_id = Client::add_app(&hippo_client, name.clone(), name.clone())
199204
.await
200-
.context("Unable to create Hippo app")?
205+
.context("Unable to create Hippo app")?;
206+
Client::add_channel(
207+
&hippo_client,
208+
app_id,
209+
String::from(SPIN_DEPLOY_CHANNEL_NAME),
210+
None,
211+
ChannelRevisionSelectionStrategy::UseRangeRule,
212+
range_rule,
213+
None,
214+
None,
215+
)
216+
.await
217+
.context("Problem creating a channel in Hippo")?
201218
}
202219
};
203220

204-
let channel_id = Client::add_channel(
205-
&hippo_client,
206-
app_id,
207-
String::from(SPIN_DEPLOY_CHANNEL_NAME),
208-
None,
209-
revision_selection_strategy,
210-
range_rule,
211-
active_revision_id,
212-
None,
213-
)
214-
.await
215-
.context("Problem creating a channel in Hippo")?;
216-
217221
println!(
218222
"Deployed {} version {}",
219223
name.clone(),

0 commit comments

Comments
 (0)