Jenkins-AWS-CICD - Implement Jenkins CI/CD with AWS CodeBuild and AWS CodeDeploy, build a python flask web application.

Overview

Jenkins CI/CD with AWS CodeBuild and AWS CodeDeploy

Continuous integration and continuous deployment for a python flask web application.

Architecture

Jenkins CI/CD with AWS CodeBuild and AWS CodeDeploy

Installation

1. Launch an EC2 instance as config host, clone repository from Github

    git clone https://github.com/dragonflly/Jenkins-AWS-CICD.git

    Repository folder tree:

  └── Jenkins-AWS-CICD/
      ├── application
      ├── cfn-template
      ├── iam-resource
      ├── images
      └── README.md

2. Create flask web application repository in Github

  • Create a new repository in your Gitbub account (Example: Jenkins-app)
  • Clone Jenkins-app
    git clone https://github.com/
   
    /Jenkins-app.git

   

two repo

  • Copy flask web application to Jenkins-app, then push
    cp -r Jenkins-AWS-CICD/application/* Jenkins-app
    cd Jenkins-app
    git add .
    git commit -m "flask web initial"
    git push

3. Create SSH keyPair

  • Create a KeyPair on AWS console (Example: KeyPair-us-east-1 in us-east-1)

4. Create a CFN templates S3 bucket and upload templates

  • Create a S3 bucket (Example: jenkins-cicd-cfn-templates in us-east-1)
    aws s3api create-bucket --bucket jenkins-cicd-cfn-templates --region us-east-1
  • Copy CFN templates to the S3 bucket
    aws s3 cp Jenkins-AWS-CICD s3://jenkins-cicd-cfn-templates/Jenkins-AWS-CICD --recursive

5. Create whole AWS infrastructure as Code (IaC) with CloudFormation

  • Create stack from AWS CloudFormation console, specify template source by Amazon S3 URL
    https://jenkins-cicd-cfn-templates.s3.amazonaws.com/Jenkins-AWS-CICD/cfn-template/cicd-Jenkins.yaml
  • Specify stack input parameter from console
    Stack name: Jenkins-cicd
    KeyPairName: KeyPair-us-east-1
    TemplateS3Bucket: jenkins-cicd-cfn-templates

      It will takes approximately 6 minutes, and CloudFormation stack Outputs tab:
Jenkins CICD AWS IaC

6. Unlock Jenkins server, and initialize Jenkins

  • SSH into JenkinsServer with IP address and KeyPair-us-east-1
    Jenkins Server

  • Get initialAdminPassword

    cat /var/lib/jenkins/secrets/initialAdminPassword
  • Copy the JenkinsServerAddr value (Example: 34.205.33.197:8080) from the CloudFormation stack Outputs tab, and paste it into browser

  • Paste initialAdminPassword into Administrator password, unlock Jenkins server Unlock Jenkins server

  • Install suggested plugins
    Install suggested plugins

  • Create First Admin User
    Create First Admin User

  • Waiting a few minutes, Jenkins will be ready!

7. Add Jenkins plugin

  • Click on Manage Jenkins, then Manage Plugins
  • Search Available and select the below plugins, then choose Install without restart
    AWS CodeDeploy
    AWS CodeBuild
    Http Request
    File Operations

choose plugin

  • Choose Restart Jenkins when installation is complete
    Restart Jenkins

  • It will take couple of minutes to download the plugins then restart

8. Create a Jenkins CICD project

  • Choose New Item
    Enter an item name (Example: Jenkins-CICD)
    Select Freestyle project
    Create Freestyle project

  • Under Source Code Management
    Choose Git
    Enter HTTPS of Jenkins-app.git into Repository URL
    Change Branch Specifier from master to main
    SCM config

  • Under Build Triggers
    Select Poll SCM
    Enter H/2 * * * * into Schedule, to poll GitHub every two minutes
    build trigger

  • Under Build Environment
    Select Delete workspace before build starts
    build environment

9. Add AWS CodeBuild

  • Under Build
    Select Add build step
    Choose AWS CodeBuild
    Add CodeBuild step

  • Under AWS Configuration
    Choose Manually specify access and secret keys
    Input AWS Access Key
    Input AWS Secret Key
    input AK SK

  • Under Project Configuration
    Enter AWS Region (Example: us-east-1)
    Enter CodeBuild Project Name, copy from CloudFormation Outputs tab
    Select Use Jenkins source
    project configuration

10. Add File Operation

  • Under Build
    Select Add build step
    Choose File Operation

  • Under File Operation
    Select File Delete
    file delete

  • Under File Delete
    Input asterisk, to delete all files which from Github after zip and upload
    Input asterisk

11. Add HTTP Request

12. Add File Operation

  • Under Build
    Select Add build step
    Choose File Operation

  • Under File Operation
    Select Add, then Unzip
    Select Add, then File Delete

  • Under Zip File
    Enter codebuild-artifact.zip into Zip File

  • Under File Delete
    Enter codebuild-artifact.zip into Include File Pattern
    file zip delete

13. Add AWS CodeDeploy

  • Under Post-build Actions
    Select Add post-build action
    Choose Deploy an application to AWS CodeDeploy
    add CodeDeploy

  • Under Deploy an application to AWS CodeDeploy
    Fill AWS CodeDeploy Application Name which copied from Outputs tab
    Fill AWS CodeDeploy Deployment Group which copied from Outputs tab
    Fill AWS CodeDeploy Deployment Config with CodeDeployDefault.OneAtATime
    Fill AWS Region (Example: us-east-1)
    Fill S3 Bucket which copied from Outputs tab
    CodeDeploy config

  • Select Deploy Revision

  • Choose Wait for deployment to finish
    deploy revision

  • Click SAVE to finish configuration

14. Build and check

  • Click Build Now
    Check Jenkins CICD progress
    build and deploy

  • CICD finished, copy ALBURL from Outputs tab, paste into browser
    Python flask web application should be
    falsk application

  • In flask application repository Jenkins-app
    Change background-color from blue to red in application/templates/Jenkins-page.html
    Commit change, trigger CI/CD in two minutes
    falsk application

License Summary

This code is made available under the MIT license. See the LICENSE file.

You might also like...
Phonebook application to manage phone numbers

PhoneBook Phonebook application to manage phone numbers. How to Use run main.py python file. python3 main.py Links Download Source Code: Click Here M

Django-Kubernetes - Learn how to deploy a docker-based Django application into a Kubernetes cluster into production on DigitalOcean
Bugbane - Application security tools for CI/CD pipeline

BugBane Набор утилит для аудита безопасности приложений. Основные принципы и осо

Prometheus exporter for AWS Simple Queue Service (SQS)
Prometheus exporter for AWS Simple Queue Service (SQS)

Prometheus SQS Exporter Prometheus exporter for AWS Simple Queue Service (SQS) Metrics Metric Description ApproximateNumberOfMessages Returns the appr

Cado Response Integration with Amazon GuardDuty using AWS Lambda
Cado Response Integration with Amazon GuardDuty using AWS Lambda

Cado Response Integration with Amazon GuardDuty using AWS Lambda This repository contains a simple example where: An alert is triggered by GuardDuty T

CDK Template of Table Definition AWS Lambda for RDB
CDK Template of Table Definition AWS Lambda for RDB

CDK Template of Table Definition AWS Lambda for RDB Overview This sample deploys Amazon Aurora of PostgreSQL or MySQL with AWS Lambda that can define

Universal Command Line Interface for Amazon Web Services

aws-cli This package provides a unified command line interface to Amazon Web Services. Jump to: Getting Started Getting Help More Resources Getting St

Python IMDB Docker - A docker tutorial to containerize a python script.

Python_IMDB_Docker A docker tutorial to containerize a python script. Build the docker in the current directory: docker build -t python-imdb . Run the

Cross-platform lib for process and system monitoring in Python
Cross-platform lib for process and system monitoring in Python

Home Install Documentation Download Forum Blog Funding What's new Summary psutil (process and system utilities) is a cross-platform library for retrie

Let's learn how to build, release and operate your containerized applications to Amazon ECS and AWS Fargate using AWS Copilot.

?? Welcome to AWS Copilot Workshop In this workshop, you'll learn how to build, release and operate your containerised applications to Amazon ECS and

Donnie Prakoso 15 Jul 14, 2022
Containerize a python web application

containerize a python web application introduction this document is part of GDSC at the university of bahrain you don't need to follow along, fell fre

abdullah mosibah 1 Oct 19, 2021
Build and Push docker image in Python (luigi + docker-py)

Docker build images workflow in Python Since docker hub stopped building images for free accounts, I've been looking for another way to do it. I could

Fabien D. 2 Dec 15, 2022
This is a tool to develop, build and test PHP extensions in Docker containers.

Develop, Build and Test PHP Extensions This is a tool to develop, build and test PHP extensions in Docker containers. Installation Clone this reposito

Suora GmbH 10 Oct 22, 2022
Build Netbox as a Docker container

netbox-docker The Github repository houses the components needed to build Netbox as a Docker container. Images are built using this code and are relea

Farshad Nick 1 Dec 18, 2021
This Docker container is build to run on a server an provide an easy to use interface for every student to vote for their councilors

This Docker container is build to run on a server and provide an easy to use interface for every student to vote for their councilors.

Robin Adelwarth 7 Nov 23, 2022
A tool to convert AWS EC2 instances back and forth between On-Demand and Spot billing models.

ec2-spot-converter This tool converts existing AWS EC2 instances back and forth between On-Demand and 'persistent' Spot billing models while preservin

jcjorel 152 Dec 29, 2022
A simple python application for running a CI pipeline locally This app currently supports GitLab CI scripts

?? Simple Local CI Runner ?? A simple python application for running a CI pipeline locally This app currently supports GitLab CI scripts ⚙️ Setup Inst

Tom Stowe 0 Jan 11, 2022
Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:

Latest Salt Documentation Open an issue (bug report, feature request, etc.) Salt is the world’s fastest, most intelligent and scalable automation engi

SaltStack 12.9k Jan 4, 2023
A honey token manager and alert system for AWS.

SpaceSiren SpaceSiren is a honey token manager and alert system for AWS. With this fully serverless application, you can create and manage honey token

null 287 Nov 9, 2022