From 378a9d22e30a9d38cca17121a2407e08bfbbfc8b Mon Sep 17 00:00:00 2001 From: abdelrahmanonline4 Date: Tue, 22 Oct 2024 20:35:32 +0300 Subject: [PATCH 1/3] Add Dockerfile and other changes --- 1 | 26 ++++++++++++++++++++++++++ Dockerfile | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 1 create mode 100644 Dockerfile diff --git a/1 b/1 new file mode 100644 index 0000000000000..a514896a2bc40 --- /dev/null +++ b/1 @@ -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"] + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000..3cd8e100cc36b --- /dev/null +++ b/Dockerfile @@ -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"] + From 991833cbaa8e9c1a5a3b0190cff19ac42a1cc760 Mon Sep 17 00:00:00 2001 From: abdelrahmanonline4 Date: Tue, 22 Oct 2024 20:46:51 +0300 Subject: [PATCH 2/3] Add Dockerfile and other changes --- Jenkinsfile | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000000000..f3a1884d676cc --- /dev/null +++ b/Jenkinsfile @@ -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_REPO = 'https://github.com/abdelrahmanonline4/nodejs.org' // رابط الـ GitHub Repo + } + + stages { + stage('Checkout or Fetch Code') { + steps { + // جلب الكود من GitHub + git 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!' + } + } +} + From 36929109b2176df998fb272310928fa40de8d230 Mon Sep 17 00:00:00 2001 From: abdelrahmanonline4 Date: Wed, 23 Oct 2024 17:29:37 +0300 Subject: [PATCH 3/3] add project in master --- Jenkinsfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f3a1884d676cc..183e4493ebc1a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,16 +2,17 @@ pipeline { agent any environment { - DOCKER_HUB_CREDENTIALS = 'docker-hub-credentials' // استخدم الـ ID الخاص بالـ Docker Hub Credentials - DOCKER_IMAGE = 'bedomm180/ci-app' // اسم الصورة التي تريد دفعها إلى Docker Hub + 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 - git url: "${GITHUB_REPO}" + // جلب الكود من GitHub باستخدام الـ credentials + git credentialsId: "${GITHUB_CREDENTIALS}", url: "${GITHUB_REPO}" } } @@ -27,7 +28,7 @@ pipeline { stage('Run Unit Testing') { steps { script { - // تشغيل اختبارات الوحدة للتأكد من عمل المشروع بشكل صحيح + // تشغيل اختبارات الوحدة sh 'npm test' } } @@ -63,4 +64,3 @@ pipeline { } } } -