Skip to content

Commit 79b8c91

Browse files
author
Yuriy Bezsonov
committed
WIP
1 parent 65ece15 commit 79b8c91

File tree

5 files changed

+102
-69
lines changed

5 files changed

+102
-69
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
305305
306306
echo "UserData started at $(date) - Logging to $LOG_GROUP_NAME"
307307
308+
# Set up error trap for UserData failures (before bootstrap.sh takes over)
309+
trap 'echo "UserData failed at line $LINENO"; /opt/aws/bin/cfn-signal -e 1 "%s" 2>/dev/null || true; exit 1' ERR
310+
308311
# Install git (required for cloning repository)
309312
echo "Installing git..."
310313
dnf install -y git
@@ -349,9 +352,9 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
349352
350353
echo "Executing full bootstrap script..."
351354
# Run bootstrap script as root from the cloned directory
352-
if bash -c "cd /home/ec2-user/java-on-aws && WAIT_CONDITION_HANDLE_URL='%s' infra/scripts/ide/bootstrap.sh '$GIT_BRANCH' '$STACK_NAME' '$TEMPLATE_TYPE'"; then
355+
if cd /home/ec2-user/java-on-aws && WAIT_CONDITION_HANDLE_URL='%s' infra/scripts/ide/bootstrap.sh '$GIT_BRANCH' '$STACK_NAME' '$TEMPLATE_TYPE'; then
353356
echo "Bootstrap completed successfully"
354-
/opt/aws/bin/cfn-signal -e 0 '%s'
357+
# Bootstrap script already signaled success
355358
else
356359
echo "FATAL: Bootstrap script failed"
357360
/opt/aws/bin/cfn-signal -e 1 '%s'

infra/scripts/ide/base.sh

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ MAVEN_VERSION="3.9.11"
1616
# Kubernetes tools
1717
KUBECTL_VERSION="1.34.2"
1818
HELM_VERSION="3.19.3"
19-
# EKSCTL_VERSION="0.220.0"
2019
EKS_NODE_VIEWER_VERSION="0.7.4"
2120

2221
# Container tools
23-
# DOCKER_COMPOSE_VERSION="2.40.2"
2422
SOCI_VERSION="0.12.0"
2523

2624
# Utilities
@@ -57,6 +55,32 @@ retry_optional() {
5755
fi
5856
}
5957

