Skip to content

A Playbook which can be used with Jenkins to automate Docker image creation and its associated testing section.

Notifications You must be signed in to change notification settings

ManuGeorge96/ansible-docker-git-jenkins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Generic badge

ansibe-docker-git

About

An Ansible Playbook which can be used for Building a docker image, Pushing and to Test the image with a docker container. Advantage of using this playbook is if there is any new commits on Git repo, the playbook will initiate the above tasks. The Playbook is designed in such a way,that the build operations are done on one server and Testing operations on another server.

Outline

  • main.yml

    • Setting Fact Values.
    • Calling tasks, Build and Test based on the condition.
  • build.yml

    • Fetching new codes from Git.
    • Creating Docker Image.
    • Taging and Pushing Image to Docker Registry.
  • test.yml

    • Pull the latest image from the Docker registry, if only there is a new update.
    • Create Docker container with the new image, else task will get skiped.

Unix

Prerequisites

  • The git repo must have Docker file and the code section( if needed).
  • Idea about configuring Tasks on Jenkins.
  • Add Webhook on Git.

To Use The Playbook

For Running the Playbook Manually

  •  git clone https://github.com/ManuGeorge96/ansible-docker-git-jenkins.git
  •   cd  ansible-docker-git-jenkins
  • Setting Up Inventory File
    • Include below line on the hosts file, commend out the existing lines on the file ( edit credentials )
      •  [Build]
         build ansible_host=WP_SERVER_IP_HERE ansible_user=SSH_USER_ON_SERVER ansible_ssh_port=SSH_PORT ansible_ssh_private_key_file=PATH_TO_PRIVATE_KEY
         [Test]
         test ansible_host=DB_SERVER_IP_HERE ansible_user=SSH_USER_ON_SERVER ansible_ssh_port=SSH_PORT ansible_ssh_private_key_file=PATH_TO_PRIVATE_KEY
  • Edit Required Data's on main.yml file.
      docker_user: DOCKER_REGISTRY_USER_HERE
      docker_pass: DOCKER_REGISTRY_PASSWORD_HERE
      repo: GIT_REPO_URL
      image_name: IMAGE_NAME
      ct_name: CONTAINER_NAME
      ct_publish_port: PUBLISH_PORT
      ct_port: CONTIANER_PORT
  •    ansible-playbook -i hosts main.yml

Sample Output from Jenkins

Unix Unix Unix Unix

About

A Playbook which can be used with Jenkins to automate Docker image creation and its associated testing section.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published