diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3913915 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +Thumbs.db +.project +.settings/ + +# Local overrides for build.xml (deploy.keyfile, deploy.key.passphrase, ...) +# — never commit a passphrase, even to a private repo. +build.local.properties diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..34f6390 --- /dev/null +++ b/build.xml @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + +The SSH deploy key isn't where this build expects it: + ${deploy.keyfile} + +If it already works from a different shell (e.g. WSL/git-bash) but not from +here, this is almost certainly the Windows-vs-WSL home directory split +described in xzpect-timer/build.xml's comments, not a missing key. Copy it +(and known_hosts, checked separately below) over from wherever it already +works, e.g. from a WSL bash shell: + + mkdir -p /mnt/c/Users/<you>/.ssh + cp ~/.ssh/sportrum_key_new /mnt/c/Users/<you>/.ssh/ + +If you keep this key somewhere else entirely (e.g. alongside the sportrum +webapp project's confdir/), point deploy.keyfile at it in +build.local.properties instead of moving the file. + + + + + +known_hosts isn't where this build expects it: + ${deploy.knownhosts} + +Same Windows-vs-WSL split as the deploy key above most likely applies here +too. Copy or append it over from wherever it already works (append, don't +overwrite, if the destination already has unrelated entries you want to +keep): + + cat ~/.ssh/known_hosts >> /mnt/c/Users/<you>/.ssh/known_hosts + +If this is truly the first time connecting to the target server from +anywhere, SSH in manually once first (e.g. +"ssh -p ${deploy.ssh.port} ${deploy.user}@<server>") and accept its host +key interactively — this build's scp/sshexec tasks deliberately don't +auto-trust unknown host keys. + + + + + + + + + + + +This build's scp/sshexec targets need JSch on ANT'S OWN classpath, not just +this project's taskdef classpathref (see lib.build/README.md). Re-run with +-lib, e.g.: + ant -lib lib.build "deploy(@local.sportrum.se)" + +Running from Eclipse instead? Add lib.build/jsch-*.jar under Window -> +Preferences -> Ant -> Runtime -> Classpath -> Ant Home Entries — same fix. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Available targets: + ant "install-scripts(@local.sportrum.se)" - sync upgrade.sh and friends to the server (does NOT run an upgrade) + ant "deploy(@local.sportrum.se)" - install-scripts(@local.sportrum.se), then run upgrade.sh, then verify the site responds + +Before the FIRST run against any given server: ssh -p ${deploy.ssh.port} ${deploy.user}@<that server> +once, interactively (accept the host key, then Ctrl+D) so ${deploy.knownhosts} +already has it — these targets do not auto-trust unknown host keys. + +Also run the sportrum webapp project's own "ant release-all" FIRST, against +the same server — it builds and uploads sportrum.war/manager.zip, which +upgrade.sh (run by the deploy target here) expects to already be sitting at +/home/sportrum/webapp/sportrum.war and /home/sportrum/manager.zip. This +project's build.xml never builds or uploads those itself. + +install-scripts/deploy are deliberately separate steps, not one big +"deploy" that both syncs scripts and upgrades: + - install-scripts(@server) only uploads this repo's control scripts + (upgrade.sh, upgrade-cmds.sh, upgrade-funs.sh, tomcat_ctl.sh, + restart.sh) to ${deploy.remotepath} on the server. Nothing on the + server is touched otherwise — no Tomcat stop, no backup, no DB + migration. + - deploy(@server) runs install-scripts(@server) first (so the server is + always running this repo's current scripts, never a stale hand-copied + version), then sshexecs upgrade.sh itself, then checks the site + responds afterwards. + +Because the upgrade is just upgrade.sh living on the server (at +${deploy.remotepath}), you don't need ant for it at all if you'd rather +not: run "ant install-scripts(@server)" whenever you like, then SSH in as +${deploy.user} and run "./upgrade.sh" (or "./restart.sh", for a plain +restart with no upgrade) yourself, at whatever moment you choose. + +Adding a new server: add + <target name="install-scripts(@new-server-hostname)" description="..."> + <upload-scripts host="new-server-hostname"/> + </target> + <target name="deploy(@new-server-hostname)" depends="install-scripts(@new-server-hostname)" description="..."> + <run-upgrade host="new-server-hostname"/> + <verify-upgrade host="new-server-hostname"/> + </target> +below — the shared sportrum user/key/port above cover it already, nothing +else to configure here. + + + + + + + + + + + + diff --git a/lib.build/README.md b/lib.build/README.md new file mode 100644 index 0000000..3f13a98 --- /dev/null +++ b/lib.build/README.md @@ -0,0 +1,64 @@ +# lib.build/ + +Third-party jars needed by `build.xml`, checked in so a fresh clone on any +machine can run `ant -lib lib.build "deploy(@local.sportrum.se)"` with +nothing to download. See the comment above `` +in `build.xml` for why a plain `classpathref` isn't always enough on its +own (short version: Ant always loads its own `Scp`/`SSHExec` classes from +whatever's already on Ant's own classpath — and if something else, like +Debian/Ubuntu's `ant-optional` apt package, already put a different/older +jsch there first, this project's own copy in `lib.build/` becomes invisible +to it no matter what the project's own classpath says). + +**Command line: always use `-lib lib.build`.** Confirmed this is required +whenever a system `ant-optional` package (or similar) is installed — that's +the case for a plain apt-installed Ubuntu/Debian `ant`. Leaving it off fails +fast with a clear message pointing back here, rather than a cryptic +`NoClassDefFoundError`. + +**Eclipse: try it with no extra configuration first.** Whether this is +needed in Eclipse depends entirely on whether that particular Eclipse +install's bundled Ant distribution ships its own conflicting `ant-jsch.jar`. +If yours hits `taskdef ... cannot be found: com/jcraft/jsch/Logger`, add +`lib.build/jsch-*.jar` under Window -> Preferences -> Ant -> Runtime -> +Classpath -> Ant Home Entries (same underlying fix as `-lib`, just via +Eclipse's UI instead of a flag). + +Currently just: + +- `jsch-2.28.7.jar` — [com.github.mwiede/jsch](https://mvnrepository.com/artifact/com.github.mwiede/jsch), + a maintained fork of the original com.jcraft:jsch (same package name, + drop-in). Ant's ``/`` tasks need this on the classpath; the + original jcraft version predates modern SSH key-exchange algorithms and + fails against current OpenSSH defaults. Direct download: + https://repo1.maven.org/maven2/com/github/mwiede/jsch/2.28.7/jsch-2.28.7.jar + + Same jar `xzpect-timer/lib.build/` uses — copied over rather than + re-resolved, so both projects are pinned to an identical, already-tested + version. If this ever needs a version bump, replace the jar here (and + probably there too, for consistency) and update the filename/link above — + nothing else in `build.xml` references the version number directly (it + just loads every `*.jar` under this folder). + +## Why not `ant-classloadertask`, like the sportrum webapp project? + +The sportrum webapp's own `build.xml` (its `release-all` target scps +`sportrum.war`/`manager.zip` to the server) avoids needing `-lib` at all, +via a third-party `` task +that injects the jsch jar directly into Ant's own running core classloader. +That trick only works on JDK 8 — it reflectively pokes +`URLClassLoader.addURL()`, which stopped being how the JVM's application +classloader works from JDK 9 onward. The webapp project gets away with it +only because it's still built on JDK 8; xzpect-timer's `build.xml` tested +this same approach directly against JDK 21 and confirmed it's a hard dead +end there (see xzpect-timer's `lib.build/README.md` for the exact +exceptions). + +This project (`sportrum-deploy`) deliberately follows xzpect-timer's +`-lib`-based approach instead of the webapp's, even though it's deployed +right alongside that JDK-8 webapp project: `ant deploy(@host)` here is a +separate Ant invocation, and there's no guarantee it always runs under the +same JDK as the webapp build — someone could easily run it from a newer +default `ant` on their machine. The `-lib` approach works on any JDK, so +it's the safer default here rather than inheriting an assumption tied to a +different project's toolchain. diff --git a/lib.build/jsch-2.28.7.jar b/lib.build/jsch-2.28.7.jar new file mode 100644 index 0000000..695b185 Binary files /dev/null and b/lib.build/jsch-2.28.7.jar differ