-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathprelaunch.sh
More file actions
46 lines (39 loc) · 1.61 KB
/
Copy pathprelaunch.sh
File metadata and controls
46 lines (39 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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
# Login docker account
echo "Logging into Docker Hub"
tdxctl notify-host -e "boot.progress" -d "logging into docker hub" || true
if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
if ! echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; then
tdxctl notify-host -e "boot.error" -d "failed to login to docker hub"
exit 1
fi
fi
# 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