2019-08-21
High Level Goals:
Create a demo project on GitHub and build it using Jenkins running in Docker all hosted on and AWS instance.
Pre-requisites:
You will need to have an AWS account and a GitHub account.
Software Downloads:
You will need to download Terraform. I was using v0.11.14 for this post.
Configuration Downloads:
GitHub Project
Procedure:
- Clone my example GitHub project
- Configure your AWS credentials and Key
- In provider.tf I look for credentials in ../credentials/credentials. Change to suit your environment
- In Variables.tf I set the ec2_keypair_name to HoN_DevOps_Walkthrough_1. Change this to refer to one of your keys.
- In Variables.tf; change aws_route53_zone.HON_Sandbox to an AWS Route53 domain you administer
- Run terraform apply to get the environment up and running
- Use a browser view Jenkins: http://‹jenkins.your.domain›:8080/
- Enter the Jenkins initialization password to get access to the admin interface. You can get this from either:
- /var/jenkins_home/secrets/initialAdminPassword in your Docker container, or
- As root in your AWS instance: grep -A1 "Please use the following password" /var/log/messages
- Create a new Jenkins administrator - we'll use this in the future.
- Install the default Jenkins configuration
- Add your GitHub credentials to Jenkins
- "Credentials" => "System" => "Global Credentials" => "Add Credentials"
- Configure Jenkins to build your clone of the example project
- New Item => Name your Jenkins job => "Freestyle project" => "OK"
- Enter a description for your new Jenkins Job; "Introduction to AWS/Docker/Jenkins and GitHub"
- Select "GitHub Project" and enter the URL to your clone of my example GitHub project into the "Project URL"
- Under "Source Code Management", Select "Git" and enter the URL to your clone of my example GitHub project into the Repository URL. Then select the credentials you entered earlier
- Under "Build Triggers", select "Poll SCM" and set the schedule to "H/5 * * * *"
- Under "Build", Select "Add build step", Select "Execute Shell", Enter "cd src; make all"
- Save the Job
Bonus Points:
- Implement with HTTPS
- Have the project build after a commit instead of having Jenkins poll GitHub looking for changes