Class UserDataBuilderImpl

java.lang.Object
com.cloudforgeci.api.core.UserDataBuilderImpl
All Implemented Interfaces:
UserDataBuilder

public class UserDataBuilderImpl extends Object implements UserDataBuilder
Implementation of UserDataBuilder that generates bash commands for EC2 UserData scripts.

This class encapsulates the complex bash logic for common infrastructure tasks, allowing applications to focus on their specific installation and configuration needs.

  • Constructor Details

    • UserDataBuilderImpl

      public UserDataBuilderImpl(software.amazon.awscdk.services.ec2.UserData userData)
  • Method Details

    • addSystemUpdate

      public void addSystemUpdate()
      Description copied from interface: UserDataBuilder
      Add system update commands (handles both dnf and yum). Automatically detects whether to use dnf (Amazon Linux 2023) or yum (Amazon Linux 2).
      Specified by:
      addSystemUpdate in interface UserDataBuilder
    • installCloudWatchAgent

      public void installCloudWatchAgent(String logGroupName, List<String> logFilePaths)
      Description copied from interface: UserDataBuilder
      Install and configure CloudWatch Agent for log streaming.

      This method:

      • Downloads and installs the CloudWatch Agent
      • Configures log file collection for the specified paths
      • Starts the agent service
      Specified by:
      installCloudWatchAgent in interface UserDataBuilder
      Parameters:
      logGroupName - The CloudWatch Logs group name (e.g., "/aws/jenkins/mystack/ec2/dev")
      logFilePaths - List of absolute paths to log files to monitor
    • mountEfs

      public void mountEfs(String efsId, String accessPointId, String mountPath, String uid, String gid)
      Description copied from interface: UserDataBuilder
      Mount EFS filesystem with IAM authentication.

      This method:

      • Installs amazon-efs-utils
      • Creates the mount directory
      • Adds fstab entry with TLS and IAM auth
      • Mounts the filesystem
      • Sets ownership to the specified uid:gid
      Specified by:
      mountEfs in interface UserDataBuilder
      Parameters:
      efsId - The EFS filesystem ID (e.g., "fs-12345678")
      accessPointId - The EFS access point ID (e.g., "fsap-12345678")
      mountPath - The local mount path (e.g., "/var/lib/jenkins")
      uid - The user ID for ownership (e.g., "1000")
      gid - The group ID for ownership (e.g., "1000")
    • mountEbs

      public void mountEbs(String deviceName, String mountPath, String uid, String gid)
      Description copied from interface: UserDataBuilder
      Format and mount EBS volume.

      This method:

      • Detects the EBS device (handles both /dev/xvdh and /dev/nvme1n1)
      • Formats the device with XFS filesystem
      • Creates the mount directory
      • Adds fstab entry
      • Mounts the filesystem
      • Sets ownership to the specified uid:gid
      Specified by:
      mountEbs in interface UserDataBuilder
      Parameters:
      deviceName - The EBS device name (e.g., "/dev/xvdh")
      mountPath - The local mount path (e.g., "/var/lib/jenkins")
      uid - The user ID for ownership (e.g., "1000")
      gid - The group ID for ownership (e.g., "1000")
    • addCommands

      public void addCommands(String... commands)
      Description copied from interface: UserDataBuilder
      Add custom commands to the UserData script. Commands are executed in the order they are added.
      Specified by:
      addCommands in interface UserDataBuilder
      Parameters:
      commands - One or more shell commands to execute
    • addCommand

      public void addCommand(String command)
      Description copied from interface: UserDataBuilder
      Add a single custom command to the UserData script.
      Specified by:
      addCommand in interface UserDataBuilder
      Parameters:
      command - Shell command to execute