-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
56 lines (48 loc) · 1.94 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pipeline {
agent any
environment {
DJANGO_SETTINGS_MODULE = 'crm_backend.settings'
}
stages {
stage('Start PostgreSQL Container') {
steps {
script {
// 使用 Docker 启动 PostgreSQL 容器,并将其连接到 my-network
sh 'docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres:latest'
// 等待 PostgreSQL 容器启动
sh 'until docker exec -i my-postgres psql -U postgres -c "SELECT 1"; do sleep 1; done'
}
}
}
stage('Test Backend') {
agent {
docker {
image 'python:3.9.13-alpine3.16'
}
}
steps {
dir('crm_backend') {
// 进入 crm_backend 目录并执行后端操作
sh 'echo "Installing dependencies..."'
sh 'pip install -r requirements.txt' // 安装依赖
sh 'echo "Running backend tests..."'
sh 'python manage.py test crm_app.tests' // 运行后端测试
}
}
}
stage('Deploy Backend Server') {
steps {
dir('crm_backend') {
// 进入 crm_backend 目录并执行部署操作
sh 'echo "Deploying backend server..."'
// 构建Django应用的Docker镜像
sh 'docker build -t my-django-app .'
// 运行Django应用的Docker容器
sh 'docker run -d -p 8000:8000 --name django-container my-django-app'
sh 'docker exec django-container python /app/manage.py makemigrations'
sh 'docker exec django-container python /app/manage.py migrate'
}
}
}
}
}