Skip to content

Commit

Permalink
Merge pull request #5 from marlapativ/feat/a1/caddyversion
Browse files Browse the repository at this point in the history
Caddy Version Fix + ZeroSSL Setup
  • Loading branch information
marlapativ authored May 30, 2024
2 parents 58e97d6 + 6d24565 commit 2021454
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 26 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 .
10 changes: 5 additions & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .'
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
1 change: 1 addition & 0 deletions jenkins.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-caddy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion scripts/install-jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions scripts/setup-caddy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 8 additions & 4 deletions variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ variable "source_ami" {
default = "ami-0a24670a6532ea110"
}

variable "domain" {
type = string
}

variable "ssh_username" {
type = string
default = "ubuntu"
Expand All @@ -38,3 +34,11 @@ variable "ami_description" {
type = string
default = "Jenkins with caddy on Ubuntu LTS"
}

variable "domain" {
type = string
}

variable "email" {
type = string
}

0 comments on commit 2021454

Please sign in to comment.