Created
July 18, 2024 11:00
-
-
Save image72/5b919b00d125f977891750a60b04b8c6 to your computer and use it in GitHub Desktop.
deploy project build to ssh server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected]:$targetPath | |
ssh [email protected] << 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