58+
# Helper function to install and get version
59+
install_with_version() {
60+
local tool_name="$1"
61+
local install_cmd="$2"
62+
local version_cmd="$3"
63+
local fail_mode="${4:-FAIL}"
64+
65+
if eval "$install_cmd"; then
66+
if [ -n "$version_cmd" ]; then
67+
local version=$(eval "$version_cmd" 2>/dev/null | head -1 || echo "unknown")
68+
echo "✅ Success: $tool_name $version"
69+
else
70+
echo "✅ Success: $tool_name"
71+
fi
72+
return 0
73+
else
74+
if [ "$fail_mode" = "FAIL" ]; then
75+
echo "💥 FATAL: $tool_name failed"
76+
exit 1
77+
else
78+
echo "⚠️ WARNING: $tool_name failed (continuing)"
79+
return 1
80+
fi
81+
fi
82+
}
83+
6084
# Helper function for consistent logging
6185
log_info() {
6286
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1"
@@ -75,7 +99,7 @@ download_and_verify() {
7599
local description="$3"
76100

77101
log_info "Downloading $description..."
78-
retry_critical "$description download" "wget -q '$url' -O '$output'"
102+
retry_critical "$description" "wget -q '$url' -O '$output'"
79103
}
80104

81105
cd /tmp
@@ -117,14 +141,13 @@ install_nodejs() {
117141

118142
# Install Node.js and tools
119143
retry_critical "Node.js ${NODE_VERSION}" "nvm install ${NODE_VERSION}"
120-
retry_critical "npm (latest)" "nvm install-latest-npm"
121-
retry_critical "CDK and Artillery" "npm install -g aws-cdk artillery"
122-
123-
# Verify installations
124-
log_info "Node.js version: $(node -v)"
125-
log_info "npm version: $(npm -v)"
126-
log_info "CDK version: $(cdk version)"
127-
log_info "Artillery version: $(artillery -v)"
144+
145+
# Install npm and get version
146+
install_with_version "npm" "nvm install-latest-npm" "npm --version"
147+
148+
# Install CDK and Artillery separately to get individual versions
149+
install_with_version "CDK" "npm install -g aws-cdk" "cdk version"
150+
install_with_version "Artillery" "npm install -g artillery" "artillery -v"
128151
}
129152

130153
install_nodejs
@@ -143,8 +166,6 @@ install_maven() {
143166
echo "export M2_HOME=/usr/lib/maven" | sudo tee -a /etc/profile.d/workshop.sh >/dev/null
144167
echo "export PATH=\${PATH}:\${M2_HOME}/bin" | sudo tee -a /etc/profile.d/workshop.sh >/dev/null
145168
sudo ln -s /usr/lib/maven/bin/mvn /usr/local/bin
146-
147-
log_info "Maven version: $(mvn --version | head -1)"
148169
}
149170

150171
install_maven
@@ -155,11 +176,9 @@ install_aws_tools() {
155176
download_and_verify "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip" "aws-sam-cli-linux-x86_64.zip" "AWS SAM CLI"
156177

157178
unzip -q aws-sam-cli-linux-x86_64.zip -d sam-installation
158-
retry_critical "SAM CLI installation" "sudo ./sam-installation/install --update"
179+
install_with_version "AWS SAM CLI" "sudo ./sam-installation/install --update" "/usr/local/bin/sam --version | awk '{print \$4}'"
159180
rm -rf ./sam-installation/ aws-sam-cli-linux-x86_64.zip
160181

161-
log_info "SAM CLI version: $(/usr/local/bin/sam --version)"
162-
163182
log_info "Installing Session Manager Plugin..."
164183
download_and_verify "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" "session-manager-plugin.rpm" "Session Manager Plugin"
165184
retry_critical "Session Manager Plugin" "sudo dnf -q install -y session-manager-plugin.rpm"
@@ -170,7 +189,7 @@ install_aws_tools
170189

171190
install_kubernetes_tools() {
172191
log_info "Installing kubectl ${KUBECTL_VERSION}..."
173-
download_and_verify "https://s3.us-west-2.amazonaws.com/amazon-eks/${KUBECTL_VERSION}/2025-11-13/bin/linux/amd64/kubectl" "kubectl" "kubectl"
192+
download_and_verify "https://s3.us-west-2.amazonaws.com/amazon-eks/${KUBECTL_VERSION}/2025-11-13/bin/linux/amd64/kubectl" "kubectl" "kubectl ${KUBECTL_VERSION}"
174193

175194
chmod +x ./kubectl
176195
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
@@ -179,31 +198,21 @@ install_kubernetes_tools() {
179198
echo "alias k=kubectl" | sudo tee -a /etc/profile.d/workshop.sh >/dev/null
180199
echo "complete -F __start_kubectl k" >> ~/.bashrc
181200

182-
log_info "kubectl version: $(kubectl version --client --short 2>/dev/null || echo 'installed')"
183-
184-
# log_info "Installing eksctl ${EKSCTL_VERSION}..."
185-
# download_and_verify "https://github.com/weaveworks/eksctl/releases/download/v${EKSCTL_VERSION}/eksctl_Linux_amd64.tar.gz" "eksctl_Linux_amd64.tar.gz" "eksctl"
186-
# tar -xzf eksctl_Linux_amd64.tar.gz -C /tmp && rm eksctl_Linux_amd64.tar.gz
187-
# sudo mv /tmp/eksctl /usr/local/bin
188-
# log_info "eksctl version: $(eksctl version)"
189-
190201
log_info "Installing Helm ${HELM_VERSION}..."
191-
retry_critical "Helm ${HELM_VERSION}" "curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3"
192-
chmod 700 get_helm.sh
193-
./get_helm.sh --version v${HELM_VERSION}
202+
retry_critical "Helm ${HELM_VERSION}" "curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && chmod 700 get_helm.sh && ./get_helm.sh --version v${HELM_VERSION}"
194203
helm completion bash >> ~/.bash_completion
195-
log_info "Helm version: $(helm version --short)"
196204

197205
log_info "Installing eks-node-viewer ${EKS_NODE_VIEWER_VERSION}..."
198-
download_and_verify "https://github.com/awslabs/eks-node-viewer/releases/download/v${EKS_NODE_VIEWER_VERSION}/eks-node-viewer_Linux_x86_64" "eks-node-viewer" "eks-node-viewer"
206+
download_and_verify "https://github.com/awslabs/eks-node-viewer/releases/download/v${EKS_NODE_VIEWER_VERSION}/eks-node-viewer_Linux_x86_64" "eks-node-viewer" "eks-node-viewer ${EKS_NODE_VIEWER_VERSION}"
199207
chmod +x eks-node-viewer
200208
sudo mv eks-node-viewer /usr/local/bin
201209

202210
log_info "Installing k9s..."
203-
retry_optional "k9s" "curl -sS https://webinstall.dev/k9s | bash"
211+
export PATH="$HOME/.local/bin:$PATH" # k9s installs to ~/.local/bin
212+
install_with_version "k9s" "curl -sS https://webinstall.dev/k9s | bash" "k9s version --short 2>/dev/null | grep Version | awk '{print \$2}'" "LOG"
204213

205214
log_info "Installing e1s..."
206-
retry_optional "e1s" "curl -sL https://raw.githubusercontent.com/keidarcy/e1s-install/master/cloudshell-install.sh | bash"
215+
install_with_version "e1s" "curl -sL https://raw.githubusercontent.com/keidarcy/e1s-install/master/cloudshell-install.sh | bash" "e1s --version 2>/dev/null | awk '{print \$3}'" "LOG"
207216
}
208217

209218
install_kubernetes_tools
@@ -215,15 +224,8 @@ install_container_tools() {
215224
sudo service docker start
216225
sudo usermod -aG docker ec2-user
217226

218-
# log_info "Installing Docker Compose ${DOCKER_COMPOSE_VERSION}..."
219-
# DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
220-
# mkdir -p $DOCKER_CONFIG/cli-plugins
221-
# download_and_verify "https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64" "$DOCKER_CONFIG/cli-plugins/docker-compose" "Docker Compose"
222-
# chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
223-
# log_info "Docker Compose version: $(docker compose version)"
224-
225227
log_info "Installing SOCI snapshotter ${SOCI_VERSION}..."
226-
download_and_verify "https://github.com/awslabs/soci-snapshotter/releases/download/v$SOCI_VERSION/soci-snapshotter-$SOCI_VERSION-linux-amd64.tar.gz" "soci-snapshotter-$SOCI_VERSION-linux-amd64.tar.gz" "SOCI snapshotter"
228+
download_and_verify "https://github.com/awslabs/soci-snapshotter/releases/download/v$SOCI_VERSION/soci-snapshotter-$SOCI_VERSION-linux-amd64.tar.gz" "soci-snapshotter-$SOCI_VERSION-linux-amd64.tar.gz" "SOCI snapshotter ${SOCI_VERSION}"
227229
sudo tar -C /usr/local/bin -xf soci-snapshotter-$SOCI_VERSION-linux-amd64.tar.gz soci soci-snapshotter-grpc
228230
rm soci-snapshotter-$SOCI_VERSION-linux-amd64.tar.gz
229231

@@ -246,13 +248,11 @@ install_container_tools
246248
install_utilities() {
247249
log_info "Installing jq..."
248250
sudo dnf install -y -q jq >/dev/null
249-
log_info "jq version: $(jq --version)"
250251

251252
log_info "Installing yq ${YQ_VERSION}..."
252-
download_and_verify "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64.tar.gz" "yq_linux_amd64.tar.gz" "yq"
253+
download_and_verify "https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64.tar.gz" "yq_linux_amd64.tar.gz" "yq ${YQ_VERSION}"
253254
tar xzf yq_linux_amd64.tar.gz && sudo mv yq_linux_amd64 /usr/bin/yq
254255
rm yq_linux_amd64.tar.gz
255-
log_info "yq version: $(yq --version)"
256256
}
257257

258258
install_utilities

infra/scripts/ide/bootstrap.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,32 @@ retry_command() {
4545
fi
4646
}
4747

48+
# Helper function to install and get version
49+
install_with_version() {
50+
local tool_name="$1"
51+
local install_cmd="$2"
52+
local version_cmd="$3"
53+
local fail_mode="${4:-FAIL}"
54+
55+
if eval "$install_cmd"; then
56+
if [ -n "$version_cmd" ]; then
57+
local version=$(eval "$version_cmd" 2>/dev/null | head -1 || echo "unknown")
58+
echo "✅ Success: $tool_name $version"
59+
else
60+
echo "✅ Success: $tool_name"
61+
fi
62+
return 0
63+
else
64+
if [ "$fail_mode" = "FAIL" ]; then
65+
echo "💥 FATAL: $tool_name failed"
66+
exit 1
67+
else
68+
echo "⚠️ WARNING: $tool_name failed (continuing)"
69+
return 1
70+
fi
71+
fi
72+
}
73+
4874
# Convenience functions for different retry policies
4975
retry_critical() { retry_command 5 5 "FAIL" "$@"; }
5076
retry_optional() { retry_command 5 5 "LOG" "$@"; }
@@ -56,7 +82,7 @@ echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing jq (required for secret parsing)
5682
dnf install -y -q jq
5783

5884
echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing AWS CLI..."
59-
retry_critical "AWS CLI" "curl -LSsf -o /tmp/aws-cli.zip https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip && rm -rf /tmp/aws && unzip -q -d /tmp /tmp/aws-cli.zip && /tmp/aws/install --update && rm -rf /tmp/aws*"
85+
retry_critical "AWS CLI 2.x" "curl -LSsf -o /tmp/aws-cli.zip https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip && rm -rf /tmp/aws && unzip -q -d /tmp /tmp/aws-cli.zip && /tmp/aws/install --update && rm -rf /tmp/aws*"
6086

6187
echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing CloudFormation helper scripts..."
6288
retry_critical "CloudFormation helper scripts" "dnf install -y aws-cfn-bootstrap"
@@ -116,7 +142,6 @@ EOF
116142
echo "Generating SSH key..."
117143
sudo -u ec2-user bash -c "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa -m pem <<< y"
118144

119-
120145
echo "Bootstrap script running from: $(pwd)"
121146
echo "Using git branch: $GIT_BRANCH"
122147

@@ -126,8 +151,6 @@ if [ ! -f "infra/scripts/ide/bootstrap.sh" ]; then
126151
exit 1
127152
fi
128153

129-
130-
131154
echo "$(date '+%Y-%m-%d %H:%M:%S') - Running VS Code setup..."
132155
bash infra/scripts/ide/vscode.sh
133156

infra/scripts/ide/vscode.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ echo "$(date '+%Y-%m-%d %H:%M:%S') - Installing code-server..."
5959
codeServer=$(dnf list installed code-server 2>/dev/null | wc -l)
6060
if [ "$codeServer" -eq "0" ]; then
6161
# Install as ec2-user with retry logic - pass version as environment variable
62-
retry_critical "VS Code Server" "sudo -u ec2-user bash -c 'curl -fsSL https://code-server.dev/install.sh | sh -s -- --version $VSCODE_VERSION'"
62+
retry_critical "VS Code Server ${VSCODE_VERSION}" "sudo -u ec2-user bash -c 'curl -fsSL https://code-server.dev/install.sh | sh -s -- --version $VSCODE_VERSION'"
6363
retry_critical "VS Code Server service" "systemctl enable --now code-server@ec2-user"
6464
fi
6565

@@ -80,7 +80,11 @@ setup_user_file "/home/ec2-user/.local/share/code-server/User/settings.json" '{
8080
"workbench.startupEditor": "terminal",
8181
"task.allowAutomaticTasks": "on",
8282
"telemetry.telemetryLevel": "off",
83-
"update.mode": "none"
83+
"update.mode": "none",
84+
"chat.agentSessionsViewLocation": "off",
85+
"github.copilot.enable": false,
86+
"github.copilot.chat.enable": false,
87+
"chat.extensionUnification.enabled": false
8488
}'
8589

8690
echo "Configuring VS Code keybindings..."

infra/workshop-template.yaml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ Resources:
714714
Fn::GetAtt:
715715
- IdeInstanceLauncherFunction803C5A2A
716716
- Arn
717+
InstanceTypes: m5.xlarge,m6i.xlarge,t3.xlarge
718+
InstanceName: ide
719+
IamInstanceProfileArn:
720+
Fn::GetAtt:
721+
- IdeIdeInstanceProfile8BD997EA
722+
- Arn
717723
VolumeSize: "50"
718724
SubnetIds:
719725
Fn::Join:
@@ -798,6 +804,12 @@ Resources:
798804
799805
echo "UserData started at $(date) - Logging to $LOG_GROUP_NAME"
800806
807+
# Set up error trap for UserData failures (before bootstrap.sh takes over)
808+
trap 'echo "UserData failed at line $LINENO"; /opt/aws/bin/cfn-signal -e 1 "
809+
- Ref: IdeBootstrapWaitConditionHandleD7141CA8
810+
- |-
811+
" 2>/dev/null || true; exit 1' ERR
812+
801813
# Install git (required for cloning repository)
802814
echo "Installing git..."
803815
dnf install -y git
@@ -842,15 +854,12 @@ Resources:
842854
843855
echo "Executing full bootstrap script..."
844856
# Run bootstrap script as root from the cloned directory
845-
if bash -c "cd /home/ec2-user/java-on-aws && WAIT_CONDITION_HANDLE_URL='
857+
if cd /home/ec2-user/java-on-aws && WAIT_CONDITION_HANDLE_URL='
846858
- Ref: IdeBootstrapWaitConditionHandleD7141CA8
847859
- |-
848-
' infra/scripts/ide/bootstrap.sh '$GIT_BRANCH' '$STACK_NAME' '$TEMPLATE_TYPE'"; then
860+
' infra/scripts/ide/bootstrap.sh '$GIT_BRANCH' '$STACK_NAME' '$TEMPLATE_TYPE'; then
849861
echo "Bootstrap completed successfully"
850-
/opt/aws/bin/cfn-signal -e 0 '
851-
- Ref: IdeBootstrapWaitConditionHandleD7141CA8
852-
- |-
853-
'
862+
# Bootstrap script already signaled success
854863
else
855864
echo "FATAL: Bootstrap script failed"
856865
/opt/aws/bin/cfn-signal -e 1 '
@@ -867,12 +876,6 @@ Resources:
867876
'
868877
exit 1
869878
fi
870-
InstanceTypes: m5.xlarge,m6i.xlarge,t3.xlarge
871-
InstanceName: ide
872-
IamInstanceProfileArn:
873-
Fn::GetAtt:
874-
- IdeIdeInstanceProfile8BD997EA
875-
- Arn
876879
UpdateReplacePolicy: Delete
877880
DeletionPolicy: Delete
878881
IdeIdeEipAssociation6C6C215D:
@@ -1242,12 +1245,12 @@ Resources:
12421245
Environment:
12431246
ComputeType: BUILD_GENERAL1_MEDIUM
12441247
EnvironmentVariables:
1245-
- Name: GIT_BRANCH
1246-
Type: PLAINTEXT
1247-
Value: new-ws-infra
12481248
- Name: TEMPLATE_TYPE
12491249
Type: PLAINTEXT
12501250
Value: base
1251+
- Name: GIT_BRANCH
1252+
Type: PLAINTEXT
1253+
Value: new-ws-infra
12511254
- Name: STACK_NAME
12521255
Type: PLAINTEXT
12531256
Value:
@@ -1458,12 +1461,12 @@ Resources:
14581461
Description: workshop-setup build complete
14591462
EventPattern:
14601463
detail:
1464+
project-name:
1465+
- Ref: CodeBuildProjectA0FF5539
14611466
build-status:
14621467
- SUCCEEDED
14631468
- FAILED
14641469
- STOPPED
1465-
project-name:
1466-
- Ref: CodeBuildProjectA0FF5539
14671470
detail-type:
14681471
- CodeBuild Build State Change
14691472
source:
@@ -1495,13 +1498,13 @@ Resources:
14951498
Fn::GetAtt:
14961499
- CodeBuildStartLambdaFunction8349284F
14971500
- Arn
1501+
ContentHash: "1765697286720"
14981502
ProjectName:
14991503
Ref: CodeBuildProjectA0FF5539
15001504
CodeBuildIamRoleArn:
15011505
Fn::GetAtt:
15021506
- CodeBuildCodeBuildRoleBA9C6D5C
15031507
- Arn
1504-
ContentHash: "1765694864050"
15051508
DependsOn:
15061509
- CodeBuildBuildCompleteRuleAllowEventRuleWorkshopStackCodeBuildReportLambdaFunctionD77C6091DA4A4BD8
15071510
- CodeBuildBuildCompleteRule06AAF17D

0 commit comments

Comments
 (0)