-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsFile
98 lines (88 loc) · 2.73 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
pipeline {
agent any
environment {
// Define environment variables like for Docker, credentials, etc.
DOCKER_IMAGE = "nextjs-app-image"
DOCKER_REGISTRY = "my-docker-registry"
NODE_ENV = "production"
FRONTEND_URL = "https://frontend.myapp.com"
}
stages {
stage('Checkout') {
steps {
// Checkout code from the Git repository
git branch: 'main', url: 'https://github.com/Emmanuel10701/AI_Prediction_Model.git'
}
}
stage('Install Dependencies') {
steps {
script {
// Install frontend and backend dependencies
dir('frontend') {
sh 'npm install'
}
}
}
}
stage('Run Tests') {
steps {
script {
// Run tests for your Next.js application
dir('frontend') {
sh 'npm test'
}
}
}
}
stage('Build Next.js App') {
steps {
script {
// Build the Next.js application for production
dir('frontend') {
sh 'npm run build'
}
}
}
}
stage('Dockerize App') {
steps {
script {
// Create a production-ready Docker image for the application
sh 'docker build -t $DOCKER_REGISTRY/$DOCKER_IMAGE .'
}
}
}
stage('Push Docker Image') {
steps {
script {
// Push the Docker image to a registry
sh 'docker push $DOCKER_REGISTRY/$DOCKER_IMAGE'
}
}
}
stage('Deploy to Production') {
steps {
script {
// SSH into your server to deploy or use your Kubernetes environment
sh 'ssh -o StrictHostKeyChecking=no user@production-server "docker pull $DOCKER_REGISTRY/$DOCKER_IMAGE && docker-compose -f docker-compose.prod.yml up -d"'
}
}
}
stage('Notify Success') {
steps {
script {
// Notify on Slack or any other communication tool
slackSend(channel: '#deployments', message: "Deployment was successful!")
}
}
}
}
post {
success {
echo 'Deployment completed successfully.'
}
failure {
echo 'Deployment failed.'
}
}
}