Skip to content

Commit

Permalink
Add jvmOptions to AgentEC2Fleet properties. (#7)
Browse files Browse the repository at this point in the history
* Add 'jvmOptions' to AgentEC2Fleet properties.
- Defaults '-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8' for Windows fleet.

* Change default value of some SSH connector parameters to empty string.
- jvmOptions
- prefixStartSlaveCmd
- suffixStartSlaveCmd

* Combine default values of SSH connector in `AgentEC2Fleet`.
  • Loading branch information
Yukinobu-Mine committed Jun 23, 2023
1 parent 48d2ffa commit 1d22a8b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
36 changes: 26 additions & 10 deletions lib/construct/jenkins/agent-ec2-fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export interface AgentEC2FleetPropsBase {
readonly fleetMinSize: number;
readonly fleetMaxSize: number;

readonly prefixStartSlaveCmd?: string;
readonly suffixStartSlaveCmd?: string;

readonly rootVolumeSize: cdk.Size;

/**
Expand Down Expand Up @@ -62,6 +59,10 @@ export interface AgentEC2FleetProps extends AgentEC2FleetPropsBase {
readonly sshConnectTimeoutSeconds: number;
readonly sshConnectMaxNumRetries: number;
readonly sshConnectRetryWaitTime: number;

readonly jvmOptions: string;
readonly prefixStartSlaveCmd: string;
readonly suffixStartSlaveCmd: string;
}

export interface AgentEC2FleetPropsCommon extends AgentEC2FleetPropsBase {
Expand All @@ -74,6 +75,10 @@ export interface AgentEC2FleetPropsCommon extends AgentEC2FleetPropsBase {
readonly sshConnectTimeoutSeconds?: number;
readonly sshConnectMaxNumRetries?: number;
readonly sshConnectRetryWaitTime?: number;

readonly jvmOptions?: string;
readonly prefixStartSlaveCmd?: string;
readonly suffixStartSlaveCmd?: string;
}

export interface AgentEC2FleetLinuxProps extends AgentEC2FleetPropsCommon {}
Expand Down Expand Up @@ -101,8 +106,9 @@ export class AgentEC2Fleet extends Construct {
public readonly sshConnectMaxNumRetries: number;
public readonly sshConnectRetryWaitTime: number;

public readonly prefixStartSlaveCmd?: string;
public readonly suffixStartSlaveCmd?: string;
public readonly jvmOptions: string;
public readonly prefixStartSlaveCmd: string;
public readonly suffixStartSlaveCmd: string;

constructor(scope: Construct, id: string, props: AgentEC2FleetProps) {
super(scope, id);
Expand All @@ -120,6 +126,7 @@ export class AgentEC2Fleet extends Construct {
this.sshConnectMaxNumRetries = props.sshConnectMaxNumRetries;
this.sshConnectRetryWaitTime = props.sshConnectRetryWaitTime;

this.jvmOptions = props.jvmOptions;
this.prefixStartSlaveCmd = props.prefixStartSlaveCmd;
this.suffixStartSlaveCmd = props.suffixStartSlaveCmd;

Expand Down Expand Up @@ -237,7 +244,10 @@ export class AgentEC2Fleet extends Construct {
: ec2.MachineImage.latestAmazonLinux2023(),
userData: userData,
rootVolumeDeviceName: '/dev/xvda',
fsRoot: '/data/jenkins-agent',
fsRoot: props.fsRoot ?? '/data/jenkins-agent',
jvmOptions: props.jvmOptions ?? '',
prefixStartSlaveCmd: props.prefixStartSlaveCmd ?? '',
suffixStartSlaveCmd: props.suffixStartSlaveCmd ?? '',
sshCredentialsId: 'instance-ssh-key-unix',
sshConnectTimeoutSeconds: props.sshConnectTimeoutSeconds ?? 60,
sshConnectMaxNumRetries: props.sshConnectMaxNumRetries ?? 10,
Expand All @@ -257,15 +267,21 @@ export class AgentEC2Fleet extends Construct {
: ec2.MachineImage.latestWindows(ec2.WindowsVersion.WINDOWS_SERVER_2022_ENGLISH_FULL_CONTAINERSLATEST),
userData: userData,
rootVolumeDeviceName: '/dev/sda1',
sshCredentialsId: 'instance-ssh-key-windows',

jvmOptions: props.jvmOptions ?? '-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8',
...(props.dataVolumeSize != null
? {
fsRoot: 'D:\\Jenkins',
prefixStartSlaveCmd: 'cd /d D:\\ && ',
fsRoot: props.fsRoot ?? 'D:\\Jenkins',
prefixStartSlaveCmd: props.prefixStartSlaveCmd ?? 'cd /d D:\\ && ',
suffixStartSlaveCmd: props.suffixStartSlaveCmd ?? '',
}
: {
fsRoot: 'C:\\Jenkins',
fsRoot: props.fsRoot ?? 'C:\\Jenkins',
prefixStartSlaveCmd: props.prefixStartSlaveCmd ?? '',
suffixStartSlaveCmd: props.suffixStartSlaveCmd ?? '',
}),

sshCredentialsId: 'instance-ssh-key-windows',
sshConnectTimeoutSeconds: props.sshConnectTimeoutSeconds ?? 60,
sshConnectMaxNumRetries: props.sshConnectMaxNumRetries ?? 30,
sshConnectRetryWaitTime: props.sshConnectRetryWaitTime ?? 15,
Expand Down
5 changes: 3 additions & 2 deletions lib/construct/jenkins/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export interface EC2FleetAgentProps {
readonly sshConnectMaxNumRetries: number;
readonly sshConnectRetryWaitTime: number;

readonly prefixStartSlaveCmd?: string;
readonly suffixStartSlaveCmd?: string;
readonly jvmOptions: string;
readonly prefixStartSlaveCmd: string;
readonly suffixStartSlaveCmd: string;
}

export interface ControllerProps {
Expand Down
7 changes: 2 additions & 5 deletions lib/construct/jenkins/resources/config/jenkins.yaml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ jenkins:
` maxNumRetries: ${agent.sshConnectMaxNumRetries}`,
` retryWaitTime: ${agent.sshConnectRetryWaitTime}`,
` sshHostKeyVerificationStrategy: nonVerifyingKeyVerificationStrategy`,
...(agent.prefixStartSlaveCmd ? [
` prefixStartSlaveCmd: '${agent.prefixStartSlaveCmd}'`
] : []),
...(agent.suffixStartSlaveCmd ? [
` jvmOptions: '${agent.jvmOptions}'`,
` prefixStartSlaveCmd: '${agent.prefixStartSlaveCmd}'`,
` suffixStartSlaveCmd: '${agent.suffixStartSlaveCmd}'`,
] : []),
` disableTaskResubmit: false`,
` fleet: \${${agent.fleetAsgNameEnv}}`,
` fsRoot: ${agent.fsRoot}`,
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/jenkins-unity-build.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ exports[`Snapshot test 1`] = `
],
"Essential": true,
"Image": {
"Fn::Sub": "\${AWS::AccountId}.dkr.ecr.us-east-2.\${AWS::URLSuffix}/cdk-hnb659fds-container-assets-\${AWS::AccountId}-us-east-2:8b220441740e064aaea571f967480aca5461a360a69042a15e1e2f739b047b9f",
"Fn::Sub": "\${AWS::AccountId}.dkr.ecr.us-east-2.\${AWS::URLSuffix}/cdk-hnb659fds-container-assets-\${AWS::AccountId}-us-east-2:c18fd707fb9a53bc41fab4920d4ea0defec7f8dea60f20f4daa5409a965f9423",
},
"LinuxParameters": {
"Capabilities": {},
Expand Down

0 comments on commit 1d22a8b

Please sign in to comment.