From 6d24565340eb77fe342a6cbc2749795c24a5764b Mon Sep 17 00:00:00 2001 From: "Marlapati Venkata Naga Sai Teja[marlapativ]" Date: Wed, 29 May 2024 22:50:49 -0400 Subject: [PATCH] Caddy Version Fix + ZeroSSL Setup --- .github/workflows/release.yml | 16 ++++++++-------- .github/workflows/validate.yml | 10 +++++----- README.md | 13 ++++++++----- jenkins.pkr.hcl | 1 + scripts/install-caddy.sh | 2 +- scripts/install-jenkins.sh | 2 +- scripts/setup-caddy.sh | 13 +++++++++++-- variables.pkr.hcl | 12 ++++++++---- 8 files changed, 43 insertions(+), 26 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1d60e94..f448b24 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,8 +9,8 @@ jobs: create-image: runs-on: ubuntu-latest permissions: - contents: 'read' - id-token: 'write' + contents: 'read' + id-token: 'write' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} @@ -26,19 +26,19 @@ jobs: - name: Packer init id: init - run: "packer init ." + run: 'packer init .' - name: Packer fmt check id: fmt - run: "packer fmt -check ." + run: 'packer fmt -check .' - name: Packer validate id: validate - run: "packer validate -syntax-only -evaluate-datasources ." + run: 'packer validate -syntax-only -evaluate-datasources .' - name: Packer build env: - # TODO: Is this alright? - PACKER_BUILD_ARGS: ${{ secrets.PACKER_BUILD_ARGS }} + PKR_VAR_domain: ${{ secrets.PKR_VAR_domain }} + PKR_VAR_email: ${{ secrets.PKR_VAR_email }} id: build - run: packer build -color=false -var "${PACKER_BUILD_ARGS}" . + run: packer build -color=false . diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ff75818..9a1bf79 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -2,12 +2,12 @@ name: Packer Validate on: pull_request: - branches: + branches: - main jobs: validate: - runs-on: ubuntu-latest + runs-on: ubuntu-latest steps: - name: Checkout repository @@ -20,12 +20,12 @@ jobs: - name: Packer init id: init - run: "packer init ." + run: 'packer init .' - name: Packer fmt check id: fmt - run: "packer fmt -check ." + run: 'packer fmt -check .' - name: Packer validate id: validate - run: "packer validate -syntax-only -evaluate-datasources ." + run: 'packer validate -syntax-only -evaluate-datasources .' diff --git a/README.md b/README.md index 1aa73be..dfbed5f 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,15 @@ Once Packer is initialized, you can build the custom image using the provided `. To build the image, run the following command in your terminal: - PACKER_BUILD_ARGS="domain=example.com" # Update with your domain - packer build -color=false -var "${PACKER_BUILD_ARGS}" . + export PKR_VAR_domain="example.com" # Update with your domain + export PKR_VAR_email="email@example.com" # Update with your email + packer build -color=false . -The `-var` flag allows you to pass variables to the build process. +In case you don't want to export the above variables, use the `-var` flag, it allows you to pass variables to the build process. Required variables are: - `domain` - The domain name to create SSL certificates for. +- `email` - The email address to use for ZeroSSL certificates. ## CI/CD Pipeline @@ -50,5 +52,6 @@ Required secrets for CI/CD pipeline are: - `AWS_ACCESS_KEY_ID` - The AWS access key ID. - `AWS_SECRET_ACCESS_KEY` - The AWS secret access key. -- `PACKER_BUILD_ARGS` - The build arguments for Packer. - - `domain` - The domain name to create SSL certificates for. +- PACKER Variables: + - `PKR_VAR_domain` - The domain name to create SSL certificates for. + - `PKR_VAR_email` - The email address to use for ZeroSSL certificates. diff --git a/jenkins.pkr.hcl b/jenkins.pkr.hcl index a1c4a44..0511abd 100644 --- a/jenkins.pkr.hcl +++ b/jenkins.pkr.hcl @@ -15,6 +15,7 @@ build { execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'" environment_vars = [ "DOMAIN=${var.domain}", + "EMAIL=${var.email}", ] scripts = [ "scripts/install-dependencies.sh", diff --git a/scripts/install-caddy.sh b/scripts/install-caddy.sh index d2624d9..c1d5efc 100644 --- a/scripts/install-caddy.sh +++ b/scripts/install-caddy.sh @@ -18,6 +18,6 @@ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo # Install Caddy sudo apt-get update -sudo apt-get install -y caddy +sudo apt-get install -y caddy=2.7.6 echo "Caddy installation complete" diff --git a/scripts/install-jenkins.sh b/scripts/install-jenkins.sh index dc605a9..0e9ac7e 100644 --- a/scripts/install-jenkins.sh +++ b/scripts/install-jenkins.sh @@ -20,7 +20,7 @@ echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \ # Install Jenkins sudo apt-get update -sudo apt-get install -y jenkins +sudo apt-get install -y jenkins=2.452.1 # Start Jenkins service sudo systemctl start jenkins diff --git a/scripts/setup-caddy.sh b/scripts/setup-caddy.sh index 4783255..9d4fea0 100644 --- a/scripts/setup-caddy.sh +++ b/scripts/setup-caddy.sh @@ -5,14 +5,23 @@ # Check if domain is provided if [ -z "$DOMAIN" ]; then - echo "Env variable '\$Domain' not provided." + echo "Env variable '\$DOMAIN' not provided." exit 1 fi -echo "Setting up Caddy for domain: $DOMAIN" +if [ -z "$EMAIL" ]; then + echo "Env variable '\$EMAIL' not provided." + exit 1 +fi + +echo "Setting up Caddy for domain: $DOMAIN with email: $EMAIL" sudo mkdir -p /etc/caddy cat << EOF > /etc/caddy/Caddyfile +{ + # acme_ca https://acme-staging-v02.api.letsencrypt.org/directory + email $EMAIL +} $DOMAIN { reverse_proxy localhost:8080 } diff --git a/variables.pkr.hcl b/variables.pkr.hcl index ace817a..738fae6 100644 --- a/variables.pkr.hcl +++ b/variables.pkr.hcl @@ -25,10 +25,6 @@ variable "source_ami" { default = "ami-0a24670a6532ea110" } -variable "domain" { - type = string -} - variable "ssh_username" { type = string default = "ubuntu" @@ -38,3 +34,11 @@ variable "ami_description" { type = string default = "Jenkins with caddy on Ubuntu LTS" } + +variable "domain" { + type = string +} + +variable "email" { + type = string +}