fix(desktop): bundle the iRedMail engine and point the API at it#238
Open
luckycrm wants to merge 1 commit into
Open
fix(desktop): bundle the iRedMail engine and point the API at it#238luckycrm wants to merge 1 commit into
luckycrm wants to merge 1 commit into
Conversation
Mail server setup failed at step 7 in the packaged desktop app with "Engine transfer failed: tar failed (exit 1): tar: could not chdir to '<home>/Library/apps/email/engine'". The API resolves the engine tree with a cwd-relative fallback, resolve(process.cwd(), "../../apps/email/engine"), which only lands correctly when it runs from apps/api in the monorepo. The desktop spawns the API with cwd = userData, so on macOS that resolves two levels up to ~/Library/apps/email/engine. The tree was also never staged into the app bundle, so no path would have found it. Ship apps/email/engine as resources/mail-engine (1.5 MB) and set MAIL_SERVER_ENGINE_DIR at spawn, matching how migrations and the pglite assets are already staged and located. Dev is unaffected: without the env var the monorepo-relative fallback still applies. Also return a real error when the engine directory is absent. transferIn shells out to tar, so the failure surfaced as an opaque tar exit 1 that reads like an SSH/transport problem rather than a missing directory.
Member
|
nice one, gonna check out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken
Mail server setup fails at step 7 in the packaged desktop app (0.3.0, macOS):
Two separate causes, both only reachable in a packaged build:
The engine tree is never bundled.
build/stage.tsstages the API binary, dashboard, migrations and pglite assets, but notapps/email/engine. Nothing inOpenship.app/Contents/ResourcescontainsiRedMail.sh.The path the API falls back to is wrong there.
resolveLocalEngineDir()(apps/api/src/modules/mail/mail.service.ts) usesresolve(process.cwd(), "../../apps/email/engine"), which is correct only when the API runs fromapps/apiin the monorepo.services.tsspawns it withcwd: userData, so it resolves to~/Library/apps/email/engine— two levels above~/Library/Application Support/Openship. Confirmed against the shipped binary and the running process:bun devnever hits either one, because the dev layout resolves the same tree from the checkout.The change
Stage
apps/email/engineasresources/mail-engine(1.5 MB) and hand it to the API viaMAIL_SERVER_ENGINE_DIRat spawn — the same stage →extraResource→ env-var pattern already used forOPENSHIP_MIGRATIONS_DIRandOPENSHIP_PGLITE_ASSETS_DIR.MAIL_SERVER_ENGINE_DIRwas already supported byresolveLocalEngineDir(); nothing set it. Dev behaviour is unchanged: with the variable unset, the monorepo-relative fallback still applies.stepTransferEnginenow also checks the directory exists before callingtransferIn.transferInshells out totar, so a missing engine surfaced as a baretarexit 1, which reads like an SSH/transport failure rather than a missing directory.Verification
Live run. Against the shipped 0.3.0 app on macOS 15 targeting an Ubuntu 24.04 DigitalOcean droplet, with
MAIL_SERVER_ENGINE_DIRpointed at a copy of the engine tree — i.e. exactly the state this PR produces automatically. Step 7, which previously failed outright, now completes:Step 8 then passes as well (
iRedMail.shfound, made executable). Setup proceeds to step 9.Build.
bun run build/stage.ts(with the pinned Bun 1.3.3 from.bun-version) completes and producesresources/mail-engine/iRedMail.sh; the ssh2#25500canary still passes.Test. New
apps/desktop/test/bundled-resources.test.ts— a static contract scan in the style of the existingipc-contract.test.ts, checking that everythingstage.tsstages is shipped byforge.config.jsand, for the engine specifically, thatresourcePaths()exposes it and the API is spawned withMAIL_SERVER_ENGINE_DIR. Reverting the three source files and keeping the test reproduces the failure:With the fix: 6 passed.
Suite.
bun run test— 7/7 workspace tasks, 969 API tests passing.bun run --cwd apps/desktop lintandbun run --cwd apps/api lintclean.bun formatreformats a lot of pre-existing drift repo-wide; per CONTRIBUTING I dropped all of it and confirmed withprettier --checkthat none of the reformatting falls on lines this PR adds.Separate issue found downstream (not addressed here)
With the transfer fixed, setup reaches step 9 and fails there for an unrelated reason — the vendored engine is iRedMail 1.8.1, and the installer's own online version check rejects it:
check_new_iredmail()inpkgs/get_all.shqueriesl.iredmail.organdexit 255when upstream reportsUPDATE_AVAILABLE. Upstream is currently 1.8.4, so mail setup cannot complete on any build — packaged or dev — untilapps/email/engineis bumped. Replacing the tree with 1.8.4 locally gets past it; all the config keys the mail service generates (BACKEND,FIRST_DOMAIN,STORAGE_BASE_DIR,USE_FAIL2BAN, the DB password vars,DOMAIN_ADMIN_PASSWD_PLAIN, and the sixAUTO_*flags) still exist in 1.8.4, and it supports Ubuntu 24.04. That's a vendored-dependency bump and a different change, so it's left out of this PR — happy to open it separately if you'd like.I have not run a full
make+ complete iRedMail install end to end, for the reason above.