Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions examples/custom-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,62 @@ This script automates the creation of a custom image on a public cloud provider
## Prerequisites

1. **Dependencies**

- Bash (Unix/Linux environment)
- Packer CLI (https://developer.hashicorp.com/packer/install?product_intent=packer)

2. **Access and Credentials**

- Ensure valid credentials for your target cloud provider.
- For AWS, configure the `aws_access_key` and `aws_secret_key` in the configuration file i.e. custom-image-config.
- Permissions to create and manage images for the chosen cloud provider.

3. **Configuration File**
- **Global Configuration (`custom-image-config`)**:
- **Global Configuration (`custom-image-config`)**:
Contains details about the cloud provider's credentials.
- **Cloud-Specific Configuration (`<cloud-provider>/<os-version>.json`)**:
Specifies the instance details for the cloud provider.

## Usage

1. Prepare the Configuration Files:
Create the custom-image-config file in the project root directory with the required credentials.
Add the appropriate cloud-specific configuration file in the <cloud-provider>/ directory
Create the custom-image-config file in the project root directory with the required credentials.
Add the appropriate cloud-specific configuration file in the <cloud-provider>/ directory

2. Run the Build Script: Execute the build-custom-image.sh script with the desired cloud provider:
```bash
cd examples/custom-image
./build-custom-image.sh <cloud provider>

eg: ./build-custom-image.sh aws
```bash
cd examples/custom-image
./build-custom-image.sh <cloud provider>

eg: ./build-custom-image.sh aws
```

## Adding default userdata

1. Create `user-data` file in the `files` directory.
2. An example of `user-data` file is as follows:

```yaml
#cloud-config
stylus:
path: /var/lib/spectro
installationMode: airgap
```

Refer to [Palette Agent Parameters Documentation](https://docs.spectrocloud.com/clusters/edge/edge-configuration/installer-reference/#palette-agent-parameters) for more details.

## Adding preloaded content in your image

1. Add your content bundle in the `files` directory.
2. In your userdata, add following stages to copy the content bundle to the desired location. Suppose your content bundle is named as content.zst

```yaml
#cloud-config
stages:
after-install:
- name: Extract content bundle
if: "[ -f /tmp/files/content.zst ]"
commands:
- $STYLUS_ROOT/opt/spectrocloud/bin/palette-agent content-extract --source /tmp/files/content.zst
```
81 changes: 44 additions & 37 deletions examples/custom-image/cloud/aws/packer.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
{
"builders": [{
"type": "amazon-ebs",
"region": "{{ user `aws_region` }}",
"source_ami": "{{user `source_ami`}}",
"instance_type": "{{user `builder_instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "{{user `ami_name`}}",
"source_ami_filter": {
"filters": {
"architecture": "x86_64",
"name": "{{user `ami_filter_name`}}",
"root-device-type": "ebs",
"virtualization-type": "hvm"
"builders": [
{
"type": "amazon-ebs",
"region": "{{ user `aws_region` }}",
"source_ami": "{{user `source_ami`}}",
"instance_type": "{{user `builder_instance_type`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "{{user `ami_name`}}",
"source_ami_filter": {
"filters": {
"architecture": "x86_64",
"name": "{{user `ami_filter_name`}}",
"root-device-type": "ebs",
"virtualization-type": "hvm"
},
"most_recent": true,
"owners": "{{user `ami_filter_owners`}}"
},
"most_recent": true,
"owners": "{{user `ami_filter_owners`}}"
},
"vpc_id": "{{ user `vpc_id` }}",
"subnet_id": "{{ user `subnet_id` }}"
}],
"vpc_id": "{{ user `vpc_id` }}",
"subnet_id": "{{ user `subnet_id` }}"
}
],

"provisioners": [
{
"type": "shell",
"inline": [
"set -e",
"sudo apt update -y || (echo 'APT Update Failed'; exit 1)",
"sudo apt install -y bash systemd rsync rsyslog jq zstd conntrack systemd-timesyncd || (echo 'APT Install Failed'; exit 1)"
]
},
{
"type": "shell",
"inline": [
"curl -fsSL -o /tmp/palette-agent-install.sh https://github.com/spectrocloud/agent-mode/releases/latest/download/palette-agent-install.sh",
"chmod +x /tmp/palette-agent-install.sh",
"sudo /tmp/palette-agent-install.sh"
]
}
]
"provisioners": [
{
"type": "shell",
"inline": [
"set -e",
"sudo apt update -y || (echo 'APT Update Failed'; exit 1)",
"sudo apt install -y bash systemd rsync rsyslog jq zstd conntrack systemd-timesyncd || (echo 'APT Install Failed'; exit 1)"
]
},
{
"type": "file",
"source": "files",
"destination": "/tmp"
},
{
"type": "shell",
"inline": [
"curl -fsSL -o /tmp/palette-agent-install.sh https://github.com/spectrocloud/agent-mode/releases/latest/download/palette-agent-install.sh",
"chmod +x /tmp/palette-agent-install.sh",
"sudo -E USERDATA=/tmp/files/user-data /tmp/palette-agent-install.sh"
]
}
]
}
4 changes: 4 additions & 0 deletions examples/custom-image/files/user-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#cloud-config
stylus:
path: /var/lib/spectro
installationMode: airgap
Loading