text
53 lines
1.61 KB
| 1 | #!/bin/bash |
| 2 | |
| 3 | # The bare git directory |
| 4 | GIT_DIR=/home/deploy/setoelkahfi.com |
| 5 | # The app directory |
| 6 | WORK_TREE=/home/deploy/apps/ssr/setoelkahfi.com |
| 7 | |
| 8 | # Put environment variabels here |
| 9 | . ~/.profile |
| 10 | |
| 11 | while read oldrev newrev ref |
| 12 | do |
| 13 | if [[ $ref =~ .*/main$ ]]; |
| 14 | then |
| 15 | echo "🚀 Main ref received. Deploying main branch to production..." |
| 16 | mkdir -p $WORK_TREE |
| 17 | git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f main |
| 18 | |
| 19 | # start deploy tasks |
| 20 | cd $WORK_TREE |
| 21 | # Configure nvm |
| 22 | nvm install $(cat .nvmrc) |
| 23 | nvm use |
| 24 | |
| 25 | # Install dependencies and build the app |
| 26 | npm install |
| 27 | npm run build |
| 28 | |
| 29 | # Check if SETOELKAHFI_COM_PORT defined in the environment variable. |
| 30 | # If not, cancel the deployment. |
| 31 | if [ -z ${SETOELKAHFI_COM_PORT+x} ]; then |
| 32 | echo "❌ Deployment failed. SETOELKAHFI_COM_PORT is not defined." |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | # Check if SETOELKAHFI_COM_PORT is a number. |
| 37 | # If not, cancel the deployment. |
| 38 | if ! [[ "$SETOELKAHFI_COM_PORT" =~ ^[0-9]+$ ]]; then |
| 39 | echo "❌ Deployment failed. SETOELKAHFI_COM_PORT is not a number." |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | # Kill existing SETOELKAHFI_COM_PORT process and start the server |
| 44 | echo "🚀 Killing existing setoelkahfi.com process..." |
| 45 | kill $(lsof -t -i:$SETOELKAHFI_COM_PORT) |
| 46 | echo "🚀 Starting server..." |
| 47 | npm run start > /dev/null 2>&1 & |
| 48 | |
| 49 | echo "✅ Deployment complete." |
| 50 | else |
| 51 | echo "Ref $ref successfully received. Doing nothing: only the main branch may be deployed on this server." |
| 52 | fi |
| 53 | done |