This project demonstrates how to create a continuous integration pipeline such that if a change is made to the repository, updates are automatically built and pushed to the ec2 instance.
Working knowledge of CICD, aws, a code editor.
- In your security group inboud rules setting, open ssh for port 22 - custom and open tcp for port 80 - anywhere
- Allocate an elastic IP address to your instance to provide you with a static ip (optional)
git clone <REPO_URL>
sudo ssh -i "yourkeypairname.pem" instancetype@instancepubliciddress.region.compute.amazonaws.com
If you do not understand the above, the below is an example
sudo ssh -i "cicdkey.pem" ubuntu@ec3-4-5-22-13.us-east-1.compute.amazonaws.com
NB: ensure you are in the directory where your key pair is present.
Push the project to github and in the settings tab, select Actions >> Runners >> Then create a new self-hosted runner
After creating the self-hosted runner, select the runner image depending on what kind of instance you created, the copy and paste all the commands under Download
to your ec2 instance which you have sshed into
Once you have copied and pasted the Download
commands, copy and past the Configure
commands as well
After setup, some specifics in the project need to be installed for the runner to do its work. If you ls
you would see the files that the runner presently contains.
sudo ./svc.sh install
After installing in, start it
sudo ./svc.sh start
This command automatically connects your project with Github/the repo.
The workflow for this project has already been setup but if you would like to set it up your own, delete the maven.yml
file.
Navigate to actions tab on the in the repository and select Java with Maven
.
Inside the workflow, in jobs >> builds >> runs-on, change ubuntu-latest
to self-hosted
because we are using a self-hosted runner. You can take out the pull_request: branches
since it is not necessary, then commit.
Jdk needs to be installed in the instance. In the actions-runner directory, ```cd`` and update pacakages first
sudo apt update
Then
sudo apt install maven openjdk-11-jre openjdk-11-jdk
With dependencies in place, builds made will run and be visble on github
You can check your instance ip address to view the site.