Skip to content

Instantly share code, notes, and snippets.

@image72
Created July 18, 2024 11:00
Show Gist options
  • Save image72/5b919b00d125f977891750a60b04b8c6 to your computer and use it in GitHub Desktop.
Save image72/5b919b00d125f977891750a60b04b8c6 to your computer and use it in GitHub Desktop.
deploy project build to ssh server
#!/bin/sh
trap cleanup EXIT
# green="\e[1;32m"
# red="\e[1;31m"
# reset="\e[0m"
green=$(tput setaf 64);
red=$(tput setaf 124);
reset=$(tput sgr0);
NODE_OPTIONS=--openssl-legacy-provider
version=$(node -p "require('./package.json').version")
VITE_GIT_VERSION=$(git rev-parse --short HEAD)
branch=$(git rev-parse --abbrev-ref HEAD)
echo "Building $branch version v$version ($VITE_GIT_VERSION)..."
# Build the app
zipfile="dist-$VITE_GIT_VERSION.zip"
npm run build && \
echo $VITE_GIT_VERSION > dist/version && \
zip -qr $zipfile dist
targetPath="/root/www-root"
# Upload dist.zip to the remote server
scp $zipfile root@192.168.1.235:$targetPath
ssh root@192.168.1.235 << EOF
cd $targetPath &&
unzip -qo $targetPath/$zipfile
EOF
cleanup() {
echo "Cleaning up... ${zipfile}"
rm -f $zipfile
}
if [ $? -eq 0 ]; then
now=$(date '+%Y-%m-%d %H:%M:%S')
echo "${green}Remote operations succeeded - ${now}${reset}"
else
echo "${red}Remote operations failed${reset}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment