Skip to content

Commit e13588b

Browse files
committed
refactor(wit): Create the app in app-init
1 parent da7d7f0 commit e13588b

3 files changed

Lines changed: 28 additions & 35 deletions

File tree

workflow/deployer-workflow/impl-flyio/src/lib.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,25 @@ fn cleanup(app_name: &str, modify_error: Option<AppInitModifyError>) -> AppInitE
185185
}
186186
}
187187

188+
fn app_create(org_slug: &str, app_name: &str) -> Result<(), AppInitError> {
189+
// Create the app
190+
// If the app already exists, fail with AppNameConflict
191+
if activity_fly_http::apps::get(app_name)
192+
.map_err(AppInitError::AppCreateError)?
193+
.is_some()
194+
{
195+
return Err(AppInitError::AppNameConflict);
196+
}
197+
// Create the app
198+
activity_fly_http::apps::put(org_slug, app_name).map_err(AppInitError::AppCreateError)?;
199+
Ok(())
200+
}
201+
188202
impl Guest for Component {
189-
fn app_init_no_cleanup_on_error(
190-
org_slug: String,
203+
fn app_modify_no_cleanup_on_error(
191204
app_name: String,
192205
config: ObeliskConfig,
193206
) -> Result<Vec<String>, AppInitNoCleanupError> {
194-
// If the app already exists, fail with AppNameConflict
195-
if activity_fly_http::apps::get(&app_name)
196-
.map_err(AppInitNoCleanupError::AppCreateError)?
197-
.is_some()
198-
{
199-
return Err(AppInitNoCleanupError::AppNameConflict);
200-
}
201-
// Create the app
202-
activity_fly_http::apps::put(&org_slug, &app_name)
203-
.map_err(AppInitNoCleanupError::AppCreateError)?;
204207
app_modify_without_cleanup(&app_name, config)
205208
.map_err(AppInitNoCleanupError::AppInitModifyError)
206209
}
@@ -211,22 +214,13 @@ impl Guest for Component {
211214
config: ObeliskConfig,
212215
sleep_between_retries_seconds: u32,
213216
) -> Result<(), AppInitError> {
217+
app_create(&org_slug, &app_name)?;
214218
// Launch a child workflow by using import
215-
let required_secrets = workflow_import::app_init_no_cleanup_on_error(
216-
&org_slug, &app_name, &config,
217-
)
218-
.map_err(|err| match err {
219-
AppInitNoCleanupError::AppCreateError(err) => {
220-
// No cleanup needed, app creation failed.
221-
AppInitError::AppCreateError(err)
222-
}
223-
AppInitNoCleanupError::AppNameConflict => {
224-
// No cleanup needed, app creation failed on name conflict.
225-
AppInitError::AppNameConflict
226-
}
227-
AppInitNoCleanupError::AppInitModifyError(err) => cleanup(&app_name, Some(err)),
228-
AppInitNoCleanupError::ExecutionFailed => cleanup(&app_name, None),
229-
})?;
219+
let required_secrets = workflow_import::app_modify_no_cleanup_on_error(&app_name, &config)
220+
.map_err(|err| match err {
221+
AppInitNoCleanupError::AppInitModifyError(err) => cleanup(&app_name, Some(err)),
222+
AppInitNoCleanupError::ExecutionFailed => cleanup(&app_name, None),
223+
})?;
230224
// Sleep until all requested secrets are stored in the app.
231225
let required_secrets: HashSet<_> = required_secrets.into_iter().collect();
232226
while !required_secrets.is_empty() {

workflow/deployer-workflow/wit/obelisk-flyio_workflow@1.0.0-beta/types.wit

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ interface types {
5757
}
5858

5959
variant app-init-no-cleanup-error {
60-
app-name-conflict,
61-
app-create-error(string),
6260
app-init-modify-error(app-init-modify-error),
6361
execution-failed,
6462
}

workflow/deployer-workflow/wit/obelisk-flyio_workflow@1.0.0-beta/workflow.wit

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ package obelisk-flyio:workflow@1.0.0-beta;
33
interface workflow {
44
use types.{obelisk-config, app-init-no-cleanup-error, app-init-error};
55

6-
/// Chcek whether the app_name exists. If it does, return app-name-conflict.
7-
/// Create a fly app.
6+
/// Allocate an IP address.
87
/// Create a volume.
98
/// Launch a temporary VM.
109
/// Store the config file on the volume.
1110
/// Execute `obelisk server verify --ignore-missing-env-vars` to download and verify WASM components.
1211
/// Shutdown and delete the temporary VM.
1312
/// Return list of secret keys the config requires.
14-
app-init-no-cleanup-on-error: func(
15-
org-slug: string,
13+
app-modify-no-cleanup-on-error: func(
1614
app-name: string,
1715
config: obelisk-config,
1816
) -> result<list<string>, app-init-no-cleanup-error>;
1917

20-
/// Calls `app-init-no-cleanup` first.
18+
19+
/// Chcek whether the app_name exists. If it does, return app-name-conflict.
20+
/// Create a fly app.
21+
/// Call `app-modify-no-cleanup-on-error` first.
2122
/// If an error occurs during app configuration
2223
/// the app is deleted, leaving the state as it was before this function was called.
2324
/// If the cleanup fails as well `cleanup-error` is raised.
24-
/// Otherwise, when `app-init-no-cleanup` succeeded, the workflow
25+
/// Otherwise, when `app-modify-no-cleanup-on-error` succeeded, the workflow
2526
/// fetches `secrets.list` in an endless loop until all configured secrets
2627
/// are present.
2728
app-init: func(

0 commit comments

Comments
 (0)