修改jenkins流水线配置
This commit is contained in:
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
FROM 39.170.26.156:8443/library/python:3.9-slim
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONUNBUFFERED=1
|
||||||
|
|
||||||
|
RUN mkdir -p /app/logs
|
||||||
|
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
EXPOSE 5010
|
||||||
|
|
||||||
|
CMD ["gunicorn", "--config=gunicorn.conf.py", "manage:app"]
|
||||||
133
Jenkinsfile
vendored
Normal file
133
Jenkinsfile
vendored
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
def dockerImage
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'cicd/ubuntu:22.04-docker-py312-jdk8-nodejs20-mvn389'
|
||||||
|
args '-u root:root -v /var/run/docker.sock:/var/run/docker.sock'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
GIT_REPO = 'https://wdxz-gitea.best-envision.com/qiaoxinjiu/effekt-interface.git'
|
||||||
|
GIT_CREDENTIALS_ID = 'ebe42f70-146f-4a4b-8090-eded24a77173'
|
||||||
|
|
||||||
|
HARBOR_URL = '39.170.26.156:8443'
|
||||||
|
HARBOR_PROJECT = 'effekt'
|
||||||
|
IMAGE_NAME = 'effekt-interface'
|
||||||
|
IMAGE = "${HARBOR_URL}/${HARBOR_PROJECT}/${IMAGE_NAME}"
|
||||||
|
IMAGE_TAG = 'latest'
|
||||||
|
HARBOR_CREDENTIALS_ID = '3a4a4463-784d-4e91-9457-9dfd64722ecb'
|
||||||
|
|
||||||
|
APP_NAME = 'effekt-interface'
|
||||||
|
HOST_PORT = '5010'
|
||||||
|
CONTAINER_PORT = '5010'
|
||||||
|
|
||||||
|
DEPLOY_HOST = '39.170.26.156'
|
||||||
|
DEPLOY_PORT = '22'
|
||||||
|
DEPLOY_USER = 'root'
|
||||||
|
DEPLOY_CREDENTIALS_ID = '82d14a67-250f-46b0-8b13-50e874a11933'
|
||||||
|
}
|
||||||
|
|
||||||
|
options {
|
||||||
|
timestamps()
|
||||||
|
disableConcurrentBuilds()
|
||||||
|
buildDiscarder(logRotator(numToKeepStr: '20'))
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
checkout([
|
||||||
|
$class: 'GitSCM',
|
||||||
|
branches: [[name: '*/master']],
|
||||||
|
userRemoteConfigs: [[
|
||||||
|
url: env.GIT_REPO,
|
||||||
|
credentialsId: env.GIT_CREDENTIALS_ID
|
||||||
|
]]
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Image') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
dockerImage = docker.build("${env.IMAGE}:${env.IMAGE_TAG}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Push Image To Harbor') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
docker.withRegistry("https://${env.HARBOR_URL}", env.HARBOR_CREDENTIALS_ID) {
|
||||||
|
dockerImage.push(env.IMAGE_TAG)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Deploy') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def remote = [
|
||||||
|
name: 'deploy-server',
|
||||||
|
host: env.DEPLOY_HOST,
|
||||||
|
port: env.DEPLOY_PORT as int,
|
||||||
|
user: env.DEPLOY_USER,
|
||||||
|
allowAnyHosts: true,
|
||||||
|
credentialsId: env.DEPLOY_CREDENTIALS_ID
|
||||||
|
]
|
||||||
|
|
||||||
|
withCredentials([usernamePassword(credentialsId: env.HARBOR_CREDENTIALS_ID, usernameVariable: 'HARBOR_USER', passwordVariable: 'HARBOR_PASS')]) {
|
||||||
|
sshCommand remote: remote, command: """
|
||||||
|
set -e
|
||||||
|
docker login ${env.HARBOR_URL} -u ${HARBOR_USER} -p '${HARBOR_PASS}'
|
||||||
|
docker pull ${env.IMAGE}:${env.IMAGE_TAG}
|
||||||
|
docker rm -f ${env.APP_NAME} || true
|
||||||
|
docker run -d \\
|
||||||
|
--name ${env.APP_NAME} \\
|
||||||
|
--restart always \\
|
||||||
|
-p ${env.HOST_PORT}:${env.CONTAINER_PORT} \\
|
||||||
|
${env.IMAGE}:${env.IMAGE_TAG}
|
||||||
|
docker ps --filter name=${env.APP_NAME}
|
||||||
|
""", sudo: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Verify') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def remote = [
|
||||||
|
name: 'deploy-server',
|
||||||
|
host: env.DEPLOY_HOST,
|
||||||
|
port: env.DEPLOY_PORT as int,
|
||||||
|
user: env.DEPLOY_USER,
|
||||||
|
allowAnyHosts: true,
|
||||||
|
credentialsId: env.DEPLOY_CREDENTIALS_ID
|
||||||
|
]
|
||||||
|
|
||||||
|
sshCommand remote: remote, command: """
|
||||||
|
set -e
|
||||||
|
docker ps --filter name=${env.APP_NAME}
|
||||||
|
curl -I http://127.0.0.1:${env.HOST_PORT}
|
||||||
|
""", sudo: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
sh 'docker image prune -f || true'
|
||||||
|
}
|
||||||
|
success {
|
||||||
|
echo 'Pipeline finished successfully.'
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo 'Pipeline failed.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
const.py
2
const.py
@@ -6,7 +6,7 @@ from urllib.parse import quote
|
|||||||
# dev环境
|
# dev环境
|
||||||
# BE_URL = '127.0.0.1:6080'
|
# BE_URL = '127.0.0.1:6080'
|
||||||
# online环境
|
# online环境
|
||||||
BE_URL = '0.0.0.0:6080'
|
BE_URL = '0.0.0.0:5010'
|
||||||
|
|
||||||
BASEDIR = os.path.dirname(os.path.abspath(__file__))
|
BASEDIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
# PROJDIR = os.path.dirname(BASEDIR)
|
# PROJDIR = os.path.dirname(BASEDIR)
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ pidfile = "logs/gunicorn.pid"
|
|||||||
accesslog = "logs/access.log" # 每个接口调用会展示在access.log中
|
accesslog = "logs/access.log" # 每个接口调用会展示在access.log中
|
||||||
errorlog = "logs/debug.log" # 未处理的报错会在debug.log日志中展示
|
errorlog = "logs/debug.log" # 未处理的报错会在debug.log日志中展示
|
||||||
timeout = 300 # 每个接口的超时时间
|
timeout = 300 # 每个接口的超时时间
|
||||||
daemon = True # 是否开启守护进程。不开启可直接在idea或命令行中查看日志,在服务器上需要修改为True来开启守护进程
|
daemon = False # 容器内以前台方式运行,避免主进程退出
|
||||||
|
|||||||
Reference in New Issue
Block a user