Package com.cloudforgeci.api.core
Class UserDataBuilderImpl
java.lang.Object
com.cloudforgeci.api.core.UserDataBuilderImpl
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommand(String command) Add a single custom command to the UserData script.voidaddCommands(String... commands) Add custom commands to the UserData script.voidAdd system update commands (handles both dnf and yum).voidinstallCloudWatchAgent(String logGroupName, List<String> logFilePaths) Install and configure CloudWatch Agent for log streaming.voidFormat and mount EBS volume.voidMount EFS filesystem with IAM authentication.
-
Constructor Details
-
UserDataBuilderImpl
public UserDataBuilderImpl(software.amazon.awscdk.services.ec2.UserData userData)
-
-
Method Details
-
addSystemUpdate
public void addSystemUpdate()Description copied from interface:UserDataBuilderAdd system update commands (handles both dnf and yum). Automatically detects whether to use dnf (Amazon Linux 2023) or yum (Amazon Linux 2).- Specified by:
addSystemUpdatein interfaceUserDataBuilder
-
installCloudWatchAgent
Description copied from interface:UserDataBuilderInstall 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:
installCloudWatchAgentin interfaceUserDataBuilder- 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
Description copied from interface:UserDataBuilderMount 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:
mountEfsin interfaceUserDataBuilder- 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
Description copied from interface:UserDataBuilderFormat 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:
mountEbsin interfaceUserDataBuilder- 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
Description copied from interface:UserDataBuilderAdd custom commands to the UserData script. Commands are executed in the order they are added.- Specified by:
addCommandsin interfaceUserDataBuilder- Parameters:
commands- One or more shell commands to execute
-
addCommand
Description copied from interface:UserDataBuilderAdd a single custom command to the UserData script.- Specified by:
addCommandin interfaceUserDataBuilder- Parameters:
command- Shell command to execute
-