Tansy UI is a React component kit by OpenKhalix, named after the tansy
flower ("golden buttons"). It has two surfaces:
- A landing page built entirely from the kit's own components, with
five featured parts, a palette-switching playground form, and links
into Storybook
- A Storybook workshop with Tansy branding, a Welcome page, palette
toolbar and accessibility checks
Includes 15 components with colocated tokens and stories, seven brand
palettes, a palette-aware logo, a Docker/nginx image, a scripted
cPanel deploy, and a generator that keeps the landing page catalogue
in sync with Storybook.
81 lines
3.5 KiB
Markdown
81 lines
3.5 KiB
Markdown
# Deploying Tansy UI to cPanel
|
|
|
|
One command replaces the old manual sequence. There is nothing to delete
|
|
first and no manual overwrite: the cPanel-side script treats the uploaded
|
|
archive as the complete truth for the docroot and prunes everything else.
|
|
|
|
## Use
|
|
|
|
```bash
|
|
python3 scripts/deploy.py # build + package + upload + verify
|
|
python3 scripts/deploy.py --deploy-only # upload the existing build
|
|
python3 scripts/deploy.py --build-only # build and package, upload nothing
|
|
python3 scripts/deploy.py --dry-run # package and report, upload nothing
|
|
```
|
|
|
|
## One-time setup
|
|
|
|
```bash
|
|
cp scripts/deploy.env.example scripts/deploy.env
|
|
$EDITOR scripts/deploy.env # fill in CPANEL_PASS
|
|
chmod 600 scripts/deploy.env
|
|
```
|
|
|
|
`scripts/deploy.env` is gitignored. Every value can also come from the
|
|
environment instead, which is what CI should do.
|
|
|
|
## How it works
|
|
|
|
1. `npm ci`, `npm run lint`, `npm run build`, `npm run build-storybook`
|
|
2. Stage `dist/` at the root and `storybook-static/` under `docs/`, zip with
|
|
Python's `zipfile` (there is no `zip` binary on the build host), base64 it
|
|
3. Upload `scripts/cpanel-deploy.php` to the docroot over the cPanel UAPI
|
|
4. POST the base64 payload to it with a `Host` header for the subdomain,
|
|
pointed at the origin IP so Cloudflare is bypassed
|
|
5. The PHP extracts, then deletes anything the archive did not contain
|
|
6. Rewrite the hardened `.htaccess` and verify the site
|
|
|
|
## Why the archive can be authoritative
|
|
|
|
Vite and Storybook both emit content-hashed filenames
|
|
(`index-DHOur7R8.js`, `Alert.stories-CL8ipgGJ.js`), so a new build never
|
|
overwrites an old file. Without pruning, every deploy leaves its previous
|
|
bundles behind. The prune step is what keeps the docroot at exactly one
|
|
build.
|
|
|
|
`KEEP_TOP` in `deploy.py` lists the names the prune must never touch:
|
|
`.htaccess`, `.user.ini`, `php.ini`, `cgi-bin`, `.well-known`. cPanel owns
|
|
those; removing `.htaccess` would take the site down.
|
|
|
|
## Traps this script works around
|
|
|
|
- **PHP is disabled in the hardened `.htaccess`.** The deployer cannot run
|
|
until it is lifted, so the script writes a PHP-enabled copy, deploys, then
|
|
restores the hardened one. It verifies PHP executes *before* trusting the
|
|
upload, and verifies PHP is off again afterwards.
|
|
- **A PHP parse error is nearly invisible.** The server returns an empty
|
|
body and leaves `_deploy.php` on disk, which looks identical to "the
|
|
upload was ignored". The real cause only shows up in
|
|
`/home/<CPANEL_USER>/logs/php.error.log`. The script therefore runs `php -l`
|
|
locally before uploading and aborts if it fails. This is why `php-cli` and
|
|
`php-zip` are required on the build host.
|
|
- **`protected` is a reserved PHP keyword.** `const PROTECTED = [...]` is a
|
|
parse error. The constant is `PRESERVE`.
|
|
- **The `Host` header is required.** Without it the request hits the
|
|
server's default vhost and cPanel answers with its own 404 page.
|
|
|
|
## Verifying a change to the prune logic
|
|
|
|
The prune step deletes files, so test it against a fixture rather than
|
|
production. Build a fake docroot containing a previous build plus cPanel's
|
|
files, run the real script under `php-cli`, and assert that current files
|
|
survive, stale ones are gone, and the preserved names are untouched.
|
|
|
|
## Wiring it into CI
|
|
|
|
`scripts/deploy.py` is the whole deploy; a workflow only has to supply
|
|
credentials and run it. Note that the Gitea runner's job timeout is 360 s
|
|
and `npm ci` plus a cold Storybook build is likely to exceed that, so either
|
|
raise `runner.timeout` in the runner config or run this from a machine that
|
|
already has `node_modules`.
|