CDK App to set up a Jenkins node to AWS. Currently a single node setup.
- Nodejs v.18.*
- AWS CLI v2 configured to an account
First run npm i
to install project dependencies.
Copy .env.example
file to project root as .env
and fill in all values. AWS region and account id must be correct according to your aws-cli setup. Other values are attributes to the created resources.
Available commands:
npm run build
compile typescript to jsnpm run test
perform the jest unit testsnpm run synth
emits the synthesized CloudFormation templatenpm run diff
compare deployed stack with current statenpm run deploy
deploy this stack to your AWS account/regionnpm run destroy
destroys the deployed stack
After a successful deployment the output contains the public ip address of the provisioned EC2 instance. Then you need the private key for the EC2 keypair that is created during the deployment.
The deploy process writes details of the deployment to an output file jenkins-cdk-outputs.json
like this
{
"JenkinsCdkStack": {
"sshConnect": "ssh -i keys/<keyname>.pem -o IdentitiesOnly=yes ec2-user@<ip>",
"instanceId": "<instance_id>",
"publicIp": "<public_ip>",
"getPemFile": "aws secretsmanager get-secret-value...",
"keyPairName": "<keypair_name>"
}
}
In order to connect to the created EC2 instance, you need to get the pem file using the command named getPemFile
and then use the pem file when creating an ssh connection with the command named sshConnect
.
- Ansible
- pem file created with the
getPemFile
command fromjenkins-cdk-outputs.json
When the infra is created its time to set up the state of the machine. This part uses Ansible. The deploy process should create a variable file in ansible/host_vars
with the EC2 instance details. Test the setup by running
ansible-playbook -i ansible/inventory.yaml ansible/playbook.yaml