Skip to content

Commit be49404

Browse files
author
Yuriy Bezsonov
committed
WIP
1 parent d9e0355 commit be49404

52 files changed

Lines changed: 1415 additions & 1306 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
branches: [ "main" ]
1515

1616
jobs:
17-
build:
17+
build-java21:
1818
runs-on: ubuntu-latest
1919
env:
2020
AWS_REGION: 'us-east-1'
@@ -28,7 +28,6 @@ jobs:
2828
cache: maven
2929
- name: Java version
3030
run: java --version
31-
working-directory: ./apps/unicorn-store-spring/
3231
- name: Build unicorn-store-spring with Maven
3332
run: mvn -B clean package --file pom.xml --no-transfer-progress
3433
working-directory: ./apps/unicorn-store-spring/
@@ -37,10 +36,8 @@ jobs:
3736
working-directory: ./apps/unicorn-spring-ai-agent/
3837
- name: Install AWS CDK
3938
run: npm install -g aws-cdk
40-
working-directory: ./infrastructure/cdk/
4139
- name: AWS CDK version
4240
run: cdk version
43-
working-directory: ./infrastructure/cdk/
4441
- name: Build CDK Immersion Day infrastructure
4542
run: mvn clean package --no-transfer-progress
4643
working-directory: ./infrastructure/cdk/
@@ -57,6 +54,34 @@ jobs:
5754
run: docker build -t unicorn-store-javax:latest .
5855
working-directory: ./apps/unicorn-store-javax/
5956

57+
build-java25:
58+
runs-on: ubuntu-latest
59+
env:
60+
AWS_REGION: 'us-east-1'
61+
steps:
62+
- uses: actions/checkout@v4
63+
- name: Set up JDK 25
64+
uses: actions/setup-java@v4
65+
with:
66+
distribution: 'corretto'
67+
java-version: 25
68+
cache: maven
69+
- name: Java version
70+
run: java --version
71+
- name: Build unicorn-store-spring-java25 with Maven
72+
run: mvn -B clean package --file pom.xml --no-transfer-progress
73+
working-directory: ./apps/unicorn-store-spring-java25/
74+
- name: Install AWS CDK
75+
run: npm install -g aws-cdk
76+
- name: AWS CDK version
77+
run: cdk version
78+
- name: Build infra CDK
79+
run: mvn clean package --no-transfer-progress
80+
working-directory: ./infra/cdk/
81+
- name: CDK Synth infra
82+
run: cdk synth
83+
working-directory: ./infra/cdk/
84+
6085
# - name: Submit Dependency Snapshot
6186
# uses: advanced-security/maven-dependency-submission-action@v4
6287
# with:

