Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI

on:
pull_request:
branches:
- main

jobs:
cpp-build-and-test:
name: C++ Build and Test
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Install C++ and Redis dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
libcppunit-dev \
libhiredis-dev \
redis-server

- name: Start Redis
run: |
sudo systemctl start redis-server
redis-cli ping

- name: Clean Redis state for tests
run: redis-cli FLUSHALL

- name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

- name: Build active C++ targets
run: cmake --build build -j2

- name: Run CTest
env:
REDIS_HOST: 127.0.0.1
REDIS_PORT: "6379"
REDIS_DB: "0"
run: ctest --test-dir build --output-on-failure

terraform-validate:
name: Terraform Validate
runs-on: ubuntu-latest

defaults:
run:
working-directory: Terraform

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Terraform
uses: hashicorp/setup-terraform@v3

- name: Check Terraform formatting
run: terraform fmt -check

- name: Initialize Terraform without backend
run: terraform init -backend=false

- name: Validate Terraform
run: terraform validate

shellcheck-userdata:
name: Shellcheck userdata
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Install ShellCheck
run: |
sudo apt-get update
sudo apt-get install -y shellcheck

- name: Lint userdata script
# The userdata.sh script uses defined env vars to pickup the parameter values.
# Added defaults in the normal way breaks terraform; not doing so causes shellcheck
# to complain about undefined variables. Ignore those warnings. Unfortunately,
# shellcheck doesn't support ignoring specific warnings for specific lines. jhrg 3/17/26
run: shellcheck --severity=error Terraform/userdata.sh
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ set

## Python code and C++ code

See the subdirectories for those.
See the subdirectories for those.

## CI

GitHub Actions pull request CI now validates the active code paths in this repo:

- C++ configure/build with CMake
- Redis-backed CppUnit tests via `ctest`
- Terraform `fmt -check`, `init -backend=false`, and `validate`
- `shellcheck` for `Terraform/userdata.sh`

The C++ workflow starts a local Redis server and clears it with `redis-cli FLUSHALL`
before running tests so CI begins from a clean Redis state.
21 changes: 13 additions & 8 deletions Terraform/userdata.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -uox pipefail
set -ueo pipefail
export DEBIAN_FRONTEND=noninteractive

# Log everything (even early failures)
Expand All @@ -12,9 +12,10 @@ REPO_URL="${repo_url}"
REDIS_ENDPOINT="${redis_endpoint}"
REDIS_MODE="${redis_mode}"


EFS_DNS="$EFS_ID.efs.$REGION.amazonaws.com"

echo "=== userdata start $(date -Is) ==="
echo "=== userdata start $$(date -Is) ==="
echo "REGION=$REGION"
echo "EFS_ID=$EFS_ID"
echo "EFS_DNS=$EFS_DNS"
Expand All @@ -36,7 +37,8 @@ mkdir -p "$MOUNT_POINT"

# Write fstab once (NO automount; just standard mount)
FSTAB_LINE="$EFS_DNS:/ $MOUNT_POINT nfs4 nfsvers=4.1,_netdev,noresvport,timeo=60,retrans=2 0 0"
if ! grep -qF "$EFS_DNS:/" /etc/fstab; then
if ! grep -qF "$EFS_DNS:/" /etc/fstab
then
echo "$FSTAB_LINE" >> /etc/fstab
fi

Expand All @@ -45,13 +47,15 @@ sleep 60

# Keep trying the exact mount command until it works (up to ~1 minutes)
for i in $(seq 1 300); do
if mountpoint -q "$MOUNT_POINT"; then
if mountpoint -q "$MOUNT_POINT"
then
echo "EFS already mounted at $MOUNT_POINT"
break
fi

echo "Attempt $i: mounting $EFS_DNS:/ to $MOUNT_POINT"
if mount -t nfs4 -o nfsvers=4.1,noresvport,timeo=60,retrans=2 "$EFS_DNS:/" "$MOUNT_POINT"; then
if mount -t nfs4 -o nfsvers=4.1,noresvport,timeo=60,retrans=2 "$EFS_DNS:/" "$MOUNT_POINT"
then
echo "Mounted OK on attempt $i"
break
fi
Expand All @@ -61,7 +65,8 @@ for i in $(seq 1 300); do
sleep 2
done

if ! mountpoint -q "$MOUNT_POINT"; then
if ! mountpoint -q "$MOUNT_POINT"
then
echo "ERROR: EFS never mounted. Giving up."
# Don't exit nonzero so instance still comes up for inspection
else
Expand Down Expand Up @@ -119,6 +124,6 @@ cd build/Cpp
# The simulator makes entries that are between 200 and 4000 bytes (approximately). If we want about 1,000 objects,
# set max bytes to about 2MB.
OPTIONS="--duration 300 --monitor-ms 10000 --blocking --read-sleep 20 --write-sleep 1000 --max-bytes 1000000"
./RedisFileCacheLRU_Simulator $OPTIONS --redis-host "$REDIS_ENDPOINT" --redis-port 6379 --cache-dir "$MOUNT_POINT/poc-cache" > /opt/simulator.log 2>&1 &
./RedisFileCacheLRU_Simulator "$OPTIONS" --redis-host "$REDIS_ENDPOINT" --redis-port 6379 --cache-dir "$MOUNT_POINT/poc-cache" > /opt/simulator.log 2>&1 &

echo "=== userdata end $(date -Is) ==="
echo "=== userdata end $$(date -Is) ==="
Loading