Skip to content

Commit 00572ea

Browse files
committed
imp: integrate with dstack-util notify-host
1 parent 6ca3bd1 commit 00572ea

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

phala-cloud-prelaunch-script/prelaunch.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
#!/bin/bash
22
echo "----------------------------------------------"
3-
echo "Running Phala Cloud Pre-Launch Script v0.0.4"
3+
echo "Running Phala Cloud Pre-Launch Script v0.0.5"
44
echo "----------------------------------------------"
55
set -e
66

7+
# Function: notify host
8+
9+
notify_host() {
10+
if command -v dstack-util >/dev/null 2>&1; then
11+
dstack-util notify-host -e "$1" -d "$2"
12+
else
13+
tdxctl notify-host -e "$1" -d "$2"
14+
fi
15+
}
16+
17+
notify_host_hoot_info() {
18+
notify_host "boot.progress" "$1"
19+
}
20+
21+
notify_host_hoot_error() {
22+
notify_host "boot.error" "$1"
23+
}
24+
725
# Function: Perform Docker cleanup
826
perform_cleanup() {
927
echo "Pruning unused images"
1028
docker image prune -af
1129
echo "Pruning unused volumes"
1230
docker volume prune -f
31+
notify_host_hoot_info "docker cleanup completed"
1332
}
1433

1534
# Function: Check Docker login status without exposing credentials
@@ -22,16 +41,6 @@ check_docker_login() {
2241
fi
2342
}
2443

25-
# Function: Check AWS ECR login status
26-
check_ecr_login() {
27-
# Check if we can access the registry without exposing credentials
28-
if aws ecr get-authorization-token --region $DSTACK_AWS_REGION &>/dev/null; then
29-
return 0
30-
else
31-
return 1
32-
fi
33-
}
34-
3544
# Main logic starts here
3645
echo "Starting login process..."
3746

@@ -55,6 +64,7 @@ if [[ -n "$DSTACK_DOCKER_USERNAME" && -n "$DSTACK_DOCKER_PASSWORD" ]]; then
5564
echo "Docker login successful"
5665
else
5766
echo "Docker login failed"
67+
notify_host_hoot_error "docker login failed"
5868
exit 1
5969
fi
6070
fi
@@ -64,11 +74,13 @@ elif [[ -n "$DSTACK_AWS_ACCESS_KEY_ID" && -n "$DSTACK_AWS_SECRET_ACCESS_KEY" &&
6474

6575
# Check if AWS CLI is installed
6676
if ! command -v aws &> /dev/null; then
77+
notify_host_hoot_info "awscli not installed, installing..."
6778
echo "AWS CLI not installed, installing..."
6879
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.24.14.zip" -o "awscliv2.zip"
6980
echo "6ff031a26df7daebbfa3ccddc9af1450 awscliv2.zip" | md5sum -c
7081
if [ $? -ne 0 ]; then
7182
echo "MD5 checksum failed"
83+
notify_host_hoot_error "awscli install failed"
7284
exit 1
7385
fi
7486
unzip awscliv2.zip &> /dev/null
@@ -95,15 +107,18 @@ elif [[ -n "$DSTACK_AWS_ACCESS_KEY_ID" && -n "$DSTACK_AWS_SECRET_ACCESS_KEY" &&
95107
echo "Testing AWS credentials..."
96108
if ! aws sts get-caller-identity &> /dev/null; then
97109
echo "AWS credentials test failed"
110+
notify_host_hoot_error "Invalid AWS credentials"
98111
exit 1
99112
fi
100113

101114
echo "Logging in to AWS ECR..."
102115
aws ecr get-login-password --region $DSTACK_AWS_REGION | docker login --username AWS --password-stdin "$DSTACK_AWS_ECR_REGISTRY"
103116
if [ $? -eq 0 ]; then
104117
echo "AWS ECR login successful"
118+
notify_host_hoot_info "AWS ECR login successful"
105119
else
106120
echo "AWS ECR login failed"
121+
notify_host_hoot_error "AWS ECR login failed"
107122
exit 1
108123
fi
109124
fi

0 commit comments

Comments
 (0)