Skip to content

Commit c484f64

Browse files
authored
Update prelaunch.sh
1 parent 7038f47 commit c484f64

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

prelaunch-script-private-registry/prelaunch.sh

Lines changed: 42 additions & 6 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.2"
3+
echo "Running Phala Cloud Pre-Launch Script v0.0.4"
44
echo "----------------------------------------------"
55
set -e
66

@@ -79,11 +79,25 @@ elif [[ -n "$DSTACK_AWS_ACCESS_KEY_ID" && -n "$DSTACK_AWS_SECRET_ACCESS_KEY" &&
7979
else
8080
echo "AWS CLI is already installed: $(which aws)"
8181
fi
82+
83+
# Set AWS credentials as environment variables
84+
export AWS_ACCESS_KEY_ID="$DSTACK_AWS_ACCESS_KEY_ID"
85+
export AWS_SECRET_ACCESS_KEY="$DSTACK_AWS_SECRET_ACCESS_KEY"
86+
export AWS_DEFAULT_REGION="$DSTACK_AWS_REGION"
87+
88+
# Set session token if provided (for temporary credentials)
89+
if [[ -n "$DSTACK_AWS_SESSION_TOKEN" ]]; then
90+
echo "AWS session token found, using temporary credentials"
91+
export AWS_SESSION_TOKEN="$DSTACK_AWS_SESSION_TOKEN"
92+
fi
8293

83-
# Configure AWS CLI
84-
aws configure set aws_access_key_id "$DSTACK_AWS_ACCESS_KEY_ID"
85-
aws configure set aws_secret_access_key "$DSTACK_AWS_SECRET_ACCESS_KEY"
86-
aws configure set default.region $DSTACK_AWS_REGION
94+
# Test AWS credentials before attempting ECR login
95+
echo "Testing AWS credentials..."
96+
if ! aws sts get-caller-identity &> /dev/null; then
97+
echo "AWS credentials test failed"
98+
exit 1
99+
fi
100+
87101
echo "Logging in to AWS ECR..."
88102
aws ecr get-login-password --region $DSTACK_AWS_REGION | docker login --username AWS --password-stdin "$DSTACK_AWS_ECR_REGISTRY"
89103
if [ $? -eq 0 ]; then
@@ -96,6 +110,28 @@ fi
96110

97111
perform_cleanup
98112

113+
#
114+
# Set root password if DSTACK_ROOT_PASSWORD is set.
115+
#
116+
if [[ -n "$DSTACK_ROOT_PASSWORD" ]]; then
117+
echo "root:$DSTACK_ROOT_PASSWORD" | chpasswd
118+
unset $DSTACK_ROOT_PASSWORD
119+
echo "Root password set"
120+
fi
121+
if [[ -n "$DSTACK_ROOT_PUBLIC_KEY" ]]; then
122+
mkdir -p /root/.ssh
123+
echo "$DSTACK_ROOT_PUBLIC_KEY" > /root/.ssh/authorized_keys
124+
unset $DSTACK_ROOT_PUBLIC_KEY
125+
echo "Root public key set"
126+
fi
127+
128+
129+
if [[ -e /var/run/dstack.sock ]]; then
130+
export DSTACK_APP_ID=$(curl -s --unix-socket /var/run/dstack.sock http://dstack/Info | jq -j .app_id)
131+
else
132+
export DSTACK_APP_ID=$(curl -s --unix-socket /var/run/tappd.sock http://dstack/prpc/Tappd.Info | jq -j .app_id)
133+
fi
134+
99135
echo "----------------------------------------------"
100136
echo "Script execution completed"
101-
echo "----------------------------------------------"
137+
echo "----------------------------------------------"

0 commit comments

Comments
 (0)