Skip to content

Commit

Permalink
github/actions: Upload image to temporary dir and then move it
Browse files Browse the repository at this point in the history
First upload contents to the temporary dir and once fully uploaded
move the directory to the final destination to avoid potential race
where simplestream-maintainer can pick the partially uploaded image.

Signed-off-by: Din Music <[email protected]>
  • Loading branch information
MusicDin committed Mar 29, 2024
1 parent a69a570 commit f6fa797
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions .github/actions/image-upload/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,14 @@ runs:
VERSION=$(cat "${SRC_DIR}/serial")
# Create directory structure that will be mirrored on the target server.
PRODUCT_PATH="${SRC_DIR}-upload/${IMG_DIR}"
mkdir -p "${PRODUCT_PATH}/${VERSION}"
# Move config.yaml file if exists.
if [ -f "${SRC_DIR}/config.yaml" ]; then
mv "${SRC_DIR}/config.yaml" "${PRODUCT_PATH}"
fi
# Move image content.
mv ${SRC_DIR}/* "${PRODUCT_PATH}/${VERSION}"
# Use SFTP to upload images to the server.
sftp -P ${SSH_PORT} "${SSH_USER}@${SSH_HOST}" <<EOF
put -r ${SRC_DIR}-upload/*
mkdir -p "${SRC_DIR}-upload/${IMG_DIR}/.${VERSION}"
mv ${SRC_DIR}/* "${SRC_DIR}-upload/${IMG_DIR}/.${VERSION}"
# First upload contents to the temporary dir and once fully uploaded
# move the directory to the final destination to avoid potential race
# where simplestream-maintainer includes partially uploaded images.
sftp -P ${SSH_PORT} -b - "${SSH_USER}@${SSH_HOST}" <<EOF
put -R ${SRC_DIR}-upload/*
rename "${IMG_DIR}/.${VERSION}" "${IMG_DIR}/${VERSION}"
bye
EOF

0 comments on commit f6fa797

Please sign in to comment.