+
Skip to content

inhacollab/sample-app

Repository files navigation

Jenkins CI/CD Pipeline Lab 6.3.6

This repository contains all the files needed to complete the Jenkins CI/CD Pipeline Lab 6.3.6. The lab demonstrates how to build a complete CI/CD pipeline using Jenkins, Docker, and a sample Flask web application.

📋 Lab Overview

This lab teaches you how to:

  • Create and containerize a Flask web application
  • Set up Jenkins with Docker
  • Create Jenkins jobs for building and testing
  • Implement a complete CI/CD pipeline
  • Automate deployment and testing processes

🏗️ Project Structure

├── sample_app.py          # Main Flask application
├── sample-app.sh          # Build and run script
├── templates/
│   └── index.html         # HTML template
├── static/
│   └── style.css         # CSS styling
├── Jenkinsfile           # Jenkins pipeline definition
├── Dockerfile            # Docker container definition
├── docker-compose.yml    # Docker Compose configuration
├── requirements.txt      # Python dependencies
├── test-app.sh          # Application testing script
├── setup-jenkins.sh     # Jenkins setup script
├── cleanup.sh           # Resource cleanup script
└── README.md            # This file

🚀 Quick Start

Prerequisites

  • Docker installed and running
  • Git installed
  • Terminal/Command Line access

1. Test the Sample Application

First, let's build and run the sample application:

# Make scripts executable
chmod +x *.sh

# Build and run the application
./sample-app.sh

Visit http://localhost:5050 to see the application running.

2. Set Up Jenkins

To set up Jenkins with Docker:

# Run the Jenkins setup script
./setup-jenkins.sh

This will:

  • Pull the Jenkins Docker image
  • Start Jenkins on port 8080
  • Display the admin password

Visit http://localhost:8080 and complete the Jenkins setup with the provided password.

3. Test the Application

Run the test script to verify the application is working:

./test-app.sh

4. Clean Up Resources

When you're done with the lab:

./cleanup.sh

🔧 Manual Setup Instructions

Part 1: Create a GitHub Repository

  1. Create a new repository named sample-app
  2. Clone this repository and push the files to your GitHub repo
  3. Configure Git credentials locally

Part 2: Jenkins Configuration

  1. Create Build Job (BuildAppJob):

    • New Item → Freestyle project
    • Source Code Management: Git
    • Repository URL: Your GitHub repository
    • Build: Execute shell → bash ./sample-app.sh
  2. Create Test Job (TestAppJob):

    • New Item → Freestyle project
    • Build Triggers: Build after other projects are built → BuildAppJob
    • Build: Execute shell → Use the test script content
  3. Create Pipeline Job (SamplePipeline):

    • New Item → Pipeline
    • Pipeline script: Use the provided Jenkinsfile content

Part 3: Running the Pipeline

  1. Trigger the BuildAppJob manually
  2. Verify both BuildAppJob and TestAppJob complete successfully
  3. Run the SamplePipeline to see the complete automated workflow

📝 Key Files Explained

sample_app.py

  • Flask web application that displays the client's IP address
  • Runs on port 5050 to avoid conflicts with Jenkins (port 8080)

sample-app.sh

  • Shell script that builds a Docker container for the Flask app
  • Creates temporary directories, copies files, and builds/runs the container

Jenkinsfile

  • Defines the complete CI/CD pipeline with stages:
    • Preparation: Clean up previous containers
    • Build: Run the application build
    • Test: Verify the application works
    • Deploy: Confirm successful deployment

templates/index.html

  • HTML template that shows the client's IP address
  • Uses Flask templating to display dynamic content

static/style.css

  • CSS styling with light steel blue background
  • Provides visual formatting for the web page

🐳 Docker Commands

Useful Docker commands for this lab:

# View running containers
docker ps

# View all containers
docker ps -a

# Stop a container
docker stop samplerunning

# Remove a container
docker rm samplerunning

# View images
docker images

# Remove an image
docker rmi sampleapp

🔍 Troubleshooting

Port Conflicts

  • Ensure port 5050 is free for the Flask app
  • Ensure port 8080 is free for Jenkins
  • Use docker ps to check running containers

Container Issues

  • If containers won't start, try the cleanup script
  • Check Docker daemon is running
  • Verify sufficient disk space

Jenkins Access

  • Wait 30 seconds after starting Jenkins before accessing
  • Check the admin password with: docker exec jenkins_server cat /var/jenkins_home/secrets/initialAdminPassword

📚 Learning Objectives

By completing this lab, you will understand:

  1. Continuous Integration (CI):

    • Automated building and testing of applications
    • Source code management integration
    • Build triggers and dependencies
  2. Continuous Deployment (CD):

    • Automated deployment processes
    • Environment management
    • Release automation
  3. Jenkins Pipeline:

    • Pipeline as Code with Jenkinsfile
    • Stage definitions and error handling
    • Pipeline visualization and monitoring
  4. Docker Integration:

    • Containerized applications
    • Docker-in-Docker configurations
    • Container lifecycle management

🎯 Next Steps

After completing this lab, you can explore:

  • Multi-branch pipelines
  • Integration with GitHub webhooks
  • Advanced testing strategies
  • Production deployment patterns
  • Monitoring and alerting
  • Security scanning integration

📞 Support

If you encounter issues:

  1. Check the troubleshooting section
  2. Verify all prerequisites are installed
  3. Ensure Docker is running properly
  4. Check the console output in Jenkins for detailed error messages

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载