Devnet
6 Cicd
## Lab Instructions
 
### Part 1: clone the devnet repo
 
   ```bash
git clone https://github.com/hwdev123/Devnet.git

Part 2: Commit the Sample App to Git

  1. Login to GitHub and create a new repository:

    • Visit GitHub (opens in a new tab) and log in.
    • Click on "New repository" or the "+" icon, then select "New repository."
    • Create a repository with the following details:
      • Repository name: sample-app
      • Description: Explore CI/CD with GitHub and Jenkins
      • Public/Private: Private
      • Click "Create repository."
  2. Configure Git credentials locally in the VM:

    git config --global user.name "Your Name"
    git config --global user.email your@example.com
  3. Initialize a directory as the Git repository:

    cd labs/devnet-src/jenkins/sample-app/
    git init
  4. Point Git repository to GitHub repository:

    git remote add origin https://github.com/github-username/sample-app.git
  5. Stage, commit, and push the sample-app files to the GitHub repository:

    git add *
    git commit -m "Committing sample-app files."
    git push origin master

Part 3: Modify the Sample App and Push Changes to Git

  1. Open the sample-app files:

    • Make sure you are in the ~/labs/devnet-src/jenkins/sample-app directory.
    • Open sample_app.py and sample-app.sh for editing.
  2. Edit the sample-app files:

    • In sample_app.py, change the port from 8080 to 5050.
    • In sample-app.sh, change all instances of port 8080 to 5050.
  3. Build and verify the sample-app:

    bash ./sample-app.sh
  4. Push your changes to GitHub:

    git add *
    git commit -m "Changed port from 8080 to 5050."
    git push origin master

Part 4: Download and Run the Jenkins Docker Image

  1. Download the Jenkins Docker image:

    docker pull jenkins/jenkins:lts
  2. Start the Jenkins Docker container:

    docker run --rm -u root -p 8080:8080 -v jenkins-data:/var/jenkins_home -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v "$HOME":/home --name jenkins_server jenkins/jenkins:lts
  3. Verify the Jenkins server is running:

    • Copy the admin password displayed in the output.
  4. Investigate the levels of abstraction:

    • Observe the levels of abstraction in the Docker-inside-Docker (dind) implementation.

Part 5: Configure Jenkins

  1. Open a web browser tab:

  2. Install the recommended Jenkins plugins:

    • Click "Install suggested plugins" and wait for the installation to finish.
  3. Skip creating a new admin user and instance configuration:

    • Skip creating an admin user and use the default configuration.
  4. Start using Jenkins:

    • Click "Start using Jenkins."

Part 6: Use Jenkins to Run a Build of Your App

  1. Create a new job:

    • Click "Create a job" or "New Item" in the menu.
    • Enter the name "BuildAppJob" and choose "Freestyle project."
  2. Configure the Jenkins BuildAppJob:

    • Set a description.
    • In the "Source Code Management" tab, choose Git and provide the repository URL and credentials.
    • enter username and for password enter GitHub personal access token
    • change the branch to /main
    • In the "Build" tab, add a build step with the command to run the build script.
  3. Have Jenkins build the app:

    • Click "Build Now" and observe the build process.
  4. Access the build details:

    • Click the build number in the Build History section and view the console output.

Part 7: Use Jenkins to Test a Build

  1. Start a new job for testing the sample-app:

    • Create a new job named "TestAppJob" with the type "Freestyle project."
  2. Configure the Jenkins TestAppJob:

    • Add a description and set the build trigger to run after the "BuildAppJob."
  3. Write the test script:

    • Add a build step with a script to test the sample-app

.

  1. Run the test job:
    • Click "Build Now" for the "TestAppJob" and observe the results.

Part 8: integration of GitHub and Jenkins in automating the build and test processes (unfinished)

  1. Consider the CI/CD process: