-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Dstack-TEE/prelaunch-demo
Add example of using prelaunch script
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
busybox: | ||
image: busybox:latest | ||
command: sh -c "cat /etc/motd" | ||
volumes: | ||
- /tapp/motd:/etc/motd | ||
restart: no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This is an example of how to write a pre-launch script of DStack App Compose. | ||
|
||
# The script is run in /tapp directory. The app-compose.json file is in the same directory. | ||
|
||
set -e | ||
|
||
# We fully handle the docker compose logic in this script. | ||
echo "Extracting docker compose file" | ||
jq -j '.docker_compose_file' app-compose.json >docker-compose.yaml | ||
echo "Removing orphans" | ||
tdxctl remove-orphans -f docker-compose.yaml || true | ||
echo "Restarting docker" | ||
chmod +x /usr/bin/containerd-shim-runc-v2 | ||
systemctl restart docker | ||
|
||
# Use a container to setup the environment | ||
echo "Setting up the environment" | ||
tdxctl notify-host -e "boot.progress" -d "setting up the environment" || true | ||
docker run \ | ||
--rm \ | ||
--name dstack-app-setup \ | ||
-v /tapp:/tapp \ | ||
-w /tapp \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
curlimages/curl:latest \ | ||
-s https://raw.githubusercontent.com/Dstack-TEE/meta-dstack/refs/heads/main/meta-dstack/recipes-core/base-files/files/motd -o /tapp/motd | ||
|
||
echo "Starting containers" | ||
tdxctl notify-host -e "boot.progress" -d "starting containers" || true | ||
if ! docker compose up -d; then | ||
tdxctl notify-host -e "boot.error" -d "failed to start containers" | ||
exit 1 | ||
fi | ||
|
||
# Use exit to skip the original docker compose handling | ||
exit 0 |