From f92bf774ea8e6b499f5840da682256438f9acd85 Mon Sep 17 00:00:00 2001 From: yashwanth170 Date: Wed, 29 May 2024 20:13:19 -0400 Subject: [PATCH 1/6] Adding packer file for building Jenkins AMI --- .DS_Store | Bin 0 -> 6148 bytes jenkins-config.json | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .DS_Store create mode 100644 jenkins-config.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..caf709ec3bdbe5984d2c1847877e5536ee4cce75 GIT binary patch literal 6148 zcmeHKF;2r!47F*5BC&L2{3k%_4L()6vGoEdR4SlW=>QW;wqA>gGjJIsp6w4x6qS(y zo+ba6Z~NsZZ-`?N(dF}IAu<<{8g3{@Tc&1t^NF36NCi~8$8Nh=-*x-Lr1EsYxRqSV zRvzSO%zr!|=Js9Fw7afFtbTdFX+LIf*W>)=$Nb@b@ND`DDvb(I0V+TRsKCEe06p8R zz6j(>1*iZO_*THa4+(CV3-*Ej>A>P60MLHp-Ei%*1Ta|um<#rSh`=x%@m37$r@vTNjX!9LLGh&vs~9|6;aMg@LD Ffln Date: Wed, 29 May 2024 20:16:33 -0400 Subject: [PATCH 2/6] Adding script file to intall jenkins, nginx --- .DS_Store | Bin 6148 -> 6148 bytes script.sh | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 script.sh diff --git a/.DS_Store b/.DS_Store index caf709ec3bdbe5984d2c1847877e5536ee4cce75..a29efc999b3153e21ea5a6957f29b009122a989e 100644 GIT binary patch delta 113 zcmZoMXfc?uEVke|0|NsKgC0XVLncE>ZoZ34QcivnP>h3tp+WE;^D#$M`4qhJ1sR6H c$@#ejKs^i$Oa_|;8NabjEa2PB&heKY08X /dev/null +echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null +sudo apt-get update +sudo apt-get install -y jenkins +sudo apt-get install -y nginx +sudo apt-get install -y nginx certbot python3-certbot-nginx +sudo systemctl enable jenkins +sudo systemctl enable nginx From a12d60539f2e8969c369b75df167621e40ab06e4 Mon Sep 17 00:00:00 2001 From: yashwanth170 Date: Wed, 29 May 2024 20:21:16 -0400 Subject: [PATCH 3/6] Setting up CI/CD --- .DS_Store | Bin 6148 -> 6148 bytes .github/workflows/packer.yml | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 .github/workflows/packer.yml diff --git a/.DS_Store b/.DS_Store index a29efc999b3153e21ea5a6957f29b009122a989e..446f0ae2080987c7a84f05257e26bd0c06638f8a 100644 GIT binary patch delta 330 zcmZoMXfc=|#>B)qF;Q%yo+2a1!~pBf3XBbmKvs`beYq(E0|N_#9z!}qCPPVXzKcsz zPJR+lj01>^{xKhOM3qm0%S%hlC_tAl$S@2}&d)6X>S17D0#lp}))P(T8336!dduLqBxL2fMK%`<71Z1>>T_Yz!2Ij c$oQRkGQWtS03*;v4L}T}K}?3t0U}$N0S+}v4*&oF delta 158 zcmZoMXfc=|#>CJ*F;Q%yo+2a5!~knXmdQL!Qn3Zk85kH?81xv@88R74a`RnWl5+Bs zfMOgB3=M++n2$N4%BSF!FUT+qPR`FQ0P102U^3Wj$b5}uvjejp(`I%Keh#1mfFj?S UC-aLKGBQlI;gQ}PBeH@S0ENFK@&Et; diff --git a/.github/workflows/packer.yml b/.github/workflows/packer.yml new file mode 100644 index 0000000..1167d06 --- /dev/null +++ b/.github/workflows/packer.yml @@ -0,0 +1,51 @@ +name: Build Jenkins AMI + +on: + push: + branches: + - main # Change this to the branch you want to trigger the workflow + +jobs: + packer: + name: Build AMI with Packer + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Packer + uses: hashicorp/setup-packer@v2 + with: + packer_version: latest + + - name: Install amazon plugin for packer + run: | + packer plugins install github.com/hashicorp/amazon + + - name: Install AWS CLI + run: | + sudo apt-get update + sudo apt-get install -y awscli + + - name: Configure AWS Credentials + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + run: | + mkdir -p ~/.aws + echo "[default]" > ~/.aws/credentials + echo "aws_access_key_id=${{ secrets.AWS_ACCESS_KEY_ID }}" >> ~/.aws/credentials + echo "aws_secret_access_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> ~/.aws/credentials + + - name: Run Packer Build + env: + AWS_PROFILE: ${{ secrets.AWS_PROFILE }} + run: | + packer build -var "region=${{ secrets.AWS_DEFAULT_REGION }}" \ + -var "source_ami=ami-04b70fa74e45c3917" \ + -var "instance_type=t2.micro" \ + -var "profile=${{ secrets.AWS_PROFILE }}" \ + -var "ssh_username=ubuntu" \ + jenkins.json From 27795940f670eb4888c801cf95bf889e7c64a3da Mon Sep 17 00:00:00 2001 From: Yashwanth Pokala <114684619+yashwanth170@users.noreply.github.com> Date: Wed, 29 May 2024 20:24:36 -0400 Subject: [PATCH 4/6] Updated packer.yml --- .github/workflows/packer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/packer.yml b/.github/workflows/packer.yml index 1167d06..4b7fca7 100644 --- a/.github/workflows/packer.yml +++ b/.github/workflows/packer.yml @@ -48,4 +48,4 @@ jobs: -var "instance_type=t2.micro" \ -var "profile=${{ secrets.AWS_PROFILE }}" \ -var "ssh_username=ubuntu" \ - jenkins.json + jenkins-config.json From c77f9bb75f7ebb8ed8c1bbe6b8583e4f498b2be0 Mon Sep 17 00:00:00 2001 From: Yashwanth Pokala <114684619+yashwanth170@users.noreply.github.com> Date: Wed, 29 May 2024 20:38:51 -0400 Subject: [PATCH 5/6] Update packer.yml --- .github/workflows/packer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/packer.yml b/.github/workflows/packer.yml index 4b7fca7..64a0fad 100644 --- a/.github/workflows/packer.yml +++ b/.github/workflows/packer.yml @@ -41,11 +41,11 @@ jobs: - name: Run Packer Build env: - AWS_PROFILE: ${{ secrets.AWS_PROFILE }} + AWS_PROFILE: default run: | packer build -var "region=${{ secrets.AWS_DEFAULT_REGION }}" \ -var "source_ami=ami-04b70fa74e45c3917" \ -var "instance_type=t2.micro" \ - -var "profile=${{ secrets.AWS_PROFILE }}" \ + -var "profile=default" \ -var "ssh_username=ubuntu" \ jenkins-config.json From e22fc636bc679b591963f16e0b823ae6cc232868 Mon Sep 17 00:00:00 2001 From: Yashwanth Pokala <114684619+yashwanth170@users.noreply.github.com> Date: Wed, 29 May 2024 23:00:34 -0400 Subject: [PATCH 6/6] Update README.md --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee962df..a19a53e 100644 --- a/README.md +++ b/README.md @@ -1 +1,37 @@ -# ami-jenkins \ No newline at end of file +# Packer Configuration for Building Jenkins Server AMI + +This repository contains a Packer configuration file (`jenkins-config.json`) and a shell script (`script.sh`) to build an Amazon Machine Image (AMI) for a Jenkins server on AWS using Packer. + +## Prerequisites + +Before you begin, ensure you have the following prerequisites installed: + +- [Packer](https://www.packer.io/downloads) +- AWS IAM credentials with permissions to create EC2 instances and AMIs + +## Usage + +### 1. Configure Variables + +Open `jenkins-config.json` in a text editor and customize the following variables as needed: + +- `region`: The AWS region where the AMI will be created. +- `source_ami`: The ID of the base AMI to use as the source. +- `instance_type`: The EC2 instance type to use for building the AMI. +- `profile`: The AWS profile to use for authentication (optional). +- `ssh_username`: The username used to SSH into the EC2 instance. + +### 2. Build the AMI + +Run the following command to build the AMI: + +```bash +packer build jenkins-json.json + +The script file (`script.sh`) installs the following software on the Amazon Machine Image (AMI) during the provisioning process: + +- **curl**: Command-line tool for transferring data with URLs. +- **OpenJDK 17**: Java Runtime Environment required for Jenkins. +- **Jenkins**: Automation server for continuous integration and continuous delivery (CI/CD). +- **Nginx**: Web server used for reverse proxying to Jenkins and handling SSL. +- **Certbot**: Tool for automatically enabling HTTPS on your server using Let's Encrypt certificates.