-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
78 lines (72 loc) · 2.44 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
pipeline {
agent { label 'ubuntu2-vbox' }
environment {
VENV_PATH = "${WORKSPACE}/venv"
APP_LOG = "${WORKSPACE}/uvicorn.log"
}
stages {
stage('Checkout Code') {
steps {
echo 'Cloning repository...'
checkout scm
}
}
stage('Prepare Environment') {
steps {
echo 'Setting up system dependencies...'
sh '''
echo '1334keiNdeltA$' | sudo -S apt update -y
echo '1334keiNdeltA$' | sudo -S apt install -y python3 python3-venv python3-pip build-essential libssl-dev libffi-dev python3-dev
python3 -m venv ${VENV_PATH}
. ${VENV_PATH}/bin/activate
pip install --upgrade pip setuptools wheel
pip cache purge
pip install numpy --only-binary :all:
pip install -r requirements.txt
'''
}
}
stage('Run Application') {
steps {
echo 'Starting the FastAPI application...'
sh '''
if lsof -i:8000; then
echo "Port 8000 is already in use. Killing the process..."
kill -9 $(lsof -t -i:8000)
fi
. ${VENV_PATH}/bin/activate
nohup uvicorn main:app --host 0.0.0.0 --port 8000 --log-level debug > ${APP_LOG} 2>&1 &
'''
}
}
stage('Health Check') {
steps {
echo 'Waiting for the application to start...'
sh 'sleep 10'
echo 'Checking if the application is running...'
script {
def response = sh(script: 'curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8000', returnStdout: true).trim()
if (response != '200') {
error "Application is not running properly. HTTP status code: ${response}"
}
}
}
}
}
post {
always {
echo 'Pipeline execution completed.'
}
failure {
echo 'Deployment failed. Check logs for details.'
sh '''
if [ -f ${APP_LOG} ]; then
cat ${APP_LOG}
fi
'''
}
success {
echo 'Deployment succeeded. Application is running.'
}
}
}