Skip to content

Commit

Permalink
fixed: deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
eustahc committed Jul 19, 2024
1 parent 104874b commit 01177d2
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
53 changes: 51 additions & 2 deletions .github/workflows/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
PROJECT="ZentinelJS"
REPOSITORY="https://github.com/surelle-ha/ZentinelJS"
BRANCH="main"
DIRECTORY="/var/www/html/$PROJECT"
DEPENDENCIES=("wget" "curl" "git" "btop" "nodejs" "npm" "figlet" "xclip")
ENVIRONMENT="production"
DIRECTORY="/var/www/html/"
DEPENDENCIES=("wget" "curl" "git" "btop" "nodejs" "npm" "figlet")

# Log Function
log() {
Expand All @@ -32,6 +33,15 @@ install_dependencies() {
# PREPARE
install_dependencies

# Install PM2 if not already installed
if ! command_exists pm2; then
log "PM2 is not installed, installing now"
if ! npm install -g pm2; then
log "Failed to install PM2"
exit 1
fi
fi

# CHECK IF GIT AUTHENTICATED
if git ls-remote $REPOSITORY &> /dev/null; then
log "Git is authenticated."
Expand Down Expand Up @@ -115,4 +125,43 @@ else

fi

# PM2 Setup
log "Setting up PM2"
if ! command_exists pm2; then
log "PM2 is not installed, installing now"
if ! npm install -g pm2; then
log "Failed to install PM2"
exit 1
fi
fi

# Create PM2 ecosystem config
log "Creating PM2 ecosystem configuration"
cat <<EOL > ecosystem.config.js
module.exports = {
apps: [{
name: '$PROJECT',
script: 'npm',
args: 'run start',
env: {
NODE_ENV: $ENVIRONMENT
}
}]
};
EOL

# Start or restart application with PM2
log "Starting application with PM2"
if pm2 list | grep -q "$PROJECT"; then
if ! pm2 reload ecosystem.config.js; then
log "Failed to reload application with PM2"
exit 1
fi
else
if ! pm2 start ecosystem.config.js; then
log "Failed to start application with PM2"
exit 1
fi
fi

log "Deployment Complete"
48 changes: 48 additions & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ jobs:
# PREPARE
install_dependencies
# Install PM2 if not already installed
if ! command_exists pm2; then
log "PM2 is not installed, installing now"
if ! npm install -g pm2; then
log "Failed to install PM2"
exit 1
fi
fi
# CHECK IF GIT AUTHENTICATED
if git ls-remote $REPOSITORY &> /dev/null; then
log "Git is authenticated."
Expand Down Expand Up @@ -138,4 +147,43 @@ jobs:
fi
# PM2 Setup
log "Setting up PM2"
if ! command_exists pm2; then
log "PM2 is not installed, installing now"
if ! npm install -g pm2; then
log "Failed to install PM2"
exit 1
fi
fi
# Create PM2 ecosystem config
log "Creating PM2 ecosystem configuration"
cat <<EOL > ecosystem.config.js
module.exports = {
apps: [{
name: '$PROJECT',
script: 'npm',
args: 'run start',
env: {
NODE_ENV: 'production'
}
}]
};
EOL
# Start or restart application with PM2
log "Starting application with PM2"
if pm2 list | grep -q "$PROJECT"; then
if ! pm2 reload ecosystem.config.js; then
log "Failed to reload application with PM2"
exit 1
fi
else
if ! pm2 start ecosystem.config.js; then
log "Failed to start application with PM2"
exit 1
fi
fi
log "Deployment Complete"

0 comments on commit 01177d2

Please sign in to comment.