This is a demo project for provisiong server, configuring server and deploying a backend app using Jenkins + Terraform + Ansible.
Notice: Docker image of the backend application is built automatically by Github Action.
Guide : https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-20-04
apt-get update && apt-get install -y ansible
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install terraform
This is a key used for connecting to AWS EC2 Instance provisioned using Terraform.
sudo su jenkins
ssh-keygen -f ~/.ssh/aws_key
This is a credential file for connecting to AWS services. This credential file is used by Terraform.
sudo su jenkins
mkdir ~/.aws
nano ~/.aws/credentials
And add the content below with the approriate values.
[default]
aws_access_key_id = <access_key>
aws_secret_access_key = <secret_key>
Install ansible
and terraform
plugins in Jenkins -> Manage Plugins -> Available
.
Confirm the installation directory for ansible/terraform binaries inside Jenkins server. Then set the tool name and the installation directory under Ansible/Terraform in Jenkins -> Manage Plugins -> Global Tool Configuration
.
Create a Pipeline job (New Item -> Pipeline
) and set Jenkinsfile under Pipeline script from SCM
.
Once a Pipeline job created, please build it. It will provision an AWS EC2 server and install everything, finally deploy the backend service.
The final stage Backend Url
of the pipeline should show the backend url. Then open it on web browser.