Skip to content
Closed

Master #7135

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
26 changes: 26 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Stage 1: Build and install dependencies
FROM node:18-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install

# Copy the rest of your application code
COPY . .

# Build your application if necessary (uncomment the next line if you have a build script)
# RUN npm run build

# Stage 2: Setup the production environment
FROM node:18-alpine
WORKDIR /app

# Only copy necessary files from the builder stage
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app .

# Expose the port the app runs on
EXPOSE 3000

# Define the command to run your app
CMD ["node", "server.js"]

22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# مرحلة البناء
FROM node:20-alpine AS build

WORKDIR /usr/src/app

COPY . .

RUN npm install --legacy-peer-deps

# مرحلة الإنتاج
FROM node:20-alpine

WORKDIR /usr/src/app

COPY --from=build /usr/src/app .

ENV HOST=0.0.0.0

EXPOSE 3000

CMD ["npx", "turbo", "dev"]

66 changes: 66 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
pipeline {
agent any

environment {
DOCKER_HUB_CREDENTIALS = 'docker-hub-credentials' // ID الخاص بـ Docker Hub Credentials
DOCKER_IMAGE = 'bedomm180/ci-app' // اسم الصورة على Docker Hub
GITHUB_CREDENTIALS = 'github-credentials2' // ID الخاص بـ GitHub Credentials
GITHUB_REPO = 'https://github.com/abdelrahmanonline4/nodejs.org' // رابط الـ GitHub Repo
}

stages {
stage('Checkout or Fetch Code') {
steps {
// جلب الكود من GitHub باستخدام الـ credentials
git credentialsId: "${GITHUB_CREDENTIALS}", url: "${GITHUB_REPO}"
}
}

stage('Install Dependencies') {
steps {
script {
// تثبيت التبعيات باستخدام npm
sh 'npm install'
}
}
}

stage('Run Unit Testing') {
steps {
script {
// تشغيل اختبارات الوحدة
sh 'npm test'
}
}
}

stage('Dockerize') {
steps {
script {
// بناء الصورة باستخدام Dockerfile الموجود في المستودع
docker.build("${DOCKER_IMAGE}")
}
}
}

stage('Push Docker Image') {
steps {
script {
// استخدام الـ credentials لدفع الصورة إلى Docker Hub
docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_HUB_CREDENTIALS}") {
docker.image("${DOCKER_IMAGE}").push('latest')
}
}
}
}
}

post {
success {
echo 'Build, test, and push completed successfully!'
}
failure {
echo 'Build, test, or push failed!'
}
}
}