Skip to main content

Command Palette

Search for a command to run...

Project: Constructing a comprehensive ChatGPT application via Jenkins pipeline

Updated
3 min read
Project: Constructing a comprehensive ChatGPT application via Jenkins pipeline
B

I like to explore the technology in DevOps area where I write blog about my learning each day on the tools that is mostly used in Industries for DevOps practices. You can go through my blogs and reach me out in LinkedIn for any suggestions.

Aim

To create a Jenkins end-to-end declarative pipeline for a ChatGPT application which will operate with a single click to be production ready.

Tools used

  1. Docker

  2. DockerHub

  3. GitHub

  4. Jenkins

  5. ChatGPT application

Execution steps

  1. In this project, we will create a Jenkins Agent node. We will run our whole project on the agent node being on the Master node.

  2. To execute the above step, let's create two AWS EC2 instances Jenkins Master and Jenkins Agent servers.

  3. Install Docker, and Jenkins in the Master server. You can refer to the official websites for the installation in Linux/Ubuntu servers.

  4. Install Docker and Java in the Agent server.

  5. You can configure the Jenkins-suggested plugins and set up the GUI of Jenkins.

  6. Create a Pipeline in Jenkins by navigating through the new item.

  7. Set up the configuration of the pipeline. Provide the necessary description for the pipeline.

  8. Provide the GitHub project URL for a better description as shown in the above screenshot.

  9. Select the GitHub Hook trigger to setup the automatic trigger of Pipeline through the GitHub Webhook property.

  10. Navigate to the GitHub project repository and go to the Settings option and select the Webhook option.

  11. Provide the appropriate Payload URL and settings to set up the Webhook utility of GitHub.

  12. Now, On Jenkins let's set up the declarative pipeline. Here we will pick the Pipeline script from GitHub without writing it in the Jenkins Pipeline. This will have a huge advantage to keep track of the changes done by the users in a bigger IT organisation.

  13. Provide the necessary description along with the project repository URL and secret token for connecting to GitHub.

  14. Add the Jenkinsfile to the pipeline and save the pipeline.

  15. Let's create the Dockerfile for the application.

  16. Create a docker-compose.yml file and make sure to install Docker-compose on the agent server.

  17. The execution steps in the Jenkins file will include the secret key to connect the OPENAI credentials of ChatGPT. Also, for pushing the image to the docker hub, set up the username and password.

  18. Write the Jenkinsfile with all the configurations.

    pipeline {
        agent {label 'Devops_Agent'}
         environment {
                       key = credentials('openAI')
                    }
        stages {
            stage('Code fetch') {
                steps {
                    git url:'https://github.com/Bandank/chatgpt-web-application.git',branch:'master'
                }
            }
            stage('build and test') {
                steps {
                    sh 'sudo docker build . -t bandank/chatgpt-app:latest'
                }
            }
            stage('push') {
                steps {
                    withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
                    sh "docker login -u ${env.dockerHubUser} -p ${env.dockerHubPassword}"
                    sh 'docker push bandank/chatgpt-app:latest'
                }
              }
            }
            stage('Deploy'){
                steps {
                    withCredentials([string(credentialsId: 'openAI', variable: 'OPENAI_API_KEY')]) {
                                    sh 'docker-compose down'
                                    sh "docker-compose up -d"
                            }
    
                }
            }
        }
    }
    

  19. You can check the images are pushed to the DockerHub.

  20. Now click on save and execute the pipeline.

  21. Click build now to run the pipeline.

  22. Let's see the Project Demo now.

Project Live Execution

  1. We have seen the execution of the Pipeline above. Now, navigate to the agent server URL and observe the running application.

  2. Now, finally, we have our ChatGPT application set up. You can ask any question about the application and witness the power of Artificial Intelligence.

Thanks for witnessing the magic of AI tool through a pipeline. Have a nice day.

You can follow me on LinkedIn for my daily updates:- linkedin.com/in/bandan-kumar-sahoo-131412203

More from this blog

Untitled Publication

98 posts