Skip to content

Commit

Permalink
fix heroku deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
singharaj-usai committed Oct 27, 2024
1 parent 4d6d66e commit de27a1f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: Deploy

name: Build & Deploy
on:
push:
branches: [ main ] # or 'master' if that's your main branch
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to Server
uses: appleboy/ssh-action@v1.0.0
- name: Deploy NodeJS app
uses: appleboy/ssh-action@v0.1.2
with:
host: ${{ secrets.HOST }}
username: root
key: ${{ secrets.SSH_PRIVATE_KEY }}
host: ${{secrets.SSH_HOST}} # IP address of the server you wish to ssh into
key: ${{secrets.SSH_KEY}} # Private or public key of the server
username: ${{ secrets.SSH_USERNAME }} # User of the server you want to ssh into

script: |
cd /var/www/valkyrie
git pull
npm install
pm2 reload all || pm2 start server/server.js --name "valkyrie"
mkdir test
cd test
git clone [email protected]:Mulubwa17/ci-cd-to-digitalocean-with-github-actions.git
echo 'Deployment successful to digital ocean'
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node server/server.js
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"start:maintenance": "cross-env MAINTENANCE_MODE=true node server/server.js",
"dev": "nodemon server/server.js",
"dev:maintenance": "cross-env MAINTENANCE_MODE=true nodemon server/server.js",
"build": "echo 'No build script needed'",
"build": "npm install",
"heroku-postbuild": "npm install",
"create-admin": "node server/scripts/createAdmin.js",
"reset-user-ids": "node server/scripts/resetUserIds.js",
"generate-test-users": "node server/scripts/generateTestUsers.js",
Expand Down
21 changes: 10 additions & 11 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function connectToDatabase() {
console.log('Connected to MongoDB');
} catch (error) {
console.error('Error connecting to database:', error);
throw error;
setTimeout(connectToDatabase, 5000);
}
}
}
Expand Down Expand Up @@ -189,14 +189,7 @@ app.use('/api', userRoutes);

app.use('/video', express.static(path.join(__dirname, '../video')));
// Serve static files from the client directory
app.use(
'/',
(req, res, next) => {
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
next();
},
express.static(path.join(__dirname, '../client'))
);
app.use(express.static(path.join(__dirname, '../client')));

// Serve static files from the images directory
app.use(
Expand Down Expand Up @@ -312,8 +305,14 @@ app.use((req, res, next) => {
// Call this function after the server starts
app.listen(port, '0.0.0.0', async () => {
console.log(`Server running at http://0.0.0.0:${port}`);
if (process.env.NODE_ENV !== 'production') {
await resetUserIdsIfNeeded();
console.log('Environment:', process.env.NODE_ENV);
try {
await connectToDatabase();
if (process.env.NODE_ENV !== 'production') {
await resetUserIdsIfNeeded();
}
} catch (error) {
console.error('Startup error:', error);
}
});

Expand Down

0 comments on commit de27a1f

Please sign in to comment.