DEV Community

mibii
mibii

Posted on

Creating Deployment Scripts with ChatGPT

Embracing GPT Chat in Your Work: Adapting to a Rapidly Evolving Landscape

In today's fast-paced world, it's no longer about how much information you can store in your head. The value of rote memorization is rapidly depreciating, giving way to skills like understanding and recognition. These are not innate talents; they are developed through dedicated study and practice, honing the mind to ask insightful questions and interpret complex answers.

Using tools like GPT Chat in your work is not a sign of weakness; it's a strategic move to adapt to the changing times. By delegating routine tasks to artificial intelligence, you free up valuable mental resources to focus on higher-level thinking and creativity. This shift doesn't diminish the importance of learning; rather, it underscores the need to evolve our educational approach. We must teach not just to remember, but to comprehend, analyze, and innovate.

As we embrace these changes, remember that the quality of your interaction with AI tools is crucial. The questions you pose and your ability to interpret the responses are reflections of your engagement and understanding. This is not a skill that will develop overnight, but with practice and persistence, you can unlock new levels of productivity and insight.

The world is changing, and so should our work habits. By integrating AI assistants into our daily routines, we are not just streamlining our tasks; we are preparing ourselves for a future where intelligence is defined not by what we know, but by what we can do with the knowledge at our fingertips.

My Journey in creating Deployment Scripts with ChatGPT: A Beginner DevOps Engineer's Experience

The process of automating deployments, managing environments, and integrating third-party services requires a good understanding of various tools and technologies. Recently, I had the opportunity to leverage ChatGPT to guide me through this process, and I’d like to share my experience on how asking the right questions led me to master deployment scripts.

Starting Point: Understanding the fundamental

You should start this journey with a base understand the fundamental steps involved in a deployment process. I knew that cloning the repository, setting up the environment, building the application, and running it were crucial. However, I needed a structured approach to tie all these steps together, especially using Jenkins and Docker, which are industry standards in CI/CD pipelines.

Asking the Right Questions

Question 1: Basic Jenkinsfile for Letterpad (it is just a random sample of git repository, that i select for this task)
https://github.com/letterpad/letterpad
I started with a straightforward question: "Can you generate a Jenkinsfile based on the provided README for Letterpad?" This question helped me get an initial draft of the Jenkinsfile, covering the basic steps needed to set up and deploy the application. The response provided me with a clear structure:

pipeline {
    agent any
    stages {
        stage('Clone repository') {
            steps {
                git 'git@github.com:letterpad/letterpad.git'
            }
        }
        // Additional stages for setup, build, and run
    }
}
Enter fullscreen mode Exit fullscreen mode

Question 2: Integrating Environment Variables

Next, I needed to understand how to manage environment variables securely, especially sensitive information like API keys and passwords. My question was: "How do I handle environment variables and credentials in Jenkins?" ChatGPT guided me to use Jenkins’ credentials management system, which was a game-changer for handling sensitive data securely.

stage('Setup environment') {
    steps {
        sh 'cp apps/admin/.env.sample apps/admin/.env'
        sh 'cp apps/client/.env.sample apps/client/.env'
        sh 'sed -i "s/SECRET_KEY=/SECRET_KEY=${SECRET_KEY}/" apps/admin/.env'
        sh 'sed -i "s/CLIENT_ID=/CLIENT_ID=${CLIENT_ID}/" apps/client/.env'
    }
}


Enter fullscreen mode Exit fullscreen mode

Question 3: Docker for Deployment

Realizing the benefits of containerization, I asked: "How can I deploy Letterpad using Docker in Jenkins?" This led to an insightful response that integrated Docker commands into the Jenkins pipeline, ensuring that my application could run consistently across different environments.

stage('Build Docker image') {
    steps {
        script {
            dockerImage = docker.build("letterpad:latest", ".")
        }
    }
}
stage('Run Docker container') {
    steps {
        script {
            dockerImage.inside("-v data:/app/apps/admin/prisma/sqlite/data -p 3001:3001 -p 3000:3000") {
                sh '''
                docker run \
                -e DATABASE_URL=${DATABASE_URL} \
                -e SECRET_KEY=${SECRET_KEY} \
                // Other environment variables
                letterpad:latest
                '''
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Question 4: Handling Third-Party Services

Given the number of third-party services Letterpad uses, I asked: "Do I need to register and pay for all the third-party services mentioned in the README?" The response clarified the importance of these services, such as Google reCAPTCHA, Cloudinary, and Unsplash, and highlighted the need to register for these services, some of which offer free tiers.

stage('Run Docker container') {
    steps {
        script {
            dockerImage.inside("-v data:/app/apps/admin/prisma/sqlite/data -p 3001:3001 -p 3000:3000") {
                sh '''
                docker run \
                -v 'data:/app/apps/admin/prisma/sqlite/data' \
                -p 3001:3001 \
                -p 3000:3000 \
                -e DATABASE_URL=${DATABASE_URL} \
                -e SECRET_KEY=${SECRET_KEY} \
                -e EMAIL=${EMAIL} \
                -e PASSWORD=${PASSWORD} \
                -e GMAIL_USER=${GMAIL_USER} \
                -e GMAIL_PASSWORD=${GMAIL_PASSWORD} \
                -e SENDER_EMAIL=${SENDER_EMAIL} \
                -e CLOUDINARY_KEY=${CLOUDINARY_KEY} \
                -e CLOUDINARY_NAME=${CLOUDINARY_NAME} \
                -e CLOUDINARY_SECRET=${CLOUDINARY_SECRET} \
                -e UNSPLASH_CLIENT_ID=${UNSPLASH_CLIENT_ID} \
                -e RECAPTCHA_KEY_CLIENT=${RECAPTCHA_KEY_CLIENT} \
                -e RECAPTCHA_KEY_SERVER=${RECAPTCHA_KEY_SERVER} \
                letterpad:latest
                '''
            }
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

Key Takeaways

Asking Specific Questions: By breaking down my queries into specific, manageable questions, I could get targeted and actionable advice from ChatGPT.
Secure Management of Credentials: Learning about Jenkins' credentials management was crucial for handling sensitive information securely.
Leveraging Docker: Understanding how to build and run Docker containers within Jenkins pipelines significantly streamlined the deployment process.
Understanding Third-Party Services: Knowing the necessity of third-party services and how to integrate them effectively was essential for a complete deployment setup.

Conclusion

Of course, you won't be able to accurately assess the quality of code generated by AI unless you have a solid understanding of the fundamentals and have prior experience. However, AI-generated code can serve as a valuable template to help you start grasping and exploring these concepts further.

Top comments (0)