Skip to content

Commit 3d64eb2

Browse files
Merge pull request #296 from rustyrazorblade/stress-no-build
Improve base AMI setup time by using cassandra-easy-stress nightly build.
2 parents 5ba87c4 + 0c737e4 commit 3d64eb2

21 files changed

+1110
-137
lines changed

.github/workflows/packer-lint.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Packer Static Analysis
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "packer/**"
7+
- ".github/workflows/packer-lint.yml"
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- "packer/**"
13+
- ".github/workflows/packer-lint.yml"
14+
workflow_dispatch:
15+
16+
jobs:
17+
validate-packer:
18+
name: Validate Packer HCL Files
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Packer
25+
uses: hashicorp/setup-packer@main
26+
with:
27+
version: "latest"
28+
29+
- name: Initialize Packer
30+
run: |
31+
cd packer/base
32+
packer init .
33+
cd ../cassandra
34+
packer init .
35+
36+
- name: Validate base.pkr.hcl
37+
run: |
38+
cd packer/base
39+
packer validate .
40+
41+
- name: Validate cassandra.pkr.hcl
42+
run: |
43+
cd packer/cassandra
44+
packer validate .
45+
46+
shellcheck:
47+
name: Lint Shell Scripts
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v4
52+
53+
- name: Run ShellCheck
54+
uses: ludeeus/action-shellcheck@master
55+
with:
56+
scandir: "./packer"
57+
severity: error
58+
format: gcc
59+
60+
yamllint:
61+
name: Validate YAML Files
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout code
65+
uses: actions/checkout@v4
66+
67+
- name: Set up Python
68+
uses: actions/setup-python@v5
69+
with:
70+
python-version: "3.x"
71+
72+
- name: Install yamllint
73+
run: pip install yamllint
74+
75+
- name: Run yamllint
76+
run: |
77+
# Check if .yamllint.yml exists, use it; otherwise use default config
78+
if [ -f packer/.yamllint.yml ]; then
79+
yamllint -c packer/.yamllint.yml packer/
80+
else
81+
yamllint packer/
82+
fi

.github/workflows/packer-test.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Packer Script Testing
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'packer/**'
7+
- '.github/workflows/packer-test.yml'
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- 'packer/**'
13+
- '.github/workflows/packer-test.yml'
14+
workflow_dispatch:
15+
16+
jobs:
17+
test-individual-scripts:
18+
name: Test Individual Scripts
19+
runs-on: ubuntu-latest
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
script:
24+
- cassandra/install/install_cassandra_easy_stress.sh
25+
- base/install/install_docker.sh
26+
- base/install/install_python.sh
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Build test image
35+
run: |
36+
cd packer
37+
docker build -t easy-cass-lab-packer-test .
38+
39+
- name: Test script - ${{ matrix.script }}
40+
run: |
41+
cd packer
42+
./test-script.sh ${{ matrix.script }}
43+
44+
test-changed-scripts:
45+
name: Test Changed Scripts
46+
runs-on: ubuntu-latest
47+
if: github.event_name == 'pull_request'
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 0
53+
54+
- name: Set up Docker Buildx
55+
uses: docker/setup-buildx-action@v3
56+
57+
- name: Build test image
58+
run: |
59+
cd packer
60+
docker build -t easy-cass-lab-packer-test .
61+
62+
- name: Detect and test changed scripts
63+
run: |
64+
cd packer
65+
echo "Detecting changed shell scripts..."
66+
67+
# Get list of changed .sh files
68+
CHANGED_SCRIPTS=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^packer/.*\.sh$' | grep -v 'test-script.sh' || true)
69+
70+
if [ -z "$CHANGED_SCRIPTS" ]; then
71+
echo "No shell scripts changed in this PR"
72+
exit 0
73+
fi
74+
75+
echo "Changed scripts:"
76+
echo "$CHANGED_SCRIPTS"
77+
78+
# Test each changed script
79+
EXIT_CODE=0
80+
for script in $CHANGED_SCRIPTS; do
81+
# Remove 'packer/' prefix if present
82+
script_path="${script#packer/}"
83+
84+
# Skip deleted files
85+
if [ ! -f "$script" ]; then
86+
echo "⊘ $script_path was deleted, skipping test"
87+
continue
88+
fi
89+
90+
echo "Testing: $script_path"
91+
92+
if ./test-script.sh "$script_path"; then
93+
echo "✓ $script_path passed"
94+
else
95+
echo "✗ $script_path failed"
96+
EXIT_CODE=1
97+
fi
98+
done
99+
100+
exit $EXIT_CODE
101+
102+
test-base-provisioning:
103+
name: Test Base Provisioning Sequence
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: Checkout code
107+
uses: actions/checkout@v4
108+
109+
- name: Set up Docker Buildx
110+
uses: docker/setup-buildx-action@v3
111+
112+
- name: Test base provisioning
113+
run: |
114+
cd packer
115+
docker compose up --exit-code-from test-base test-base
116+
117+
- name: Show logs on failure
118+
if: failure()
119+
run: |
120+
cd packer
121+
docker compose logs test-base
122+
123+
test-cassandra-provisioning:
124+
name: Test Cassandra Provisioning Sequence
125+
runs-on: ubuntu-latest
126+
steps:
127+
- name: Checkout code
128+
uses: actions/checkout@v4
129+
130+
- name: Set up Docker Buildx
131+
uses: docker/setup-buildx-action@v3
132+
133+
- name: Test cassandra provisioning
134+
run: |
135+
cd packer
136+
docker compose up --exit-code-from test-cassandra test-cassandra
137+
138+
- name: Show logs on failure
139+
if: failure()
140+
run: |
141+
cd packer
142+
docker compose logs test-cassandra

CLAUDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ Before pushing code, verify it passes all checks:
5555

5656
**Note**: `ktlintFormat` auto-fixes many violations but can't fix all issues (e.g., line length). Always run `ktlintCheck` after formatting to catch remaining issues.
5757

58+
### Packer Script Testing
59+
60+
Test packer provisioning scripts locally using Docker (no AWS required):
61+
62+
```bash
63+
# Test base provisioning scripts
64+
./gradlew testPackerBase
65+
66+
# Test Cassandra provisioning scripts
67+
./gradlew testPackerCassandra
68+
69+
# Run all packer tests
70+
./gradlew testPacker
71+
72+
# Test a specific script
73+
./gradlew testPackerScript -Pscript=cassandra/install/install_cassandra_easy_stress.sh
74+
```
75+
76+
For more details, see [packer/README.md](packer/README.md) and [packer/TESTING.md](packer/TESTING.md).
77+
5878
## Development Rules
5979

6080
- All tests should pass before committing.

build.gradle.kts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,39 @@ tasks.test {
178178
}
179179
}
180180

181+
// Packer testing tasks
182+
tasks.register<Exec>("testPackerBase") {
183+
group = "Verification"
184+
description = "Test base packer provisioning scripts using Docker"
185+
workingDir = file("packer")
186+
commandLine = listOf("docker", "compose", "up", "--force-recreate", "--exit-code-from", "test-base", "test-base")
187+
}
188+
189+
tasks.register<Exec>("testPackerCassandra") {
190+
group = "Verification"
191+
description = "Test Cassandra packer provisioning scripts using Docker"
192+
workingDir = file("packer")
193+
commandLine = listOf("docker", "compose", "up", "--force-recreate", "--exit-code-from", "test-cassandra", "test-cassandra")
194+
}
195+
196+
tasks.register("testPacker") {
197+
group = "Verification"
198+
description = "Run all packer provisioning tests"
199+
dependsOn("testPackerBase", "testPackerCassandra")
200+
}
201+
202+
tasks.register<Exec>("testPackerScript") {
203+
group = "Verification"
204+
description = "Test a specific packer script (use -Pscript=path/to/script.sh)"
205+
workingDir = file("packer")
206+
doFirst {
207+
val scriptPath =
208+
project.findProperty("script")?.toString()
209+
?: throw GradleException("Please specify script path with -Pscript=path/to/script.sh")
210+
commandLine = listOf("./test-script.sh", scriptPath)
211+
}
212+
}
213+
181214
tasks.register("buildAll") {
182215
group = "Publish"
183216
// dependsOn("buildDeb")

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resilience4j = "2.2.0"
5656
# Gradle Plugins
5757
shadow = "8.1.1"
5858
versions = "0.53.0"
59-
ktlint = "13.1.0"
59+
ktlint = "14.0.1"
6060
detekt = "1.23.7"
6161
kover = "0.8.3"
6262

packer/.shellcheckrc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ShellCheck configuration for packer scripts
2+
# https://github.com/koalaman/shellcheck/wiki/Directive
3+
4+
# Require explicit shell specification at the top of scripts
5+
shell=bash
6+
7+
# Specify the minimum severity level
8+
# error, warning, info, style
9+
severity=warning
10+
11+
# Disabled checks (comma-separated list of codes)
12+
# Uncomment and modify if you need to disable specific checks
13+
# disable=SC2034,SC2086
14+
15+
# Enable all optional checks
16+
enable=all
17+
18+
# Source path for scripts that use 'source' command
19+
# This helps shellcheck find sourced files
20+
# source-path=SCRIPTDIR
21+
22+
# External sources that shellcheck should not complain about
23+
# Useful for sourced files that may not exist in the repo
24+
# external-sources=true

packer/.yamllint.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# yamllint configuration for packer YAML files
3+
# https://yamllint.readthedocs.io/en/stable/configuration.html
4+
5+
extends: default
6+
7+
rules:
8+
# Line length - allow longer lines for readability
9+
line-length:
10+
max: 120
11+
level: warning
12+
13+
# Indentation - 2 spaces
14+
indentation:
15+
spaces: 2
16+
indent-sequences: true
17+
18+
# Allow empty values
19+
empty-values:
20+
forbid-in-block-mappings: false
21+
forbid-in-flow-mappings: false
22+
23+
# Comments
24+
comments:
25+
min-spaces-from-content: 1
26+
27+
# Document start (---) is optional
28+
document-start:
29+
present: false
30+
31+
# Trailing spaces
32+
trailing-spaces: enable
33+
34+
# Truthy values (yes/no vs true/false)
35+
truthy:
36+
allowed-values: ['true', 'false', 'yes', 'no']
37+
check-keys: false
38+
39+
# Files to ignore
40+
ignore: |
41+
*.json

0 commit comments

Comments
 (0)