Overview:
We have a script that deploys our branch to the dev server so each branch has a specific URL. Previously, it worked by creating a folder with the branch name in the dev server directory and then populating that folder with the respective UI and API code folders. However, the script no longer works after a recent update from GitHub. While the folder for the branch is still being created, the UI and API folders are now empty.
Below are the steps I have tried:
Please find below our .server_deploy.sh file
. In order to find out where the code stopped executing, I tried adding echo statements. After checking, I discovered that it creates the UI and API folders by running mkdir api
and mkdir UI
for the API and UI projects, but no files or folders get deployed by running the following cloning commands.
` #!/bin/bash
set -e
echo "Deploying application ..... branch = $1"
#rm -rf "/var/www/html/devserver/$1"
BRANCH_DIR="/var/www/html/devserver/$1"
if [ ! -d "$BRANCH_DIR" ]
then
mkdir -p "$BRANCH_DIR"
chown $USER:www-data -R $BRANCH_DIR
cd $BRANCH_DIR
echo "Cloning API Repo..."
mkdir api
git config --global --add safe.directory $BRANCH_DIR/api
git clone [email protected]:{API URL HERE} api
echo "Cloning UI Repo..."
mkdir ui
git config --global --add safe.directory $BRANCH_DIR/ui
git clone [email protected]:{UI URL HERE} ui
chown $USER:www-data -R $BRANCH_DIR
fi
# back to home directory
cd
# setup Node version
source ~/.nvm/nvm.sh
nvm use 12.16.3
# setup API
cd $BRANCH_DIR/api
chmod 777 -R storage bootstrap/cache
chown aqib:www-data -R $BRANCH_DIR
#switch branch
git stash
git reset --hard origin/master
git pull
if git branch -a | grep $1
then
git checkout $1
else
git checkout master
fi
cp /var/www/html/devserver/.env $BRANCH_DIR/api/
sed -i -e "s/BRANCH/$1/g" $BRANCH_DIR/api/.env
composer install --no-interaction --prefer-dist --optimize-autoloader
php artisan config:clear
php artisan cache:clear
php artisan migrate --force
php artisan db:seed
php artisan optimize
npm install
npm run prod
#setup UI
cd $BRANCH_DIR/ui
#switch branch
git stash
git reset --hard origin/master
git pull
if git branch -a | grep $1
then
git checkout $1
else
git checkout master
fi
cp /var/www/html/devserver/config.js $BRANCH_DIR/ui/src/api/
sed -i -e "s/BRANCH/$1/g" $BRANCH_DIR/ui/src/api/config.js
npm install
npm run build
Also, I tried cloning the branch on the server using ssh and it didn’t work. I also added permission to the folder.
Here is our laravel.yml file.
name: Laravel
on:
pull_request
jobs:
devserver:
runs-on: ubuntu-latest
services:
# mysql-service Label used to access the service container
mysql-service:
# Docker Hub image (also with version)
image: mysql:5.7
env:
## Accessing to Github secrets, where you can store your configuration
MYSQL_ROOT_PASSWORD: ******
MYSQL_DATABASE: db_test
## map the "external" 33306 port with the "internal" 3306
** REST OF THE CODE HERE, LIKE UNIT TESTING AND CODE QUALITY **
- name: Deploy to Devserver
env:
PUSHED_BRANCH_NAME: ${{ steps.branch-name.outputs.head_ref_branch }}
uses: appleboy/ssh-action@master
with:
username: ${{ secrets.DEVSERVER_SSH_USER }}
host: ${{secrets.DEVSERVER_HOST}}
envs: PUSHED_BRANCH_NAME
password: ${{ secrets.DEVSERVER_SSH_PASS }}
script: sudo /home/$USER/.server_deploy.sh $PUSHED_BRANCH_NAME
Below are the log of errros which I’m getting while deploying the code to the dev server.
======CMD======
sudo /home/***/.server_deploy.sh $PUSHED_BRANCH_NAME
======END======
out: Deploying application ..... branch = lg-30rvkhp
out: Now using node v12.16.3 (npm v6.14.4)
err: chmod: cannot access 'storage': No such file or directory
err: chmod: cannot access 'bootstrap/cache': No such file or directory
2023/03/27 07:45:20 Process exited with status 1
Can anybody please help?
2
Answers
Are you able to clone your project? Is this working
Your output goes from the first "Deploying application" string to the NVM "Now using" response, but it doesn’t include the "Cloning API Repo" or "Cloning UI Repo" echoes that should otherwise be between the two (along with the detailed output of the clone tasks). Unless you’re obscuring parts of the output, I suspect the problem is in that
if [ ! -d "$BRANCH_DIR" ]
conditional; that test is returning false, so the clone commands are never called in the first place.Also, how exactly did your SSH cloning attempts "not work"?