-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
86 lines (71 loc) · 2.33 KB
/
Jenkinsfile
File metadata and controls
86 lines (71 loc) · 2.33 KB
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
79
80
81
82
83
84
85
86
pipeline {
agent any
environment {
IMAGE_NAME = "opsnaveen/opsnaveen-python-chatbot:${GIT_COMMIT}"
}
triggers {
githubPush()
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/Codingnaveen46/PythonChatbot.git'
}
}
stage('Build Docker Image') {
steps {
sh '''
echo "Building Docker Image..."
docker build -t ${IMAGE_NAME} .
'''
}
}
stage('UI Health Test') {
steps {
sh '''
echo "Starting temporary container for UI test..."
docker run -d --rm --name temp-ui-test -p 8501:8501 ${IMAGE_NAME}
echo "Waiting for Streamlit to start..."
sleep 8
echo "Checking UI accessibility..."
curl -f http://localhost:8501 > /dev/null
echo "UI is reachable."
# Stop the temp container
docker stop temp-ui-test || true
'''
}
}
stage('Login to Docker Hub') {
steps {
withCredentials([
usernamePassword(
credentialsId: 'docker-hub-cred',
usernameVariable: 'DOCKER_USERNAME',
passwordVariable: 'DOCKER_PASSWORD'
)
]) {
sh '''
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
'''
}
}
}
stage('Push Docker Image') {
steps {
sh '''
echo "Pushing Docker Image to Docker Hub..."
docker push ${IMAGE_NAME}
'''
}
}
stage('Run Container') {
steps {
sh '''
docker rm -f opsnaveen-python-chatbot || true
docker run -d --name opsnaveen-python-chatbot -p 9001:8501 ${IMAGE_NAME}
echo "Deployment complete. Application running on port 9001."
'''
}
}
}
}