Skip to content

Commit bc1a6db

Browse files
committed
refactor: Add obelisk-version parameter
1 parent 5175f93 commit bc1a6db

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

scripts/json-app-init-stargazers.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
# Prints JSON containing arguments to `app-init` function.
44

5-
SKIP_CLEANUP=${SKIP_CLEANUP:-false}
6-
5+
OBELISK_VERSION=${OBELISK_VERSION:-$(obelisk -v | cut -d ' ' -f 2)}
76
SECRETS_DEADLINE_SECS=${SECRETS_DEADLINE_SECS:-120}
87
HEALTH_CHECK_DEADLINE_SECS=${HEALTH_CHECK_DEADLINE_SECS:-120}
8+
SKIP_CLEANUP=${SKIP_CLEANUP:-false}
99
MINIO=${MINIO:-true}
1010

1111
cat <<EOF
1212
[
1313
"$FLY_ORG_SLUG",
1414
"$FLY_APP_NAME",
15+
"$OBELISK_VERSION",
1516
{
1617
"activity-wasm-list":[
1718
{

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const MINIO_PORT: u16 = 9000;
5151

5252
const VM_NAME_FINAL: &str = "obelisk";
5353
const VOLUME_MOUNT_PATH: &str = "/volume";
54-
const FINAL_IMAGE: &str = "getobelisk/obelisk:0.25.4-ubuntu-litestream";
5554
const OBELISK_TOML_PATH: &str = formatcp!("{VOLUME_MOUNT_PATH}/obelisk.toml");
5655
const OBELISK_BIN_PATH: &str = "/obelisk/obelisk";
5756
const LITESTREAM_CONFIG_PATH: &str = formatcp!("{VOLUME_MOUNT_PATH}/litestream.yml");
@@ -64,6 +63,10 @@ const HEALTHCHECK_EXTERNAL_PORT: u16 = 444;
6463
const SLEEP_BETWEEN_RETRIES: Duration = Duration::from_secs(10);
6564
const SLEEP_AFTER_TEMP_VM_SHUTDOWN: Duration = Duration::from_secs(5);
6665

66+
fn obelisk_image(obelisk_version: &str) -> String {
67+
format!("getobelisk/obelisk:{obelisk_version}-ubuntu-litestream")
68+
}
69+
6770
fn allocate_ip(app_name: &str) -> Result<(), AppInitModifyError> {
6871
activity_fly_http::ips::allocate_unsafe(
6972
app_name,
@@ -108,6 +111,7 @@ fn wait_until_started(app_name: &str, machine_id: &str) -> Result<(), AppInitMod
108111
// If minio is enabled, configure litestream.yml
109112
fn setup_volume(
110113
app_name: &str,
114+
obelisk_version: &str,
111115
obelisk_toml: &str,
112116
minio_machine_id: Option<&str>,
113117
) -> Result<(), AppInitModifyError> {
@@ -128,7 +132,7 @@ fn setup_volume(
128132
app_name,
129133
VM_NAME_TEMP,
130134
&MachineConfig {
131-
image: FINAL_IMAGE.to_string(),
135+
image: obelisk_image(obelisk_version),
132136
guest: Some(GuestConfig {
133137
cpu_kind: Some(CpuKind::Shared),
134138
cpus: Some(1),
@@ -326,7 +330,11 @@ fn minio_configure(app_name: &str, machine_id: &str) -> Result<(), AppInitModify
326330
Ok(())
327331
}
328332

329-
fn start_final_vm(app_name: &str, litestream: bool) -> Result<(), AppInitModifyError> {
333+
fn start_final_vm(
334+
app_name: &str,
335+
obelisk_version: &str,
336+
litestream: bool,
337+
) -> Result<(), AppInitModifyError> {
330338
let entrypoint = if litestream {
331339
Some(vec!["/usr/bin/litestream".to_string()])
332340
} else {
@@ -350,7 +358,7 @@ fn start_final_vm(app_name: &str, litestream: bool) -> Result<(), AppInitModifyE
350358
app_name,
351359
VM_NAME_FINAL,
352360
&MachineConfig {
353-
image: FINAL_IMAGE.to_string(),
361+
image: obelisk_image(obelisk_version),
354362
guest: Some(GuestConfig {
355363
cpu_kind: Some(CpuKind::Shared),
356364
cpus: Some(1),
@@ -487,6 +495,7 @@ impl Guest for Component {
487495
fn prepare(
488496
org_slug: String,
489497
app_name: String,
498+
obelisk_version: String,
490499
config: ObeliskConfig,
491500
minio: bool,
492501
) -> Result<(), AppInitModifyError> {
@@ -503,7 +512,12 @@ impl Guest for Component {
503512
} else {
504513
None
505514
};
506-
setup_volume(&app_name, &obelisk_toml, minio_machine_id.as_deref())?;
515+
setup_volume(
516+
&app_name,
517+
&obelisk_version,
518+
&obelisk_toml,
519+
minio_machine_id.as_deref(),
520+
)?;
507521
Ok(())
508522
}
509523

@@ -517,8 +531,12 @@ impl Guest for Component {
517531
Ok(())
518532
}
519533

520-
fn start_final_vm(app_name: String, litestream: bool) -> Result<(), AppInitModifyError> {
521-
start_final_vm(&app_name, litestream)
534+
fn start_final_vm(
535+
app_name: String,
536+
obelisk_version: String,
537+
litestream: bool,
538+
) -> Result<(), AppInitModifyError> {
539+
start_final_vm(&app_name, &obelisk_version, litestream)
522540
}
523541

524542
fn wait_for_health_check(
@@ -532,6 +550,7 @@ impl Guest for Component {
532550
fn app_init(
533551
org_slug: String,
534552
app_name: String,
553+
obelisk_version: String,
535554
config: ObeliskConfig,
536555
secrets_deadline_secs: u16,
537556
health_check_deadline_secs: u16,
@@ -540,13 +559,13 @@ impl Guest for Component {
540559
) -> Result<(), AppInitError> {
541560
// Launch sub-workflows by using import.
542561
// In case of any error including a trap (panic), delete the whole app.
543-
workflow_import::prepare(&org_slug, &app_name, &config, minio)
562+
workflow_import::prepare(&org_slug, &app_name, &obelisk_version, &config, minio)
544563
.map_err(|err| cleanup(&app_name, err, skip_cleanup_on_error))?;
545564

546565
workflow_import::wait_for_secrets(&app_name, &config, secrets_deadline_secs)
547566
.map_err(|err| cleanup(&app_name, err, skip_cleanup_on_error))?;
548567

549-
workflow_import::start_final_vm(&app_name, minio)
568+
workflow_import::start_final_vm(&app_name, &obelisk_version, minio)
550569
.map_err(|err| cleanup(&app_name, err, skip_cleanup_on_error))?;
551570

552571
workflow_import::wait_for_health_check(&app_name, health_check_deadline_secs)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface workflow {
99
prepare: func(
1010
org-slug: string,
1111
app-name: string,
12+
obelisk-version: string,
1213
config: obelisk-config,
1314
minio: bool,
1415
) -> result<_, app-init-modify-error>;
@@ -23,6 +24,7 @@ interface workflow {
2324
/// Start the final VM.
2425
start-final-vm: func(
2526
app-name: string,
27+
obelisk-version: string,
2628
litestream: bool,
2729
) -> result<_, app-init-modify-error>;
2830

@@ -36,10 +38,10 @@ interface workflow {
3638
/// If an error occurs during app configuration,
3739
/// the app is deleted, leaving the state as it was before this function was called.
3840
/// If the cleanup fails as well `cleanup-error` is raised.
39-
// TODO: Add Obelisk version
4041
app-init: func(
4142
org-slug: string,
4243
app-name: string,
44+
obelisk-version: string,
4345
config: obelisk-config,
4446
secrets-deadline-secs: u16,
4547
health-check-deadline-secs: u16,

0 commit comments

Comments
 (0)