Skip to content

Commit e89b132

Browse files
committed
chore: extract newer archive only based on touch time in GHA
1 parent bf6725b commit e89b132

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

docker/all-in-one/entrypoint.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ function start_supervisor {
210210
}
211211

212212
DELEGATED_ARCHIVE_PATH=/data/delegated-init.tar.gz
213+
DELEGATED_ENTRY_PATH=/data/delegated-entry.sh
213214

214215
function fetch_and_execute_delegated_payload {
215216
curl -s --time-cond $DELEGATED_ARCHIVE_PATH -o $DELEGATED_ARCHIVE_PATH "$DELEGATED_INIT_LOCATION"
@@ -220,15 +221,29 @@ function fetch_and_execute_delegated_payload {
220221
fi
221222

222223
# only extract a valid archive
223-
if [[ $(tar -tzf $DELEGATED_ARCHIVE_PATH) ]]; then
224-
# TODO: (tom) Only extract newer tar archives
225-
tar -xvzf $DELEGATED_ARCHIVE_PATH -C /
224+
if tar -tzf "$DELEGATED_ARCHIVE_PATH" &>/dev/null; then
225+
TAR_MTIME_EPOCH=$(tar -tvzf "$DELEGATED_ARCHIVE_PATH" data/delegated-entry.sh | awk '{print $4, $5}' | xargs -I {} date -d {} +%s)
226+
227+
if [ -f $DELEGATED_ENTRY_PATH ]; then
228+
FILE_MTIME_EPOCH=$(stat -c %Y "$DELEGATED_ENTRY_PATH")
229+
230+
if [ "$TAR_MTIME_EPOCH" -gt "$FILE_MTIME_EPOCH" ]; then
231+
tar -xvzf "$DELEGATED_ARCHIVE_PATH" -C /
232+
else
233+
echo "TAR archive is not newer, skipping extraction"
234+
fi
235+
else
236+
tar -xvzf "$DELEGATED_ARCHIVE_PATH" -C /
237+
fi
238+
else
239+
echo "Invalid TAR archive"
240+
return
226241
fi
227242

228243
# Run our delegated entry script here
229-
if [ -f /data/delegated-init/delegated-entry.sh ]; then
230-
chmod +x /data/delegated-init/delegated-entry.sh
231-
bash -c "/data/delegated-init/delegated-entry.sh $START_TIME"
244+
if [ -f "$DELEGATED_ENTRY_PATH" ]; then
245+
chmod +x $DELEGATED_ENTRY_PATH
246+
bash -c "$DELEGATED_ENTRY_PATH $START_TIME"
232247
fi
233248
}
234249

0 commit comments

Comments
 (0)