Skip to content

Commit fc0d427

Browse files
committed
teepod: Show compose hash in the UI
1 parent 0098af0 commit fc0d427

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

teepod/src/console.html

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ <h2>Deploy a new instance</h2>
669669
</div>
670670
</div>
671671
</div>
672+
<div class="app-id-preview">
673+
Compose Hash: 0x{{ composeHashPreview }}
674+
</div>
672675

673676
<div class="vm-actions">
674677
<button type="submit" class="action-btn primary">Deploy</button>
@@ -930,6 +933,9 @@ <h3>Update VM Config</h3>
930933
<textarea id="userConfig" v-model="upgradeDialog.user_config"
931934
placeholder="Optional: User config to be put at /tapp/.user-config in the CVM"></textarea>
932935
</div>
936+
<div class="app-id-preview">
937+
Compose Hash: 0x{{ upgradeComposeHashPreview }}
938+
</div>
933939
</div>
934940
<div style="display: flex; align-items: center; margin-top: 16px;">
935941
<input type="checkbox" v-model="upgradeDialog.resetSecrets" style="width: 16px; height: 16px;">
@@ -1020,7 +1026,8 @@ <h3>Derive VM</h3>
10201026
createApp,
10211027
ref,
10221028
onMounted,
1023-
watch
1029+
watch,
1030+
computed
10241031
} = Vue;
10251032

10261033
createApp({
@@ -1183,10 +1190,14 @@ <h3>Derive VM</h3>
11831190
return JSON.stringify(app_compose);
11841191
};
11851192

1186-
const calcAppId = async () => {
1187-
const app_compose = makeAppComposeFile();
1193+
const calcComposeHash = async (app_compose) => {
11881194
const sha256Hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(app_compose));
1189-
return Array.from(new Uint8Array(sha256Hash)).map(b => b.toString(16).padStart(2, '0')).join('').slice(0, 40);
1195+
return Array.from(new Uint8Array(sha256Hash)).map(b => b.toString(16).padStart(2, '0')).join('');
1196+
}
1197+
1198+
const calcAppId = async () => {
1199+
const composeHash = await calcComposeHash(makeAppComposeFile());
1200+
return composeHash.slice(0, 40);
11901201
};
11911202

11921203
const encryptEnv = async (envs, hexPublicKey) => {
@@ -1449,6 +1460,16 @@ <h3>Derive VM</h3>
14491460
}
14501461
};
14511462

1463+
const updatedCompose = () => {
1464+
const currentAppCompose = upgradeDialog.value.vm.appCompose;
1465+
const app_compose = {
1466+
...currentAppCompose,
1467+
docker_compose_file: upgradeDialog.value.dockerComposeFile || currentAppCompose.docker_compose_file
1468+
};
1469+
app_compose.pre_launch_script = upgradeDialog.value.preLaunchScript?.trim();
1470+
return JSON.stringify(app_compose);
1471+
}
1472+
14521473
const upgradeVM = async () => {
14531474
try {
14541475
const vm = upgradeDialog.value.vm;
@@ -1470,13 +1491,7 @@ <h3>Derive VM</h3>
14701491
id: upgradeDialog.value.vm.id,
14711492
};
14721493
if (upgradeDialog.value.updateCompose) {
1473-
const currentAppCompose = upgradeDialog.value.vm.appCompose;
1474-
const app_compose = {
1475-
...currentAppCompose,
1476-
docker_compose_file: upgradeDialog.value.dockerComposeFile || currentAppCompose.docker_compose_file
1477-
};
1478-
app_compose.pre_launch_script = upgradeDialog.value.preLaunchScript?.trim();
1479-
body.compose_file = JSON.stringify(app_compose);
1494+
body.compose_file = updatedCompose();
14801495
}
14811496

14821497
if (upgradeDialog.value.resetSecrets) {
@@ -1679,6 +1694,45 @@ <h3>Derive VM</h3>
16791694
return "running";
16801695
};
16811696

1697+
const composeHashPreview = ref('');
1698+
const upgradeComposeHashPreview = ref('');
1699+
1700+
// Watch for changes to relevant form fields and update the hash preview
1701+
watch([
1702+
() => vmForm.value.name,
1703+
() => vmForm.value.dockerComposeFile,
1704+
() => vmForm.value.preLaunchScript,
1705+
() => vmForm.value.kms_enabled,
1706+
() => vmForm.value.tproxy_enabled,
1707+
() => vmForm.value.public_logs,
1708+
() => vmForm.value.public_sysinfo,
1709+
() => vmForm.value.local_key_provider_enabled,
1710+
() => vmForm.value.docker_config.enabled,
1711+
() => vmForm.value.docker_config.username,
1712+
() => vmForm.value.docker_config.token_key
1713+
], async () => {
1714+
try {
1715+
composeHashPreview.value = await calcComposeHash(makeAppComposeFile());
1716+
} catch (error) {
1717+
composeHashPreview.value = 'Error calculating hash';
1718+
}
1719+
}, { deep: true });
1720+
1721+
// Watch for changes to upgrade dialog compose fields
1722+
watch([
1723+
() => upgradeDialog.value.dockerComposeFile,
1724+
() => upgradeDialog.value.preLaunchScript
1725+
], async () => {
1726+
if (!upgradeDialog.value.show || !upgradeDialog.value.updateCompose) return;
1727+
1728+
try {
1729+
// Calculate hash with upgrade values
1730+
upgradeComposeHashPreview.value = await calcComposeHash(updatedCompose());
1731+
} catch (error) {
1732+
upgradeComposeHashPreview.value = 'Error calculating hash';
1733+
}
1734+
}, { deep: true });
1735+
16821736
return {
16831737
vms,
16841738
vmForm,
@@ -1722,6 +1776,8 @@ <h3>Derive VM</h3>
17221776
getFlags,
17231777
version,
17241778
showDeployDialog,
1779+
composeHashPreview,
1780+
upgradeComposeHashPreview,
17251781
};
17261782
}
17271783
}).mount('#app');

0 commit comments

Comments
 (0)