@@ -49,12 +49,7 @@ public static class IdeProps {
4949 private IMachineImage machineImage = MachineImage .latestAmazonLinux2023 ();
5050 private List <String > instanceTypes = Arrays .asList ("m5.xlarge" , "m6i.xlarge" , "t3.xlarge" );
5151 private List <ISecurityGroup > additionalSecurityGroups = new ArrayList <>();
52- private int bootstrapTimeoutMinutes = 10 ;
53- private List <String > vscodeExtensions = Arrays .asList (
54- "shardulm94.trailing-spaces" ,
55- "ms-kubernetes-tools.vscode-kubernetes-tools" ,
56- "ms-azuretools.vscode-docker"
57- );
52+ private int bootstrapTimeoutMinutes = 30 ;
5853 private String gitBranch = "main" ;
5954 private String templateType = "base" ;
6055
@@ -70,10 +65,8 @@ public static class Builder {
7065 public Builder instanceTypes (List <String > instanceTypes ) { props .instanceTypes = instanceTypes ; return this ; }
7166 public Builder additionalSecurityGroups (List <ISecurityGroup > additionalSecurityGroups ) { props .additionalSecurityGroups = additionalSecurityGroups ; return this ; }
7267 public Builder bootstrapTimeoutMinutes (int bootstrapTimeoutMinutes ) { props .bootstrapTimeoutMinutes = bootstrapTimeoutMinutes ; return this ; }
73- public Builder vscodeExtensions (List <String > vscodeExtensions ) { props .vscodeExtensions = vscodeExtensions ; return this ; }
7468 public Builder gitBranch (String gitBranch ) { props .gitBranch = gitBranch ; return this ; }
7569 public Builder templateType (String templateType ) { props .templateType = templateType ; return this ; }
76-
7770 public IdeProps build () { return props ; }
7871 }
7972
@@ -85,7 +78,6 @@ public static class Builder {
8578 public List <String > getInstanceTypes () { return instanceTypes ; }
8679 public List <ISecurityGroup > getAdditionalSecurityGroups () { return additionalSecurityGroups ; }
8780 public int getBootstrapTimeoutMinutes () { return bootstrapTimeoutMinutes ; }
88- public List <String > getVscodeExtensions () { return vscodeExtensions ; }
8981 public String getGitBranch () { return gitBranch ; }
9082 public String getTemplateType () { return templateType ; }
9183 }
@@ -243,11 +235,10 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
243235
244236 // Create User Data for bootstrap with CloudWatch logging
245237 var userData = UserData .forLinux ();
246- String extensionsString = String .join ("," , props .getVscodeExtensions ());
247238 String gitBranch = props .getGitBranch ();
248239 String templateType = props .getTemplateType ();
249240
250- // Build UserData content with proper substitutions
241+ // Build UserData content with substitutions
251242 String userDataContent = String .format ("""
252243 #!/bin/bash
253244 set -e
@@ -261,7 +252,6 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
261252 STACK_NAME="%s"
262253 AWS_REGION="%s"
263254 TEMPLATE_TYPE="%s"
264- VSCODE_EXTENSIONS="%s"
265255
266256 # Setup logging
267257 LOG_GROUP_NAME="ide-bootstrap-$(date +%%Y%%m%%d-%%H%%M%%S)"
@@ -300,42 +290,47 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
300290
301291 echo "UserData started at $(date) - Logging to $LOG_GROUP_NAME"
302292
303- # Download and run full bootstrap script with retry logic
304- download_bootstrap() {
305- local urls=(
306- "https://raw.githubusercontent.com/aws-samples/java-on-aws/${GIT_BRANCH}/infra/scripts/ide/bootstrap.sh"
307- "https://github.com/aws-samples/java-on-aws/raw/${GIT_BRANCH}/infra/scripts/ide/bootstrap.sh"
308- )
293+ # Clone repository to ec2-user home directory
294+ clone_repository() {
309295 local max_attempts=5
310296 local delay=5
311297
312298 for attempt in $(seq 1 $max_attempts); do
313- echo "Download attempt $attempt of $max_attempts"
299+ echo "Clone attempt $attempt of $max_attempts"
300+
301+ # Remove existing directory if it exists
302+ sudo -u ec2-user rm -rf /home/ec2-user/java-on-aws
314303
315- for url in "${urls[@]}"; do
316- echo "Trying to download bootstrap from: $url"
317- if curl -fsSL --connect-timeout 30 --max-time 60 "$url" -o /tmp/bootstrap.sh; then
318- echo "Successfully downloaded bootstrap script on attempt $attempt"
304+ # Clone as ec2-user to their home directory
305+ if sudo -u ec2-user git clone https://github.com/aws-samples/java-on-aws.git /home/ec2-user/java-on-aws; then
306+ # Checkout the correct branch as ec2-user
307+ if sudo -u ec2-user bash -c "cd /home/ec2-user/java-on-aws && git checkout $GIT_BRANCH"; then
308+ echo "Successfully cloned repository and checked out branch $GIT_BRANCH on attempt $attempt"
319309 return 0
310+ else
311+ echo "Failed to checkout branch $GIT_BRANCH on attempt $attempt"
320312 fi
321- echo "Failed to download from: $url"
322- done
313+ else
314+ echo "Failed to clone repository on attempt $attempt"
315+ fi
323316
324317 if [ $attempt -lt $max_attempts ]; then
325- echo "All URLs failed on attempt $attempt, waiting ${delay}s before retry..."
318+ echo "Clone failed on attempt $attempt, waiting ${delay}s before retry..."
326319 sleep $delay
327320 fi
328321 done
329322
330- echo "All download attempts failed after $max_attempts tries"
323+ echo "All clone attempts failed after $max_attempts tries"
331324 return 1
332325 }
333326
334- if download_bootstrap; then
335- chmod +x /tmp/bootstrap.sh
327+ if clone_repository; then
328+ # Make scripts executable
329+ sudo -u ec2-user chmod +x /home/ec2-user/java-on-aws/infra/scripts/ide/*.sh
330+
336331 echo "Executing full bootstrap script..."
337- export VSCODE_EXTENSIONS="$VSCODE_EXTENSIONS"
338- if /tmp/ bootstrap.sh " $IDE_PASSWORD" " $GIT_BRANCH" " $STACK_NAME" "$AWS_REGION" "$ TEMPLATE_TYPE"; then
332+ # Run bootstrap script as ec2-user from their home directory
333+ if sudo -u ec2-user bash -c "cd /home/ec2-user/java-on-aws && infra/scripts/ide/ bootstrap.sh ' $IDE_PASSWORD' ' $GIT_BRANCH' ' $STACK_NAME' '$ TEMPLATE_TYPE' "; then
339334 echo "Bootstrap completed successfully"
340335 /opt/aws/bin/cfn-signal -e 0 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
341336 else
@@ -344,7 +339,7 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
344339 exit 1
345340 fi
346341 else
347- echo "FATAL: Could not download bootstrap script from any source "
342+ echo "FATAL: Could not clone repository "
348343 /opt/aws/bin/cfn-signal -e 1 --stack "$STACK_NAME" --resource IdeBootstrapWaitCondition --region "$AWS_REGION"
349344 exit 1
350345 fi
@@ -353,8 +348,7 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
353348 ideSecretsManagerPassword .secretValueFromJson ("password" ).unsafeUnwrap (),
354349 Aws .STACK_NAME ,
355350 Aws .REGION ,
356- templateType ,
357- extensionsString
351+ templateType
358352 );
359353
360354 userData .addCommands (userDataContent );
0 commit comments