diff --git a/basefiles/app-compose.sh b/basefiles/app-compose.sh index 1f6c39479..59ee187c1 100644 --- a/basefiles/app-compose.sh +++ b/basefiles/app-compose.sh @@ -1,12 +1,39 @@ -#!/bin/sh -tdxctl notify-host -e "boot.progress" -d "starting containers" || true +#!/bin/bash -docker compose up --remove-orphans -d || true -chmod +x /usr/bin/containerd-shim-runc-v2 -systemctl restart docker +if [ $(jq 'has("pre_launch_script")' app-compose.json) == true ]; then + echo "Running pre-launch script" + tdxctl notify-host -e "boot.progress" -d "pre-launch" || true + source <(jq -r '.pre_launch_script' app-compose.json) +fi + +RUNNER=$(jq -r '.runner' app-compose.json) +case "$RUNNER" in +"docker-compose") + echo "Starting containers" + tdxctl notify-host -e "boot.progress" -d "starting containers" || true + if ! [ -f docker-compose.yaml ]; then + jq -r '.docker_compose_file' app-compose.json >docker-compose.yaml + fi + docker compose up --remove-orphans -d || true + chmod +x /usr/bin/containerd-shim-runc-v2 + systemctl restart docker -if ! docker compose up --remove-orphans -d; then - tdxctl notify-host -e "boot.error" -d "failed to start containers" + if ! docker compose up --remove-orphans -d; then + tdxctl notify-host -e "boot.error" -d "failed to start containers" + exit 1 + fi + ;; +"bash") + chmod +x /usr/bin/containerd-shim-runc-v2 + echo "Running main script" + tdxctl notify-host -e "boot.progress" -d "running main script" || true + jq -r '.bash_script' app-compose.json | bash + ;; +*) + echo "ERROR: unsupported runner: $RUNNER" >&2 + tdxctl notify-host -e "boot.error" -d "unsupported runner: $RUNNER" exit 1 -fi + ;; +esac + tdxctl notify-host -e "boot.progress" -d "done" || true diff --git a/tdxctl/src/tboot.rs b/tdxctl/src/tboot.rs index 1ebe03435..4b4949923 100644 --- a/tdxctl/src/tboot.rs +++ b/tdxctl/src/tboot.rs @@ -67,7 +67,6 @@ impl<'a> Setup<'a> { nc.notify_q("boot.progress", "setting up docker").await; self.setup_docker_registry()?; self.setup_docker_account()?; - self.prepare_docker_compose()?; Ok(()) } @@ -263,21 +262,6 @@ impl<'a> Setup<'a> { cmd!(docker login -u $username -p $token)?; Ok(()) } - - fn prepare_docker_compose(&self) -> Result<()> { - info!("Preparing docker compose"); - if self.app_compose.runner == "docker-compose" { - let docker_compose = self - .app_compose - .docker_compose_file - .as_ref() - .context("Missing docker_compose_file")?; - fs::write(self.resolve("/tapp/docker-compose.yaml"), docker_compose)?; - } else { - bail!("Unsupported runner: {}", self.app_compose.runner); - } - Ok(()) - } } pub async fn tboot(args: &TbootArgs) -> Result<()> { diff --git a/teepod/src/console.html b/teepod/src/console.html index 62491a0c0..c7d5ef469 100644 --- a/teepod/src/console.html +++ b/teepod/src/console.html @@ -521,10 +521,16 @@
{{ vm.appCompose?.docker_compose_file }}
+ {{ vm.appCompose?.pre_launch_script }}