.kiro/specs/infra/design.md

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ infra/
5252
│ └── java-spring-ai-agents-stack.yaml
5353
├── scripts/
5454
│ ├── ide/ # IDE setup scripts
55-
│ │ ├── bootstrap.sh # Full bootstrap orchestration
55+
│ │ ├── functions.sh # Shared helper functions (retry, logging, install)
56+
│ │ ├── bootstrap.sh # Full bootstrap orchestration (jq, Docker, AWS CLI, env vars)
5657
│ │ ├── vscode.sh # VS Code Server installation
5758
│ │ ├── code-editor.sh # AWS Code Editor installation
5859
│ │ ├── tools.sh # Base development tools
@@ -339,7 +340,8 @@ infra/cdk/src/main/resources/
339340
└── userdata.sh # Minimal UserData script with CloudWatch logging
340341
341342
infra/scripts/ide/
342-
├── bootstrap.sh # Full bootstrap orchestration
343+
├── functions.sh # Shared helper functions (retry_command, install_with_version, log_info)
344+
├── bootstrap.sh # Full bootstrap orchestration (jq, Docker, AWS CLI, environment setup)
343345
├── vscode.sh # VS Code Server installation and configuration
344346
├── code-editor.sh # AWS Code Editor installation
345347
├── tools.sh # Base development tools (Java, Node.js, kubectl, etc.)
@@ -355,25 +357,43 @@ infra/scripts/templates/
355357
└── java-spring-ai-agents.sh # Java-Spring-AI-Agents workshop post-deploy (same as base)
356358
```
357359

360+
#### Shared Functions Architecture
361+
All IDE scripts source `functions.sh` for consistent helper functions:
362+
- `retry_command(attempts, delay, fail_mode, tool_name, cmd)`: Retry with configurable failure handling
363+
- `retry_critical(tool_name, cmd)`: Retry with exit on failure (5 attempts, 5s delay)
364+
- `retry_optional(tool_name, cmd)`: Retry with warning on failure (continues execution)
365+
- `install_with_version(tool_name, install_cmd, version_cmd, fail_mode)`: Install and log version
366+
- `log_info(message)`: Timestamped logging
367+
- `download_and_verify(url, output, description)`: Download with retry
368+
358369
#### Bootstrap Flow
359370
```
360371
userdata.sh → bootstrap.sh → {IDE_TYPE}.sh → tools.sh → templates/{TEMPLATE_TYPE}.sh
361372
```
362373

363374
Where:
364375
- `userdata.sh`: Minimal UserData script that clones repo and runs bootstrap.sh with CloudWatch logging
365-
- `bootstrap.sh`: Full system setup, environment variables, calls IDE setup and template script
366-
- `{IDE_TYPE}.sh`: IDE-specific setup (vscode.sh or code-editor.sh)
367-
- `tools.sh`: Base development tools installation (Java, Node.js, kubectl, Helm, etc.)
376+
- `bootstrap.sh`: System setup (jq, Docker, AWS CLI), environment variables in `/etc/profile.d/workshop.sh`, calls IDE setup and template script
377+
- `{IDE_TYPE}.sh`: IDE-specific setup (vscode.sh or code-editor.sh), sources functions.sh
378+
- `tools.sh`: Base development tools installation (Java, Node.js, kubectl, Helm, etc.), sources functions.sh and workshop.sh
368379
- `templates/{TEMPLATE_TYPE}.sh`: Workshop-specific post-deploy (EKS setup, monitoring, analysis)
369380

381+
#### Environment Variables
382+
Scripts source `/etc/profile.d/workshop.sh` instead of re-fetching AWS variables. This file is created by bootstrap.sh and contains:
383+
- `AWS_REGION`, `AWS_DEFAULT_REGION`: AWS region from instance metadata
384+
- `ACCOUNT_ID`, `AWS_ACCOUNT_ID`: AWS account ID from STS
385+
- `EC2_PRIVATE_IP`, `EC2_DOMAIN`, `EC2_URL`: Instance networking
386+
- `IDE_DOMAIN`, `IDE_URL`, `IDE_PASSWORD`: IDE access
387+
- `JAVA_HOME`, `M2_HOME`: Development tool paths
388+
370389
#### Workshop Orchestration Pattern
371390
Workshop scripts follow a layered approach:
372-
1. **IDE Layer**: `bootstrap.sh` calls IDE setup (`vscode.sh` or `code-editor.sh`) and `tools.sh`
373-
2. **Tools Layer**: `tools.sh` provides foundational development tools (Java, Node.js, kubectl, Helm, etc.)
374-
3. **Workshop Layer**: Template scripts in `templates/` folder add workshop-specific setup (EKS, monitoring, analysis)
375-
4. **Error Handling**: Each layer implements proper error handling and progress feedback
376-
5. **Verification**: Final verification ensures all tools and services are operational
391+
1. **Bootstrap Layer**: `bootstrap.sh` installs jq, Docker, AWS CLI, creates `/etc/profile.d/workshop.sh` with all environment variables
392+
2. **IDE Layer**: `bootstrap.sh` calls IDE setup (`vscode.sh` or `code-editor.sh`) which sources `functions.sh`
393+
3. **Tools Layer**: `tools.sh` sources `functions.sh` and `workshop.sh`, provides foundational development tools
394+
4. **Workshop Layer**: Template scripts in `templates/` folder add workshop-specific setup (EKS, monitoring, analysis)
395+
5. **Error Handling**: Each layer implements proper error handling via shared `functions.sh`
396+
6. **Verification**: Final verification ensures all tools and services are operational
377397

378398
#### Configuration
379399
- **Template Type**: Configurable via `TEMPLATE_TYPE` environment variable (defaults to `base`)
@@ -388,6 +408,14 @@ Workshop scripts follow a layered approach:
388408
- `STACK_NAME` - AWS stack name
389409
- `TEMPLATE_TYPE` - template type
390410
- `GIT_BRANCH` - git branch (hardcoded to "main")
411+
- `PREFIX` - resource naming prefix (defaults to "workshop")
412+
413+
**Created by bootstrap.sh in `/etc/profile.d/workshop.sh`:**
414+
- `AWS_REGION`, `AWS_DEFAULT_REGION` - AWS region
415+
- `ACCOUNT_ID`, `AWS_ACCOUNT_ID` - AWS account ID
416+
- `EC2_PRIVATE_IP`, `EC2_DOMAIN`, `EC2_URL` - Instance networking
417+
- `IDE_DOMAIN`, `IDE_URL`, `IDE_PASSWORD` - IDE access
418+
- `JAVA_HOME`, `M2_HOME` - Development tool paths
391419

392420
#### Tool Version Management
393421
The system uses a hybrid approach for tool versions:
@@ -418,25 +446,36 @@ The system uses a hybrid approach for tool versions:
418446
- jq, Docker, git, Caddy: latest available in package repositories
419447

420448
#### Script Architecture
421-
Scripts are organized with helper functions and consistent error handling:
422-
423-
**Bootstrap Script (`ide-bootstrap.sh`):**
449+
Scripts are organized with shared helper functions and consistent error handling:
450+
451+
**Shared Functions (`functions.sh`):**
452+
- Central location for all helper functions used across IDE scripts
453+
- `retry_command()`: Configurable retry with attempts, delay, and failure mode
454+
- `retry_critical()`: Retry with exit on failure (5 attempts, 5s delay)
455+
- `retry_optional()`: Retry with warning on failure (continues execution)
456+
- `install_with_version()`: Install tool and log version in consistent format
457+
- `log_info()`: Timestamped logging
458+
- `download_and_verify()`: Download with retry and verification
459+
460+
**Bootstrap Script (`bootstrap.sh`):**
461+
- Sources functions.sh for shared helpers
462+
- Installs jq and Docker before IDE setup (services inherit docker group)
463+
- Creates `/etc/profile.d/workshop.sh` with all environment variables
424464
- Standardized on `dnf` package manager
425-
- Added error handling for critical operations (AWS CLI, git clone, CloudFront)
426-
- Improved logging and comments
465+
- Error handling with CloudFormation signaling
427466

428467
**VS Code Script (`vscode.sh`):**
468+
- Sources functions.sh for shared helpers
429469
- Helper functions eliminate repetitive `sudo -u ec2-user` patterns
430470
- `setup_user_file()` function for clean file creation
431471
- `run_as_user()` function for user command execution
432472
- Uses latest VS Code version by default
433473

434-
**IDE Script (`ide.sh`):**
474+
**Tools Script (`tools.sh`):**
475+
- Sources functions.sh and `/etc/profile.d/workshop.sh`
435476
- Function-based organization by tool category
436-
- Comprehensive logging with timestamps (`log_info()`)
437-
- Error handling and download verification (`handle_error()`, `download_and_verify()`)
438-
- Consistent output handling and cleanup
439-
- Removed redundant operations (multiple `java -version` calls)
477+
- Uses shared retry and install functions
478+
- No redundant AWS variable fetching
440479

441480
### Build Automation
442481

@@ -960,3 +999,22 @@ if ("java-on-aws-immersion-day".equals(templateType) || "java-on-amazon-eks".equ
960999
#### Property 34: Construct Simplification
9611000
*For any* Unicorn or JvmAnalysis construct, it should not create explicit ECR repositories when EcrRegistry is present
9621001
**Validates: Requirements 28.1, 28.2, 28.3**
1002+
1003+
1004+
### Correctness Properties for Shared Functions
1005+
1006+
#### Property 35: Shared Functions Sourcing
1007+
*For any* IDE script (bootstrap.sh, vscode.sh, code-editor.sh, tools.sh), it should source functions.sh for shared helper functions
1008+
**Validates: Requirements 30.1**
1009+
1010+
#### Property 36: Environment Variable Sourcing
1011+
*For any* script that needs AWS variables (AWS_REGION, ACCOUNT_ID), it should source /etc/profile.d/workshop.sh instead of re-fetching from metadata or API
1012+
**Validates: Requirements 30.4, 31.1, 31.2**
1013+
1014+
#### Property 37: Docker Installation Timing
1015+
*For any* bootstrap execution, Docker should be installed before IDE setup so that IDE services inherit docker group membership without requiring restart
1016+
**Validates: Requirements 30.5**
1017+
1018+
#### Property 38: Consistent Variable Naming
1019+
*For any* script referencing AWS region, it should use AWS_REGION variable name (not REGION) for consistency
1020+
**Validates: Requirements 31.1, 31.3**

.kiro/specs/infra/requirements.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,26 @@ This document specifies the requirements for creating a new AWS workshop infrast
383383

384384
1. THE Repository_Creation_Template SHALL apply an "Environment" tag with value "workshop" to all created repositories
385385
2. THE Repository_Creation_Template SHALL apply a "ManagedBy" tag with value "ecr-create-on-push" to all created repositories
386+
387+
388+
### Requirement 30
389+
390+
**User Story:** As a workshop developer, I want shared helper functions across all IDE scripts, so that I can maintain consistent error handling, logging, and retry logic without code duplication.
391+
392+
#### Acceptance Criteria
393+
394+
1. WHEN IDE scripts execute, THE system SHALL source a shared functions.sh file for common helper functions
395+
2. WHEN retry operations are needed, THE system SHALL use retry_command with configurable attempts, delay, and failure mode
396+
3. WHEN tools are installed, THE system SHALL use install_with_version to log tool name and version consistently
397+
4. WHEN AWS variables are needed, THE system SHALL source /etc/profile.d/workshop.sh instead of re-fetching from metadata/API
398+
5. WHEN Docker is installed, THE system SHALL install it in bootstrap.sh before IDE setup so services inherit docker group membership
399+
400+
### Requirement 31
401+
402+
**User Story:** As a workshop developer, I want consistent AWS variable naming across all scripts, so that I can avoid confusion between different variable names for the same values.
403+
404+
#### Acceptance Criteria
405+
406+
1. WHEN AWS region is referenced, THE system SHALL use AWS_REGION variable name consistently (not REGION)
407+
2. WHEN AWS account ID is referenced, THE system SHALL use ACCOUNT_ID variable name consistently
408+
3. WHEN workshop.sh is created, THE system SHALL set AWS_REGION, AWS_DEFAULT_REGION, ACCOUNT_ID, and AWS_ACCOUNT_ID for compatibility

.kiro/specs/infra/tasks.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,3 +927,54 @@
927927
- Runs after VPC endpoints are deleted (security groups depend on endpoints) ✅
928928
- Added ec2:DescribeSecurityGroups and ec2:DeleteSecurityGroup permissions ✅
929929
- _Requirements: 5.6_
930+
931+
932+
## Script Refactoring and Shared Functions (1400.x)
933+
934+
- [x] 1400.1 Create shared functions.sh helper file
935+
- Created infra/scripts/ide/functions.sh with shared helper functions ✅
936+
- Implemented retry_command(attempts, delay, fail_mode, tool_name, cmd) for configurable retry ✅
937+
- Implemented retry_critical and retry_optional convenience wrappers ✅
938+
- Implemented install_with_version for install + version logging ✅
939+
- Implemented log_info for timestamped logging ✅
940+
- Implemented download_and_verify for downloads with retry ✅
941+
- _Requirements: 6.6, 6.7_
942+
943+
- [x] 1400.2 Move Docker and jq installation to bootstrap.sh
944+
- Moved jq and Docker installation from tools.sh to bootstrap.sh ✅
945+
- Docker installed before IDE setup so service inherits docker group membership ✅
946+
- Eliminates need to restart IDE service after Docker installation ✅
947+
- _Requirements: 6.1, 6.7_
948+
949+
- [x] 1400.3 Update bootstrap.sh to source functions.sh
950+
- Added source of functions.sh at start of bootstrap.sh ✅
951+
- Removed duplicate function definitions ✅
952+
- Uses shared install_with_version for AWS CLI installation ✅
953+
- _Requirements: 6.6_
954+
955+
- [x] 1400.4 Update tools.sh to source functions.sh and workshop.sh
956+
- Added source of functions.sh at start of tools.sh ✅
957+
- Sources /etc/profile.d/workshop.sh for AWS_REGION instead of re-fetching ✅
958+
- Removed duplicate retry_command, log_info, download_and_verify definitions ✅
959+
- Removed redundant jq installation (now in bootstrap.sh) ✅
960+
- Fixed Kiro CLI sudo nesting issue ✅
961+
- _Requirements: 6.6, 6.7_
962+
963+
- [x] 1400.5 Update code-editor.sh to source functions.sh
964+
- Added source of functions.sh at start of code-editor.sh ✅
965+
- Removed duplicate function definitions ✅
966+
- _Requirements: 6.6_
967+
968+
- [x] 1400.6 Update vscode.sh to source functions.sh
969+
- Added source of functions.sh at start of vscode.sh ✅
970+
- Removed duplicate function definitions ✅
971+
- Extracted Caddy installation to function matching code-editor.sh structure ✅
972+
- _Requirements: 6.6_
973+
974+
- [x] 1400.7 Consolidate AWS variable sourcing across setup scripts
975+
- Updated eks.sh to source /etc/profile.d/workshop.sh instead of re-fetching ACCOUNT_ID, AWS_REGION ✅
976+
- Updated unicorn-store-spring.sh to source workshop.sh ✅
977+
- Updated analysis.sh to source workshop.sh ✅
978+
- Updated monitoring.sh to source workshop.sh ✅
979+
- Standardized on AWS_REGION variable name (not REGION) ✅
980+
- _Requirements: 6.6_

.kiro/specs/java25-spring-modernization/requirements.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,20 @@ When a Java/Spring developer sees this application, they should think:
229229
6. THE pom.xml SHALL be organized with sortpom plugin for consistent dependency ordering
230230
7. THE application.yaml SHALL be organized with logical sections and explanatory comments
231231

232-
### Requirement 19: Clean Configuration for Microservices
232+
### Requirement 19: Standardized Container Base Images
233+
234+
**User Story:** As a workshop attendee, I want consistent container base images across all Dockerfiles, so that I can fairly compare optimization techniques and have predictable behavior.
235+
236+
#### Acceptance Criteria
237+
238+
1. ALL Dockerfiles SHALL use `public.ecr.aws/docker/library/maven:3-amazoncorretto-25-al2023` as the builder image
239+
2. ALL Dockerfiles SHALL use `public.ecr.aws/docker/library/amazoncorretto:25-al2023` as the runner image
240+
3. THE Jib plugin in pom.xml SHALL use `public.ecr.aws/docker/library/amazoncorretto:25-al2023` as the base image
241+
4. WHEN CRaC is used, THE Dockerfile SHALL use `azul/zulu-openjdk:25-jdk-crac-latest` (exception - CRaC requires special JVM)
242+
5. WHEN GraalVM native image is built, THE Dockerfile SHALL use Mandrel builder image (exception - native compilation)
243+
6. THE standardization SHALL enable fair comparison of image sizes across optimization techniques
244+
245+
### Requirement 20: Clean Configuration for Microservices
233246

234247
**User Story:** As a workshop attendee, I want to see production-ready microservice configuration, so that I can understand best practices for containerized Java applications.
235248

0 commit comments

Comments
 (0)