Skip to content
Open
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
31 changes: 31 additions & 0 deletions .github/workflow/ci-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: deploy to production
on:
push:
branches:
- main


jobs:
build:
name: package application
runs-on: ubuntu-latest
needs: {other jobs}
if: github.ref == 'refs/heads/main'

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

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: pnpm install

- name: Run tests
run: pnpm test



File renamed without changes.
4 changes: 4 additions & 0 deletions musango-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.qodo
.env
node_modules/
coverage/
Binary file added musango-app/Capture.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions musango-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use official Node.js image
FROM node:16

# Set working directory
WORKDIR /app

# Copy package.json and install dependencies
COPY package*.json ./
RUN npm install

# Copy the rest of the application
COPY . .

# Expose port 8080
EXPOSE 8080

# Start the application
CMD ["node", "app.js"]
69 changes: 69 additions & 0 deletions musango-app/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
pipeline {
agent any

environment {
MONGO_URI = "mongodb://localhost:27017/musango-express"
DOCKER_IMAGE = "hilltopconsultancy/musango"
DOCKER_CREDENTIALS_ID = "dockerhub-creds" // Jenkins credentials ID
}

stages {
stage('Clone Repo') {
steps {
git url: 'https://github.com/HILL-TOPCONSULTANCY/musango-app.git'
}
}

stage('Install Dependencies') {
steps {
sh 'npm install'
}
}

stage('Run Tests') {
steps {
// Ensure MongoDB is running locally (assumes it's installed on Jenkins host or as a service)
sh '''
echo "Waiting for MongoDB to be ready..."
until nc -z localhost 27017; do sleep 2; done
'''
sh 'npm test'
}
}

stage('Run App Locally') {
steps {
sh '''
nohup node app.js &
sleep 10
curl --fail http://localhost:8080/health
'''
}
}

stage('Build Docker Image') {
steps {
sh 'docker build -t $DOCKER_IMAGE .'
}
}

stage('Push to DockerHub') {
steps {
withCredentials([usernamePassword(credentialsId: "${DOCKER_CREDENTIALS_ID}", passwordVariable: 'DOCKER_PASSWORD', usernameVariable: 'DOCKER_USERNAME')]) {
sh '''
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push $DOCKER_IMAGE
'''
}
}
}
}

post {
always {
echo 'Cleaning up...'
sh 'pkill -f "node app.js" || true'
sh 'docker logout || true'
}
}
}
Loading