Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy Backend to EC2

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup SSH key
uses: webfactory/ssh-agent@v0.7.0
with:
ssh-private-key: ${{ secrets.EC2_SSH_KEY }}

- name: Deploy Backend to EC2
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }} -p ${{ secrets.EC2_PORT }} << 'EOF'
cd /home/ec2-user/easyToFind-Backend

echo "DB_HOST=${{ secrets.DB_HOST }}" > .env
echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
echo "PORT=${{ secrets.PORT }}" >> .env
echo "CORS_ORIGIN=${{ secrets.CORS_ORIGIN }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env

git pull origin main
npm install
pm2 restart easytofind-backend
EOF
2 changes: 1 addition & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require("dotenv").config();
* Get port from environment and store in Express.
*/

const port = normalizePort(PORT || "3000");
const port = normalizePort(PORT || "3001");
app.set("port", port);

/**
Expand Down
2 changes: 1 addition & 1 deletion common/envConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const dotenv = require("dotenv");
dotenv.config();

const constants = {
PORT: process.env.PORT || "3000",
PORT: process.env.PORT || "3001",
DB_HOST: process.env.DB_HOST,
DB_USER: process.env.DB_USER,
DB_PORT: process.env.DB_PORT,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon ./bin/www",
"start": "node ./bin/www",
"import-csv": "node scripts/importCsvData.js",
"test-api": "node scripts/testApi.js",
"test-db": "node scripts/testDatabase.js"
Expand Down