Skip to content

Commit b63707b

Browse files
author
Yuriy Bezsonov
committed
WIP
1 parent 8a500a1 commit b63707b

File tree

10 files changed

+170
-235
lines changed

10 files changed

+170
-235
lines changed

.github/renovate.yml

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extends:
33
schedule:
44
- "before 6am on monday"
55
regexManagers:
6+
# Development tools
67
- fileMatch:
78
- "^infra/scripts/.*\\.sh$"
89
matchStrings:
@@ -12,49 +13,70 @@ regexManagers:
1213
- fileMatch:
1314
- "^infra/scripts/.*\\.sh$"
1415
matchStrings:
15-
- "MAVEN_VERSION=\"(?<currentValue>.*?)\""
16-
datasourceTemplate: github-releases
17-
depNameTemplate: apache/maven
16+
- "NODE_VERSION=\"(?<currentValue>.*?)\""
17+
datasourceTemplate: node-version
18+
depNameTemplate: node
1819
- fileMatch:
1920
- "^infra/scripts/.*\\.sh$"
2021
matchStrings:
21-
- "KUBECTL_VERSION=\"(?<currentValue>.*?)\""
22+
- "MAVEN_VERSION=\"(?<currentValue>.*?)\""
2223
datasourceTemplate: github-releases
23-
depNameTemplate: kubernetes/kubernetes
24+
depNameTemplate: apache/maven
25+
26+
# VS Code tools
2427
- fileMatch:
2528
- "^infra/scripts/.*\\.sh$"
2629
matchStrings:
27-
- "HELM_VERSION=\"(?<currentValue>.*?)\""
30+
- "VSCODE_VERSION=\"(?<currentValue>.*?)\""
2831
datasourceTemplate: github-releases
29-
depNameTemplate: helm/helm
32+
depNameTemplate: coder/code-server
33+
34+
# Kubernetes tools
3035
- fileMatch:
3136
- "^infra/scripts/.*\\.sh$"
3237
matchStrings:
33-
- "EKSCTL_VERSION=\"(?<currentValue>.*?)\""
38+
- "KUBECTL_VERSION=\"(?<currentValue>.*?)\""
3439
datasourceTemplate: github-releases
35-
depNameTemplate: weaveworks/eksctl
40+
depNameTemplate: kubernetes/kubernetes
3641
- fileMatch:
3742
- "^infra/scripts/.*\\.sh$"
3843
matchStrings:
39-
- "YQ_VERSION=\"(?<currentValue>.*?)\""
44+
- "HELM_VERSION=\"(?<currentValue>.*?)\""
4045
datasourceTemplate: github-releases
41-
depNameTemplate: mikefarah/yq
46+
depNameTemplate: helm/helm
4247
- fileMatch:
4348
- "^infra/scripts/.*\\.sh$"
4449
matchStrings:
45-
- "DOCKER_COMPOSE_VERSION=\"(?<currentValue>.*?)\""
50+
- "EKS_NODE_VIEWER_VERSION=\"(?<currentValue>.*?)\""
4651
datasourceTemplate: github-releases
47-
depNameTemplate: docker/compose
52+
depNameTemplate: awslabs/eks-node-viewer
4853

54+
# Container tools
4955
- fileMatch:
5056
- "^infra/scripts/.*\\.sh$"
5157
matchStrings:
52-
- "EKS_NODE_VIEWER_VERSION=\"(?<currentValue>.*?)\""
58+
- "SOCI_VERSION=\"(?<currentValue>.*?)\""
5359
datasourceTemplate: github-releases
54-
depNameTemplate: awslabs/eks-node-viewer
60+
depNameTemplate: awslabs/soci-snapshotter
61+
62+
# Utilities
5563
- fileMatch:
5664
- "^infra/scripts/.*\\.sh$"
5765
matchStrings:
58-
- "SOCI_VERSION=\"(?<currentValue>.*?)\""
66+
- "YQ_VERSION=\"(?<currentValue>.*?)\""
5967
datasourceTemplate: github-releases
60-
depNameTemplate: awslabs/soci-snapshotter
68+
depNameTemplate: mikefarah/yq
69+
70+
# Commented out tools (disabled for now)
71+
# - fileMatch:
72+
# - "^infra/scripts/.*\\.sh$"
73+
# matchStrings:
74+
# - "# EKSCTL_VERSION=\"(?<currentValue>.*?)\""
75+
# datasourceTemplate: github-releases
76+
# depNameTemplate: weaveworks/eksctl
77+
# - fileMatch:
78+
# - "^infra/scripts/.*\\.sh$"
79+
# matchStrings:
80+
# - "# DOCKER_COMPOSE_VERSION=\"(?<currentValue>.*?)\""
81+
# datasourceTemplate: github-releases
82+
# depNameTemplate: docker/compose

infra/cdk/src/main/java/sample/com/WorkshopApp.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public static void main(final String[] args) {
1414

1515
new WorkshopStack(app, "WorkshopStack", StackProps.builder()
1616
.synthesizer(new DefaultStackSynthesizer(DefaultStackSynthesizerProps.builder()
17-
.generateBootstrapVersionRule(false)
18-
.fileAssetsBucketName("unused-bucket") // Force inline assets
19-
.bucketPrefix("unused-prefix")
17+
.generateBootstrapVersionRule(false) // This disables the bootstrap version parameter
2018
.build()))
2119
.build());
2220

infra/cdk/src/main/java/sample/com/WorkshopStack.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import software.amazon.awscdk.Stack;
44
import software.amazon.awscdk.StackProps;
5-
import software.amazon.awscdk.CfnOutput;
6-
import software.amazon.awscdk.CfnParameter;
75
import software.amazon.awscdk.Aws;
86
import software.constructs.Construct;
97
import sample.com.constructs.*;
@@ -57,11 +55,6 @@ public WorkshopStack(final Construct scope, final String id, final StackProps pr
5755
.templateType(templateType)
5856
.build());
5957

60-
// Custom roles only for non-base templates
61-
if (!"base".equals(templateType)) {
62-
Roles roles = new Roles(this, "Roles");
63-
}
64-
6558
// CodeBuild for workshop setup
6659
CodeBuild codeBuild = new CodeBuild(this, "CodeBuild",
6760
CodeBuild.CodeBuildProps.builder()
@@ -73,5 +66,10 @@ public WorkshopStack(final Construct scope, final String id, final StackProps pr
7366
"GIT_BRANCH", gitBranch))
7467
.buildSpec(buildSpec)
7568
.build());
69+
70+
// Custom roles only for non-base templates
71+
if (!"base".equals(templateType)) {
72+
Roles roles = new Roles(this, "Roles");
73+
}
7674
}
7775
}

infra/cdk/src/main/java/sample/com/constructs/CodeBuild.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static class CodeBuildProps {
3030
private String projectName = "workshop-setup";
3131
private IBuildImage buildImage = LinuxBuildImage.AMAZON_LINUX_2_5;
3232
private ComputeType computeType = ComputeType.MEDIUM;
33-
private Duration timeout = Duration.minutes(60);
33+
private Duration timeout = Duration.minutes(30);
3434
private Boolean privilegedMode = false;
3535
private IVpc vpc;
3636
private Map<String, String> environmentVariables;

infra/cdk/src/main/java/sample/com/constructs/Ide.java

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

infra/cdk/src/main/resources/ec2-userdata.sh

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)