Skip to content

Commit bc3dd37

Browse files
committed
chore: use marketype spot option instead of resetting bid price
Signed-off-by: Huamin Chen <hchen@redhat.com>
1 parent bbc701c commit bc3dd37

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

entrypoint.sh

+3-28
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,10 @@ export RUNNER_ALLOW_RUNASROOT=true
146146
EOF
147147
}
148148

149-
get_bid_price () {
150-
BID_PRICE=$(aws ec2 describe-spot-price-history --instance-types "$INSTANCE_TYPE" \
151-
--product-descriptions "Linux/UNIX" --region "${REGION}" \
152-
--query 'SpotPriceHistory[0].SpotPrice' --output text)
153-
}
154-
155149
run_spot_instance () {
156150
INSTANCE_JSON=$(aws ec2 run-instances --image-id $AMI_ID --count 1 --instance-type $INSTANCE_TYPE \
157151
--security-group-ids $SECURITY_GROUP_ID --region ${REGION} --region ${REGION} \
158-
--instance-market-options '{"MarketType":"spot", "SpotOptions": {"MaxPrice": "'${BID_PRICE}'" }}' \
152+
--instance-market-options 'MarketType=spot' \
159153
--block-device-mappings '[{"DeviceName": "/dev/sda1","Ebs": { "VolumeSize": '${ROOT_VOLUME_SIZE}', "DeleteOnTermination": true } }]'\
160154
$KEY_NAME_OPT \
161155
--user-data file://user_data.sh 2>&1)
@@ -201,13 +195,7 @@ create_runner () {
201195
# GitHub Runner setup script
202196
create_uesr_data
203197

204-
# we use spot instance, the bid price is determined by the spot price history, simply use the last price for now
205-
# Fetching spot price history
206-
debug "Fetching spot price history..."
207-
get_bid_price
208-
# Creating a spot instance request
209-
debug "Creating a spot instance with an initial bid of ${BID_PRICE}"
210-
# try 3 times, each time increase the bid price by 10%
198+
# try 3 times
211199
for i in {1..3}
212200
do
213201
run_spot_instance
@@ -216,20 +204,7 @@ create_runner () {
216204

217205
# Check if instance creation failed
218206
if [ -z "$INSTANCE_ID" ]; then
219-
debug "Failed to create instance with bid price ${BID_PRICE}"
220-
# if bid price is too low, and the error message contains"An error occurred (SpotMaxPriceTooLow) when calling the RunInstances operation: Your Spot request price of 0.0035200000000000023 is lower than the minimum required Spot request fulfillment price of 0.06319999999999999."
221-
# then we extract the minimum required price and use that as the new bid price
222-
if [[ "$INSTANCE_JSON" == *"SpotMaxPriceTooLow"* ]]; then
223-
debug "SpotMaxPriceTooLow error, extracting minimum required price"
224-
MIN_PRICE=$(echo -n "$INSTANCE_JSON" | awk '{print $NF}' | head -c -2 | tr -d '\r')
225-
debug "Minimum required price: ${MIN_PRICE}"
226-
BID_PRICE=$(echo "$MIN_PRICE * 1.01" | bc)
227-
BID_PRICE=$MIN_PRICE
228-
continue
229-
else
230-
BID_PRICE=$(echo "$BID_PRICE * 1.1" | bc)
231-
fi
232-
debug "Creating a spot instance with a new bid of ${BID_PRICE}"
207+
debug "Failed to create instance, retrying"
233208
continue
234209
else
235210
break

0 commit comments

Comments
 (0)