Skip to content

Commit c9021a1

Browse files
oilcan-productionslarsbrinkhoff
authored andcommitted
Update deploy-ftp.sh
Adding retry logic for creatin the tar ball to ensure what we upload is valid. Looping back to creating the tar ball instead of looping on the download.
1 parent 63b10e0 commit c9021a1

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

build/deploy-ftp.sh

+52-4
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,68 @@ echo "login $USER" >> "$NETRC"
1818
echo "password $FTP_SECRET" >> "$NETRC"
1919
chmod 600 "$NETRC"
2020

21+
# create_archive will create a tar ball from the out folder
22+
# try to extract it to see if it is valid
23+
# retry 3 times then fail
24+
create_archive{
25+
MAX_RETRIES=3
26+
RETRY_COUNT=0
27+
28+
while (( RETRY_COUNT < MAX_RETRIES )); do
29+
(cd out; tar czf $EMULATOR.tgz $EMULATOR)
30+
31+
# Verify the tarball
32+
if tar tf $EMULATOR.tgz >/dev/null 2>&1; then
33+
echo "Tarball is valid and can be expanded."
34+
break
35+
else
36+
echo "Tarball is not valid or cannot be expanded. Retrying..."
37+
RETRY_COUNT=$((RETRY_COUNT + 1))
38+
rm -f $EMULATOR.tgz
39+
continue
40+
fi
41+
done
42+
43+
if (( RETRY_COUNT == MAX_RETRIES )); then
44+
echo "Failed to create a valid tarball after $MAX_RETRIES attempts."
45+
return 1
46+
fi
47+
}
48+
49+
# upload_file tries to upload the tar ball to the FTP server, will retry 5 times and then fail
2150
upload_file(){
22-
(cd out; tar czf $EMULATOR.tgz $EMULATOR)
51+
MAX_RETRIES=5
52+
RETRY_COUNT=0
2353

24-
echo "Deploying as $USER at $HOST"
54+
while (( RETRY_COUNT < MAX_RETRIES )); do
55+
echo "Deploying as $USER at $HOST"
2556

26-
ftp "$HOST" <<EOF
57+
# Attempt to upload the file
58+
if ftp "$HOST" <<EOF
2759
passive on
2860
type image
2961
cd $DIR
3062
lcd out
3163
put $EMULATOR.tgz
3264
bye
3365
EOF
66+
then
67+
echo "Upload successful."
68+
break
69+
else
70+
echo "Upload failed. Retrying..."
71+
RETRY_COUNT=$((RETRY_COUNT + 1))
72+
fi
73+
done
74+
75+
if (( RETRY_COUNT == MAX_RETRIES )); then
76+
echo "Failed to upload the file after $MAX_RETRIES attempts."
77+
return 1
78+
fi
3479
}
3580

81+
# test_archive_integrity will download the tarball after successful upload and verify its integrity
82+
# by binary comparing the contents of the source folder and the expanded folder
3683
test_archive_integrity(){
3784
echo "Testing download of $EMULATOR.tgz"
3885
mkdir -p "$TESTDIR"
@@ -78,8 +125,9 @@ test_archive_integrity(){
78125
fi
79126
}
80127

81-
128+
# main loop
82129
while [ $retry_count -lt $RETRY_LIMIT ]; do
130+
create_archive
83131
upload_file
84132
if test_archive_integrity; then
85133
echo "File integrity verified successfully."

0 commit comments

Comments
 (0)