Skip to content

Commit 418d26e

Browse files
committed
feat: added phala-cloud default prelaunch script v0.0.8
1 parent 1a43a9c commit 418d26e

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

phala-cloud-prelaunch-script/prelaunch.sh

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
echo "----------------------------------------------"
3-
echo "Running Phala Cloud Pre-Launch Script v0.0.7"
3+
echo "Running Phala Cloud Pre-Launch Script v0.0.8"
44
echo "----------------------------------------------"
55
set -e
66

@@ -73,7 +73,7 @@ elif [[ -n "$DSTACK_AWS_ACCESS_KEY_ID" && -n "$DSTACK_AWS_SECRET_ACCESS_KEY" &&
7373
echo "AWS ECR credentials found"
7474

7575
# Check if AWS CLI is installed
76-
if ! command -v aws &> /dev/null; then
76+
if [ ! -f "./aws/dist/aws" ]; then
7777
notify_host_hoot_info "awscli not installed, installing..."
7878
echo "AWS CLI not installed, installing..."
7979
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.24.14.zip" -o "awscliv2.zip"
@@ -84,12 +84,8 @@ elif [[ -n "$DSTACK_AWS_ACCESS_KEY_ID" && -n "$DSTACK_AWS_SECRET_ACCESS_KEY" &&
8484
exit 1
8585
fi
8686
unzip awscliv2.zip &> /dev/null
87-
./aws/install
88-
89-
# Clean up installation files
90-
rm -rf awscliv2.zip aws
9187
else
92-
echo "AWS CLI is already installed: $(which aws)"
88+
echo "AWS CLI is already installed: ./aws/dist/aws"
9389
fi
9490

9591
# Set AWS credentials as environment variables
@@ -105,21 +101,35 @@ elif [[ -n "$DSTACK_AWS_ACCESS_KEY_ID" && -n "$DSTACK_AWS_SECRET_ACCESS_KEY" &&
105101

106102
# Test AWS credentials before attempting ECR login
107103
echo "Testing AWS credentials..."
108-
if ! aws sts get-caller-identity &> /dev/null; then
104+
if ! ./aws/dist/aws sts get-caller-identity &> /dev/null; then
109105
echo "AWS credentials test failed"
110-
notify_host_hoot_error "Invalid AWS credentials"
111-
exit 1
112-
fi
113-
114-
echo "Logging in to AWS ECR..."
115-
aws ecr get-login-password --region "$DSTACK_AWS_REGION" | docker login --username AWS --password-stdin "$DSTACK_AWS_ECR_REGISTRY"
116-
if [ $? -eq 0 ]; then
117-
echo "AWS ECR login successful"
118-
notify_host_hoot_info "AWS ECR login successful"
106+
# For session token credentials, this might be expected if they're expired
107+
# Log warning but don't fail startup
108+
if [[ -n "$DSTACK_AWS_SESSION_TOKEN" ]]; then
109+
echo "Warning: AWS temporary credentials may have expired, continuing startup"
110+
notify_host_hoot_info "AWS temporary credentials may have expired"
111+
else
112+
echo "AWS credentials test failed"
113+
notify_host_hoot_error "Invalid AWS credentials"
114+
exit 1
115+
fi
119116
else
120-
echo "AWS ECR login failed"
121-
notify_host_hoot_error "AWS ECR login failed"
122-
exit 1
117+
echo "Logging in to AWS ECR..."
118+
./aws/dist/aws ecr get-login-password --region $DSTACK_AWS_REGION | docker login --username AWS --password-stdin "$DSTACK_AWS_ECR_REGISTRY"
119+
if [ $? -eq 0 ]; then
120+
echo "AWS ECR login successful"
121+
notify_host_hoot_info "AWS ECR login successful"
122+
else
123+
echo "AWS ECR login failed"
124+
# For session token credentials, don't fail startup if login fails
125+
if [[ -n "$DSTACK_AWS_SESSION_TOKEN" ]]; then
126+
echo "Warning: AWS ECR login failed with temporary credentials, continuing startup"
127+
notify_host_hoot_info "AWS ECR login failed with temporary credentials"
128+
else
129+
notify_host_hoot_error "AWS ECR login failed"
130+
exit 1
131+
fi
132+
fi
123133
fi
124134
fi
125135

@@ -129,7 +139,7 @@ perform_cleanup
129139
# Set root password if DSTACK_ROOT_PASSWORD is set.
130140
#
131141
if [[ -n "$DSTACK_ROOT_PASSWORD" ]]; then
132-
echo "root:$DSTACK_ROOT_PASSWORD" | chpasswd
142+
echo "$DSTACK_ROOT_PASSWORD" | passwd --stdin root 2>/dev/null || echo -e "$DSTACK_ROOT_PASSWORD\n$DSTACK_ROOT_PASSWORD" | passwd root
133143
unset $DSTACK_ROOT_PASSWORD
134144
echo "Root password set"
135145
fi
@@ -139,24 +149,26 @@ if [[ -n "$DSTACK_ROOT_PUBLIC_KEY" ]]; then
139149
unset $DSTACK_ROOT_PUBLIC_KEY
140150
echo "Root public key set"
141151
fi
152+
if [[ -n "$DSTACK_AUTHORIZED_KEYS" ]]; then
153+
mkdir -p /root/.ssh
154+
echo "$DSTACK_AUTHORIZED_KEYS" > /root/.ssh/authorized_keys
155+
unset $DSTACK_AUTHORIZED_KEYS
156+
echo "Root authorized_keys set"
157+
fi
142158

143159

144160
if [[ -e /var/run/dstack.sock ]]; then
145-
DSTACK_APP_ID=$(curl -s --unix-socket /var/run/dstack.sock http://dstack/Info | jq -j .app_id)
146-
export DSTACK_APP_ID
147-
else
148-
DSTACK_APP_ID=$(curl -s --unix-socket /var/run/tappd.sock http://dstack/prpc/Tappd.Info | jq -j .app_id)
149-
export DSTACK_APP_ID
161+
export DSTACK_APP_ID=$(curl -s --unix-socket /var/run/dstack.sock http://dstack/Info | jq -j .app_id)
162+
elif [[ -e /var/run/tappd.sock ]]; then
163+
export DSTACK_APP_ID=$(curl -s --unix-socket /var/run/tappd.sock http://dstack/prpc/Tappd.Info | jq -j .app_id)
150164
fi
151165
# Check if app-compose.json has default_gateway_domain field and DSTACK_GATEWAY_DOMAIN is not set
152166
# If true, set DSTACK_GATEWAY_DOMAIN from app-compose.json
153167
if [[ $(jq 'has("default_gateway_domain")' app-compose.json) == "true" && -z "$DSTACK_GATEWAY_DOMAIN" ]]; then
154-
DSTACK_GATEWAY_DOMAIN=$(jq -j '.default_gateway_domain' app-compose.json)
155-
export DSTACK_GATEWAY_DOMAIN
168+
export DSTACK_GATEWAY_DOMAIN=$(jq -j '.default_gateway_domain' app-compose.json)
156169
fi
157170
if [[ -n "$DSTACK_GATEWAY_DOMAIN" ]]; then
158-
DSTACK_APP_DOMAIN=$DSTACK_APP_ID"."$DSTACK_GATEWAY_DOMAIN
159-
export DSTACK_APP_DOMAIN
171+
export DSTACK_APP_DOMAIN=$DSTACK_APP_ID"."$DSTACK_GATEWAY_DOMAIN
160172
fi
161173

162174
echo "----------------------------------------------"

0 commit comments

Comments
 (0)