From 263cdc09b74014d67fed6fc5fcdf5e999ace12c6 Mon Sep 17 00:00:00 2001 From: mortezaei Date: Wed, 6 May 2026 16:30:53 +0330 Subject: [PATCH] feat: add Dockerfile and docker-compose.yml for containerized application setup --- .dockerignore | 7 +++++++ Dockerfile | 28 ++++++++++++++++++++++++++++ Jenkinsfile | 46 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 25 +++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9010dc5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +node_modules +.next +.git +.gitignore +README.md +.env* +npm-debug.log* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e85c66c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM node:20-alpine AS base + +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN npm ci + +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ARG NEXT_PUBLIC_API_URL +ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL +RUN npm run build + +FROM base AS runner +WORKDIR /app +ENV NODE_ENV=production +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 nextjs +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +USER nextjs +EXPOSE 3000 +ENV PORT=3000 HOSTNAME="0.0.0.0" +CMD ["node", "server.js"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..a2ac63c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,46 @@ +pipeline { + environment { + develop_server_ip = '' + develop_server_name = '' + production_server_ip = "88.99.212.243" + production_server_name = "newhorizon_germany_001_server" + project_path = "/najm/marriage" + version = "master" + gitBranch = "origin/master" + } + agent any + stages { + stage('deploy') { + steps { + script { + if (gitBranch == "origin/master") { + try { + withCredentials([usernamePassword(credentialsId: production_server_name, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) { + sh 'sshpass -p $PASSWORD ssh -p 1782 $USERNAME@$production_server_ip -o StrictHostKeyChecking=no "cd $project_path && ./runner.sh"' + } + } catch (Exception e) { + def lastCommit = sh(script: 'git log -1 --pretty=format:"%h - %s (%an)"', returnStdout: true).trim() + sh """ + curl -F chat_id=-1002316394394 \ + -F message_thread_id=1629 \ + -F document=@/var/jenkins_home/jobs/${env.JOB_NAME}/builds/${env.BUILD_NUMBER}/log \ + -F caption='Project name: #${env.JOB_NAME} \nBuild status is FAILED \nBuild url: ${BUILD_URL} \nLast Commit: ${lastCommit}' \ + https://api.telegram.org/bot7207581748:AAFeymryw7S44D86LYfWqYK-tSNeV3TOwBs/sendDocument + """ + currentBuild.result = 'FAILURE' + throw e + } + def lastCommit = sh(script: 'git log -1 --pretty=format:"%h - %s (%an)"', returnStdout: true).trim() + sh """ + curl -F chat_id=-1002316394394 \ + -F message_thread_id=1629 \ + -F document=@/var/jenkins_home/jobs/${env.JOB_NAME}/builds/${env.BUILD_NUMBER}/log \ + -F caption='Project name: #${env.JOB_NAME} \nBuild status is SUCCESS \nBuild url: ${BUILD_URL} \nLast Commit: ${lastCommit}' \ + https://api.telegram.org/bot7207581748:AAFeymryw7S44D86LYfWqYK-tSNeV3TOwBs/sendDocument + """ + } + } + } + } + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d022708 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +services: + web: + build: + context: . + dockerfile: Dockerfile + args: + NEXT_PUBLIC_API_URL: http://localhost:3000/api + ports: + - "5561:3000" + environment: + - NODE_ENV=production + - NEXT_PUBLIC_API_URL=http://localhost:3000/api + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + networks: + - najm_najm + +networks: + najm_najm: + external: true