فهرست منبع

Merge remote-tracking branch 'origin/dev' into dev

wmy 3 هفته پیش
والد
کامیت
203199c266
4فایلهای تغییر یافته به همراه111 افزوده شده و 0 حذف شده
  1. 7 0
      Dockerfile
  2. 83 0
      Jenkinsfile
  3. 6 0
      build.sh
  4. 15 0
      docker-compose.yaml

+ 7 - 0
Dockerfile

@@ -0,0 +1,7 @@
+FROM 172.16.0.165:5000/simulations/reverse_osmosis_model:v1
+
+WORKDIR /app
+
+COPY . .
+
+CMD ["python", "smart_monitor.py"]

+ 83 - 0
Jenkinsfile

@@ -0,0 +1,83 @@
+pipeline {
+    agent any
+
+    environment {
+        DEPLOY_SERVER = "greentech@101.200.76.30"
+        DEPLOY_REPO_PATH = "/home/greentech/services/reverse_osmosis_model"
+        HARBOR_URL = "172.16.0.165:5000/simulations"
+        IMAGE_NAME = "reverse_osmosis_model"
+    }
+
+    stages {
+        stage('获取commit哈希') {
+            steps {
+                git branch: "${APP_GIT_BRANCH}",
+                    url: "${APP_GIT_URL}",
+                    credentialsId: "git-public"
+            }
+        }
+
+        stage('拉取代码') {
+            steps {
+                withCredentials([usernamePassword(
+                    credentialsId: 'gpu2key',
+                    usernameVariable: 'USER',
+                    passwordVariable: 'PWD'
+                )]) {
+                    sh """
+                        sshpass -p '$PWD' ssh -o StrictHostKeyChecking=no $USER@101.200.76.30 "
+                            cd ${DEPLOY_REPO_PATH} &&
+                            git pull origin ${APP_GIT_BRANCH}
+                        "
+                    """
+                }
+            }
+        }
+
+        stage('构建并推送镜像') {
+            steps {
+                script {
+                    def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
+                    withCredentials([usernamePassword(
+                        credentialsId: 'gpu2key',
+                        usernameVariable: 'USER',
+                        passwordVariable: 'PWD'
+                    )]) {
+                        sh """
+                            sshpass -p '$PWD' ssh -o StrictHostKeyChecking=no $USER@101.200.76.30 "
+                                cd ${DEPLOY_REPO_PATH} &&
+                                export HARBOR_URL=${HARBOR_URL} &&
+                                export IMAGE_NAME=${IMAGE_NAME} &&
+                                export GIT_COMMIT_SHORT=${gitCommitShort} &&
+                                chmod +x build.sh &&
+                                ./build.sh
+                            "
+                        """
+                    }
+                }
+            }
+        }
+
+        stage('部署到测试环境') {
+            steps {
+                script {
+                    def gitCommitShort = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
+                    
+                    withCredentials([usernamePassword(
+                        credentialsId: 'gpu2key',
+                        usernameVariable: 'USER',
+                        passwordVariable: 'PWD'
+                    )]) {
+                        sh """
+                            sshpass -p '$PWD' ssh -o StrictHostKeyChecking=no $USER@101.200.76.30 "
+                            export GIT_COMMIT_SHORT=${gitCommitShort}
+                                cd ${DEPLOY_REPO_PATH} &&
+								docker compose pull && docker compose up -dV 
+                            "
+                        """
+                    }
+                }
+            }
+        }
+    }
+}

+ 6 - 0
build.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+#zoumuyu
+
+docker build -t ${HARBOR_URL}/${IMAGE_NAME}:${GIT_COMMIT_SHORT} .
+docker push ${HARBOR_URL}/${IMAGE_NAME}:${GIT_COMMIT_SHORT}
+docker pull ${HARBOR_URL}/${IMAGE_NAME}:${GIT_COMMIT_SHORT}

+ 15 - 0
docker-compose.yaml

@@ -0,0 +1,15 @@
+version: '3.8'
+
+services:
+  reverse_osmosis_model:
+    image: 172.16.0.165:5000/simulations/reverse_osmosis_model:${GIT_COMMIT_SHORT}
+    container_name: reverse_osmosis_model
+    restart: always
+    environment:
+      - TZ=Asia/Shanghai
+    networks:
+      - reverse_osmosis_model
+
+networks:
+  reverse_osmosis_model:
+    driver: bridge