diff --git a/examples/custom-image/README.md b/examples/custom-image/README.md index dbd95bd..794c9df 100644 --- a/examples/custom-image/README.md +++ b/examples/custom-image/README.md @@ -5,16 +5,18 @@ 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 (`/.json`)**: Specifies the instance details for the cloud provider. @@ -22,12 +24,43 @@ This script automates the creation of a custom image on a public 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 / 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 / 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 - eg: ./build-custom-image.sh aws + ```bash + cd examples/custom-image + ./build-custom-image.sh + + 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 +``` diff --git a/examples/custom-image/cloud/aws/packer.json b/examples/custom-image/cloud/aws/packer.json index 23fee93..8eebe65 100644 --- a/examples/custom-image/cloud/aws/packer.json +++ b/examples/custom-image/cloud/aws/packer.json @@ -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" + ] + } + ] } diff --git a/examples/custom-image/files/user-data b/examples/custom-image/files/user-data new file mode 100644 index 0000000..cec0f3b --- /dev/null +++ b/examples/custom-image/files/user-data @@ -0,0 +1,4 @@ +#cloud-config +stylus: + path: /var/lib/spectro + installationMode: airgap