Skip to content

ihalloum/jokes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About jokes Project:

This project includes:

  • Python api to connect with bash.org.pl/text and get jokes as text format then it will paress text to find jokes and return 100 jokes in json format.
  • Python Tests to perform unit tests.
  • Terraform files to create AWS infrastructure which contains VPC, public subnet, security group, internet gateway, route table, key pair and  EC2.- Ansible playbook to update and upgrade packages, install Docker and install Jenkins on EC2.
  • Dockerfile to build development and production images for our project.
  • Jenkinsfile for CI/CD process which builded when triggered from push request to git repository and contains:
    1. Build Development Image stage: triggered from push request to dev branch and it builds development docker image for our project and pushes it to GitHub registry.
    2. Unit Test stage: triggered from push request to dev branch and it runs Unit test on development image instance.
    3. Deploy to Development stage: triggered from push request to dev branch and it runs container from development image at port 5000 for testing.
    4. Build Production Image: triggered from push request to main branch, after testing and when merge to main it builds production image from main branch and pushes it to GitHub registry.
    5. Deploy to Production stage: triggered from push request to main branch and it runs container from production image at port 80.

Configure infrastructure:

We will need a machine to execute terraform and ansible commands and we will call it the control machine.

  1. Install Ansible, terraform and git on the control machine. Install Ansible on ubuntu 20 / Install Terraform on ubuntu 20

  2. Generate control machine ssh keys.

    ssh-keygen

  3. Fork repository to your GitHub account.

  4. Clone the repository from your account.

    git clone your_github_repo

  5. Edit the terraform/vars.tf file and add aws_access_key , aws_secret_key and ansible_public_key (control machine public key).

  6. Change directory to terraform and run these commands:

    terraform init

    terraform plan -out terraform.out

    terraform apply "terraform.out"

    Those commands will create our AWS infrastructure for our project.

  7. Execute terraform show | grep public_ip to detect EC2 public ip and will put it on /etc/ansible/hosts and name it jokes_ec2.

  8. Change directory to ansible and launch ansible playbook to configure EC2 instance.

    ansible-playbook setup_EC2.yaml

Configure Jenkins:

  1. The last task of the playbook will print the initial admin password for jenkins, use it to setup the jenkins by this URL EC2_public_ip:8080.
  2. Install docker and docker pipeline plugins which will be used to push images to the github container registry, from Manage Jenkines -> Manage Plugins.
  3. Create a pipeline from a new item and choose a pipeline after that:
    • Check GitHub project and enter project URL.
    • Check GitHub hook trigger for GITScm polling.
    • In the pipeline section choose pipeline script from SCM and choose git as SCM also add credentials for github account.
    • clear the Branch Specifier field.
    • unchesk Lightweight checkout.
  4. On Github account create:
    • Webhook and add this url http://jenkins_ip:8080/github-webhook/ and choose application/json as a content type.
    • Generate a new personal access token with upload packages to GitHub Package Registry privilege.
  5. Add the personal access token to jenkins credentials and name it ghcr.
  6. Edit Jenkinsfile and change environment variables devImage and prodImage.

Notes:

  1. The Jenkins pipeline will be build only when you push to dev or main branches.
  2. When you merge dev to master use no fast forward (--no-ff) parameters to force Jenkins to build the CD stages.A new commit is necessary because otherwise Jenkins might discard the job if another one has already run for the current commit.
  3. When you build the pipeline from jenkins webapp it will rebuild the last commit so if this commit to dev it will run dev stages and if it for main branch it will run prod stages.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published