{"id":22636504,"url":"https://github.com/mrdvince/koko","last_synced_at":"2026-04-11T04:32:11.014Z","repository":{"id":106601733,"uuid":"446079971","full_name":"mrdvince/koko","owner":"mrdvince","description":"Using Terraform to provision AWS resources \u0026 Ansible to deploy a Docker container","archived":false,"fork":false,"pushed_at":"2022-01-11T18:55:19.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-14T14:51:44.910Z","etag":null,"topics":["ansible","aws","docker","jenkins","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrdvince.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-09T12:20:24.000Z","updated_at":"2022-01-11T16:28:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"d06b1f84-84be-4329-b2ee-680b265e18c1","html_url":"https://github.com/mrdvince/koko","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mrdvince/koko","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdvince%2Fkoko","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdvince%2Fkoko/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdvince%2Fkoko/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdvince%2Fkoko/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrdvince","download_url":"https://codeload.github.com/mrdvince/koko/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdvince%2Fkoko/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31669114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T17:19:37.612Z","status":"online","status_checked_at":"2026-04-11T02:00:05.776Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","aws","docker","jenkins","terraform"],"created_at":"2024-12-09T03:22:02.042Z","updated_at":"2026-04-11T04:32:10.994Z","avatar_url":"https://github.com/mrdvince.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker image deployment, using ansible\n\nUsing terraform to provision AWS resources, and deploy a simple flask app using ansible.\n\n# TOC\n\n- [Docker image deployment, using ansible](#docker-image-deployment--using-ansible)\n- [Getting started](#getting-started)\n- [Dependencies](#dependencies)\n- [Docker image](#docker-image)\n- [AWS resource provisioning](#aws-resource-provisioning)\n- [Ansible](#ansible)\n- [Jenkins](#jenkins)\n- [Jenkins \u0026 Ansible](#jenkins---ansible)\n\n# Getting started\n\nThe project is broken down into:\n\n- Buld docker image and push to docker hub\n- Provision AWS resources using terraform\n- Use ansible to install docker in the ec2 instances and run the image pulled from docker hub\n- Setup jenkins to build and push new containers to docker hub and deploy to the instances\n\n# Dependencies\n\nTo set up your environment to run the code in this repository, you need to have terraform, ansible and jenkins installed.\n\nInstallation links:\n\n- Terraform https://www.terraform.io/downloads\n- Ansible https://docs.ansible.com/ansible/latest/installation_guide/index.html\n\n# Docker image\n\n1. Login to docker hub\n\nOr any other registry of choice\n\nBuild the docker image, tag and push to the registry. This is the image to be deployed using ansible.\n\n```bash\ndocker login\n```\n\n# AWS resource provisioning\n\n1. Clone the repository and navigate to the terraform folder\n\n```bash\n# clone the repository\ngit clone https://github.com/mrdvince/koko.git\n\n# the terraform directory\ncd iac-modules/terraform\n```\n\n\u003e for convinience using terraform login it using the `aws cli` this way you don't have to provide the aws access keys to terraform\n\n```bash\n# will walk you through the steps of setting it up\naws configure\n```\n\n2. Setup\n\n- EC2 instances\n  The current configuration is set up to create 2 instances with the ability to scale up to a max of 3 instaces if there's a sustained cpu load above 20% for 2 minutes.\n\nThese should be modified to suit you needs (e.g 20% load is not much, increase it to around 90%)\n\n- Load balancing\n\nA load balancer is also configured to include the instances and route traffic accordingly to them\n\nthe load balancer and the instances use separate AWS security groups so feel free to play around with that as well\n\n3. Terraform apply\n\nOnce satisfied with the config, run `terraform apply` to create all the resources and in about 4mins everything should be set up\n\nTest the instance by trying to ssh using your ssh key.\n\n```bash\n# check the changes terraform is going to make\nterraform plan\n# apply the config\nterraform apply\n\n# try to ssh to the instance\nssh -i \u003cyour key here\u003e ubuntu@\u003cinstance ip\u003e\n```\n\nYou can also check the aws console to verify if everything is setup correctly\n\n# Ansible\n\nInside the ansible directory there are two playbooks, one for installing docker and the other deploys the application.\n\n1. Update the inventory\n\nThe file has a list of instance, this is the list ansible is going to use to deploy the image.\n\n2. Ping the instances\n\nCheck if ansible can communicate with the instances.\n\n```bash\n ansible all -m ping\n```\n\n3.  Install docker\n\nRun the install docker playbook, this will go ahead and install docker in all the instances in the inventory list\n\n```bash\nansible-playbook playbooks/install-docker.yaml\n```\n\n4.  Deploy the app\n\nRun the `deploy_app.yaml` playbook to pull the image from docker hub and deploy it to all the instances.\n\n\u003e Since the instances are behind a load balancer this will take care of routing the traffic to them.\n\n```bash\nansible-playbook playbooks/deploy_app.yaml\n```\n\n\u003e visit the load balancer's dns name, should have been printed to the screen when terraform finished running, alternatively this can be found on the console.\n\n# Jenkins\n\n1. Fetch the war file from jenkins website and run it\n\n```bash\njava -jar jenkins.war\n```\n\nVisit `http://localhost:8080/` and go through the initial setup guide, which entails creating a new user etc.\n\n2. Install docker plugins\n\nIn order to be able to build the containers and push them to the registry a few extra set up steps are required.\n\nHead over to `Manage Jenkins` then `Manage Plugins` under `available` search for docker and install\n\n- Docker plugin\n- Docker Pipeline\n- CloudBees Docker Build and Publish plugin\n\nthis will add more options to the build steps in the project\n\n3. New Item\n\n- Go back to the dashboard and create a `New Item` and select `Freestyle project`\n- Add a description of your choice (what the project is about)\n- Select Github project option and provide the project url\n- Under `Source Code Management` select git and provide the git url, (if it's a private github project credentials are also required)\n- Next add a build step and select `Docker build and Publish` and fill the fields, docker hub credentials are also needed if using docker hub, if the fields are left empty the defaults are used. Attached screenshot.\n\n![jenkins](screenshots/jenkins.png)\n\n- finally apply, save and build.\n\n\u003e Build Triggers can also be setup based on once's choice. I went with `Poll SCM` every minute `* * * * *`\n\n# Jenkins \u0026 Ansible\n\nWIP\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdvince%2Fkoko","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdvince%2Fkoko","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdvince%2Fkoko/lists"}