Skip to content

Add Docker-based test suite and fix install/uninstall for all 6 OSes#35

Closed
DASimp wants to merge 5 commits into
mainfrom
feature/uninstall-support
Closed

Add Docker-based test suite and fix install/uninstall for all 6 OSes#35
DASimp wants to merge 5 commits into
mainfrom
feature/uninstall-support

Conversation

@DASimp
Copy link
Copy Markdown
Contributor

@DASimp DASimp commented May 8, 2026

Summary

This PR adds a complete Docker-based automated test suite covering all 6 supported OSes, wires up CI, and fixes three bugs in simplerisk-setup.sh uncovered during testing.

What changed

New: Docker test infrastructure (tests/)

File Purpose
tests/run-tests.sh Orchestrator: build image → start container → install → verify → uninstall → verify across all 6 OS slugs
tests/verify-install.sh 24-point post-install checklist: services running, files present, DB accessible, SimpleRisk web UI reachable, cron job installed, SSL cert present, PHP settings applied
tests/verify-uninstall.sh 12-point post-uninstall checklist: packages removed, files/dirs gone, DB dropped, cron job removed
tests/dockerfiles/Dockerfile.ubuntu-{22.04,24.04} Pre-installs lamp-server^ with policy-rc.d deny during build; starts services before the setup script runs to replicate a real server state
tests/dockerfiles/Dockerfile.debian-{12,13} /etc/init.d/mysql shim that manages mysqld directly (no systemd); policy-rc.d deny gate during image build
tests/dockerfiles/Dockerfile.centos-stream-{9,10} /usr/local/bin/systemctl shim (takes PATH precedence over the real systemctl installed by MySQL's systemd RPM dep) that starts/stops mysqld and httpd directly; no-op shims for firewall-cmd, setsebool, chcon; innodb_use_native_aio=0 for Docker overlayfs

All containers run with --init + tail -f /dev/null (no systemd as PID 1) — required for Docker Desktop on Windows where cgroup v2 is unavailable.

New: CI (.github/workflows/install-test.yml)

Matrix workflow over all 6 OSes triggered on push/PR to main. Uses fail-fast: false so all OSes always run.

New: CLAUDE.md

Project documentation for Claude Code describing the repo structure, supported OSes, how to run tests, and key conventions.

Bug fixes in simplerisk-setup.sh

1. --uninstall flag was silently ignored
The flag was parsed but perform_installation was always called. Added routing in setup() to call perform_uninstallation() when UNINSTALL is set, along with a dedicated ask_user_uninstall() prompt and uninstall_final_message().

2. CentOS/RHEL: php-cli not installed on el10
On CentOS Stream 10, php-cli is only a Recommends (weak) dependency of php. Without it, which php returns empty and the backup cron job installation fails with Invalid crontab file. Fixed by adding php-cli explicitly to the dnf install line (no-op on el9/el8 where it is a hard dep).

3. CentOS/RHEL 10: mysql8.4-server AppStream conflict
CentOS Stream 10's AppStream ships mysql8.4-server, which DNF pulls in as a weak dependency and which conflicts on dozens of files (including /usr/sbin/mysqld) with mysql-community-server from dev.mysql.com. Fixed by adding --exclude 'mysql8.4*' to the dnf install mysql-community-server command. No-op on el9/el8 where the package doesn't exist.

Test results

All 6 OSes pass the full 7-step suite (build → start → install → verify-install → uninstall → verify-uninstall) on Docker Desktop for Windows:

  PASS  ubuntu-22.04
  PASS  ubuntu-24.04
  PASS  debian-12
  PASS  debian-13
  PASS  centos-stream-9
  PASS  centos-stream-10

  All 6 tests passed.

Reviewer notes

  • The systemctl shim on CentOS/RHEL is placed at /usr/local/bin/systemctl so it takes PATH precedence over /usr/bin/systemctl (which gets overwritten by MySQL's systemd RPM dependency). On a real Linux host running systemd, /usr/local/bin/ still comes first in PATH — if this becomes a concern for production use the shim could add a check for systemd as PID 1 and exec the real binary.
  • The CI workflow uses ubuntu-latest runners; systemd is available there but the uses_systemd() function in run-tests.sh currently returns false for all OSes (comment explains why). This can be revisited if a future CI environment supports cgroup v2 in Docker.

🤖 Generated with Claude Code

DASimp and others added 5 commits May 8, 2026 12:21
## Test infrastructure (new)

- tests/run-tests.sh: orchestrates build → install → verify → uninstall → verify
  across all 6 supported OSes; runs each OS sequentially with full logging to
  tests/logs/<os-slug>/
- tests/verify-install.sh: 24-point post-install checklist (services running,
  files present, DB accessible, SimpleRisk web UI reachable, cron job installed,
  SSL cert present, PHP settings applied)
- tests/verify-uninstall.sh: 12-point post-uninstall checklist (packages removed,
  files/dirs gone, DB dropped, cron job removed)
- tests/dockerfiles/Dockerfile.ubuntu-{22.04,24.04}: pre-install lamp-server^ with
  policy-rc.d deny so services are installed but not started; start them before
  running the setup script to match a real server state
- tests/dockerfiles/Dockerfile.debian-{12,13}: /etc/init.d/mysql shim that manages
  mysqld directly (no systemd); /usr/sbin/policy-rc.d deny gate during image build
- tests/dockerfiles/Dockerfile.centos-stream-{9,10}: /usr/local/bin/systemctl shim
  (takes PATH precedence over real systemctl installed by MySQL's systemd RPM dep)
  that manages mysqld and httpd directly; no-op shims for firewall-cmd, setsebool,
  chcon; innodb_use_native_aio=0 for Docker overlayfs compatibility
- .github/workflows/install-test.yml: CI matrix over all 6 OSes on push/PR to main
- CLAUDE.md: project documentation for Claude Code

## Bug fixes in simplerisk-setup.sh

- Add --uninstall flag: routes to per-OS uninstall functions with dedicated
  ask_user_uninstall() prompt and uninstall_final_message(); previously the flag
  was accepted but silently fell through to installation
- CentOS/RHEL: add php-cli to explicit dnf install list — on el10 it is a
  Recommended (weak) dep of php and was being silently omitted
- CentOS/RHEL: add --exclude 'mysql8.4*' to mysql-community-server install —
  CentOS Stream 10's AppStream ships mysql8.4-server which conflicts on
  /usr/sbin/mysqld; the exclude is a no-op on el9/el8

All 6 OS tests (ubuntu-22.04, ubuntu-24.04, debian-12, debian-13,
centos-stream-9, centos-stream-10) pass the full 7-step suite locally on
Docker Desktop for Windows.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…fix CentOS start

Three CI failures fixed:

1. Dockerfile heredoc parse error (Debian-12, Debian-13, CentOS-9, CentOS-10)
   Docker's standard Dockerfile parser treats `RUN cat > /file << 'EOF'` as a
   single-line RUN — subsequent lines are parsed as new Dockerfile instructions,
   causing "unknown instruction: PIDFILE=..." errors on the Linux CI runner.
   Fix: extract the mysql init script and systemctl shim to separate files
   (mysql-init-debian.sh, systemctl-shim-centos.sh) and use COPY + chmod.
   Also add eol=lf to .gitattributes for *.sh, Dockerfile*, and *.yml so CRLF
   conversion on Windows never affects files parsed on Linux.

2. Ubuntu Apache restart timeout during apt post-install triggers
   The libapache2-mod-php post-install script fires `service apache2 restart`
   multiple times in quick succession.  Without --init (tini as PID 1), child
   processes are not properly reaped and a graceful restart can hang for the
   full 60s timeout.  Fix: add --init to all docker run commands in the CI
   workflow (matches what run-tests.sh already does locally).

3. CentOS CI container start used the systemd path
   The CI workflow started CentOS containers with --cgroupns=host / --tmpfs
   expecting systemd as PID 1, then waited for multi-user.target.  But the
   Dockerfiles use the /usr/local/bin/systemctl shim (no real systemd).
   Fix: unify container start for all OSes to --init + tail -f /dev/null;
   remove the separate CentOS systemd-start step and the "Wait for systemd"
   step entirely.

Also adds a "Start pre-installed services" step in CI for Ubuntu only, to
mirror what run-tests.sh does locally: start MySQL and Apache before the
setup script runs, since Ubuntu images pre-install lamp-server^ during the
Docker build (services blocked by policy-rc.d).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
On CentOS/RHEL with MySQL 8.4.9, appending sql_mode to /etc/my.cnf did not
take effect after restart — the vendor-supplied files in /etc/my.cnf.d/ appear
to override it.  Two-part fix:

1. Write sql_mode to /etc/my.cnf.d/zz-simplerisk.cnf (the "zz-" prefix
   ensures it sorts last alphabetically among included files, so it wins
   regardless of what other files the MySQL RPM installs).

2. After the restart, also run SET GLOBAL sql_mode=... so the change is
   applied to the running instance immediately, without relying solely on
   config-file parsing order.

Also enhances the CI diagnostics step to dump /etc/my.cnf, all files in
/etc/my.cnf.d/, and the live sql_mode value on failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Switch all package removal steps in uninstall_ubuntu_debian,
uninstall_centos_rhel, and uninstall_suse from exec_cmd (bail on
failure) to exec_cmd_nobail so the uninstaller continues even when
packages were never installed or only partially set up.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The mysql84-community-release RPM (updated in-place to -3) now also
enables a mysql-9.7-lts-community repo. DNF was resolving
mysql-community-server to 9.7.0 instead of 8.4.x. Add
--disablerepo='mysql-9*' to the install command so we always get
the 8.4 LTS release.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@DASimp
Copy link
Copy Markdown
Contributor Author

DASimp commented May 12, 2026

Closing — all changes from this PR have been moved to simplerisk/setup-scripts-dev#13 (merged) to keep CI/test infrastructure out of the public repo and away from external contributors. The bug fixes to simplerisk-setup.sh are included there as well.

@DASimp DASimp closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant