Skip to main content

updateDockerCompose

PATCH /cvms/{cvmId}/docker-compose Updates the Docker Compose file for a running CVM. The request body is sent as text/yaml. This function uses a two-phase flow for CVMs with on-chain KMS:
  1. Phase 1: Call with the new docker_compose_file. If the CVM uses on-chain KMS, the API returns precondition_required with a compose_hash.
  2. Register on-chain: Call addComposeHash to register the new compose hash on the blockchain.
  3. Phase 2: Retry the call with the original YAML plus compose_hash and transaction_hash.
Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
docker_compose_filestringYesNew Docker Compose YAML content
compose_hashstringNoCompose hash (Phase 2, sent via X-Compose-Hash header)
transaction_hashstringNoOn-chain transaction hash (Phase 2, sent via X-Transaction-Hash header)
Returns: Union of two possible responses: Success (in_progress):
FieldTypeDescription
status"in_progress"Update accepted
messagestringStatus message
correlation_idstringTracking ID
Precondition required (precondition_required):
FieldTypeDescription
status"precondition_required"On-chain registration needed
messagestringInstructions
compose_hashstringHash to register on-chain
app_idstringApp ID for contract interaction
device_idstringDevice ID
kms_infoKmsInfoKMS details for chain interaction
Example — PHALA KMS:
const result = await client.updateDockerCompose({
  id: "my-app",
  docker_compose_file: newComposeYaml,
});
// result.status === "in_progress"
Example — On-chain KMS (two phases):
import { addComposeHash } from "@phala/cloud";

// Phase 1
const result = await client.updateDockerCompose({
  id: "my-app",
  docker_compose_file: newComposeYaml,
});

if (result.status === "precondition_required") {
  // Register on-chain
  const receipt = await addComposeHash({
    chain: result.kms_info.chain,
    kmsContractAddress: result.kms_info.kms_contract_address,
    appId: result.app_id as `0x${string}`,
    composeHash: result.compose_hash,
    privateKey: privateKey,
  });

  // Phase 2
  await client.updateDockerCompose({
    id: "my-app",
    docker_compose_file: newComposeYaml,
    compose_hash: result.compose_hash,
    transaction_hash: receipt.transactionHash,
  });
}

safeUpdateDockerCompose

Safe variant that returns a SafeResult instead of throwing on errors.