Skip to content

A full-featured download manager.

fix(build): include the Motrix license in Server artifacts (#1983)

Dr_rOot5034b8e3ba6d
diff --git a/Dockerfile b/Dockerfile
index 5630dea4..268971d7 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -74,6 +74,7 @@ COPY --from=build --chown=node:node /app/dist/server-app/bin/aria2c ./bin/aria2c
COPY --from=full-root-production-deps --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/extra/aria2.conf ./extra/aria2.conf
COPY --from=build --chown=node:node /app/dist/builtin-plugins ./builtin-plugins
+COPY --from=build --chown=node:node /app/LICENSE ./LICENSE
COPY --from=build --chown=node:node /app/THIRD_PARTY_NOTICES.md ./THIRD_PARTY_NOTICES.md
COPY --from=build --chown=node:node /app/THIRD_PARTY_NOTICES.zh-CN.md ./THIRD_PARTY_NOTICES.zh-CN.md
COPY --from=build --chown=node:node /app/THIRD_PARTY_LICENSES ./THIRD_PARTY_LICENSES
diff --git a/scripts/server-runtime-dependencies.json b/scripts/server-runtime-dependencies.json
index d5bd4782..ebc419c2 100644
--- a/scripts/server-runtime-dependencies.json
+++ b/scripts/server-runtime-dependencies.json
@@ -56,6 +56,11 @@
}
],
"resourceInputs": [
+ {
+ "source": "LICENSE",
+ "destination": "LICENSE",
+ "type": "file"
+ },
{
"source": "THIRD_PARTY_LICENSES",
"destination": "THIRD_PARTY_LICENSES",
diff --git a/scripts/smoke-server-image.mjs b/scripts/smoke-server-image.mjs
index 2f70f0e4..729fec36 100644
--- a/scripts/smoke-server-image.mjs
+++ b/scripts/smoke-server-image.mjs
@@ -593,6 +593,8 @@ async function assertRuntimeContract(name, url, token, identity, timeoutMs) {
'test -w /downloads',
'test -w /data/tmp',
'test ! -w /app',
+ 'test -s /app/LICENSE',
+ 'test -s /app/THIRD_PARTY_NOTICES.md',
'test -s /data/motrix.db',
'test "$MOTRIX_ARIA2_BIN" = "/app/bin/aria2c"',
'test "$SSL_CERT_FILE" = "/etc/ssl/certs/ca-certificates.crt"',
diff --git a/scripts/verify-server-package.mjs b/scripts/verify-server-package.mjs
index 194b38d4..3f46dd90 100644
--- a/scripts/verify-server-package.mjs
+++ b/scripts/verify-server-package.mjs
@@ -323,6 +323,24 @@ export async function verifyServerPackage(options) {
}
return `${tree.files.length} regular files and no symlinks`
})
+ await check('project-license', async () => {
+ if (
+ typeof appManifest?.license !== 'string' ||
+ appManifest.license === ''
+ ) {
+ throw new Error('generated package.json has no project license')
+ }
+ const licensePath = path.join(stageRoot, 'LICENSE')
+ const info = await lstat(licensePath)
+ if (!info.isFile()) {
+ throw new Error('LICENSE is not a regular file')
+ }
+ const text = await readFile(licensePath, 'utf8')
+ if (text.trim() === '') {
+ throw new Error('LICENSE is empty')
+ }
+ return `Motrix ${appManifest.license} license is included`
+ })
await check('bundled-engine', async () => {
if (!engineInput) return 'runtime contract does not bundle an engine'
const assetKey = `${target.platform}-${target.arch}`
diff --git a/tests/check-third-party-notices.test.ts b/tests/check-third-party-notices.test.ts
index 4aa9fd4b..4bea1e67 100644
--- a/tests/check-third-party-notices.test.ts
+++ b/tests/check-third-party-notices.test.ts
@@ -362,6 +362,7 @@ describe('third-party graph dependency notices', () => {
).toContain(`legal/${artifact}`)
}
for (const destination of [
+ 'LICENSE',
'THIRD_PARTY_NOTICES.md',
'THIRD_PARTY_NOTICES.zh-CN.md',
'THIRD_PARTY_LICENSES',
diff --git a/tests/scripts/audit-server-runtime.test.ts b/tests/scripts/audit-server-runtime.test.ts
index 156254f5..036d8603 100644
--- a/tests/scripts/audit-server-runtime.test.ts
+++ b/tests/scripts/audit-server-runtime.test.ts
@@ -255,6 +255,7 @@ describe('Server package contracts', () => {
'motrix-admin.mjs',
])
expect(contract.resourceInputs.map((entry) => entry.source)).toEqual([
+ 'LICENSE',
'THIRD_PARTY_LICENSES',
'THIRD_PARTY_NOTICES.md',
'THIRD_PARTY_NOTICES.zh-CN.md',
diff --git a/tests/scripts/docker-server-runtime.test.ts b/tests/scripts/docker-server-runtime.test.ts
index 80fe69bb..53322f03 100644
--- a/tests/scripts/docker-server-runtime.test.ts
+++ b/tests/scripts/docker-server-runtime.test.ts
@@ -194,6 +194,7 @@ describe('Docker Server runtime staging contract', () => {
expect(imageSmoke).toContain('Save directory is not writable: /downloads')
expect(imageSmoke).toContain('did not survive container restart')
expect(imageSmoke).toContain("'SQLite3-Persistence'")
+ expect(imageSmoke).toContain("'test -s /app/LICENSE'")
expect(imageSmoke).toContain("'test ! -e /usr/bin/aria2c'")
expect(imageSmoke).toContain(
'\'test "$(readlink /proc/$aria2_pid/exe)" = "/app/bin/aria2c"\''
diff --git a/tests/scripts/verify-server-package.test.ts b/tests/scripts/verify-server-package.test.ts
index e992cbf7..419bf014 100644
--- a/tests/scripts/verify-server-package.test.ts
+++ b/tests/scripts/verify-server-package.test.ts
@@ -98,6 +98,11 @@ function fixtureContract() {
},
],
resourceInputs: [
+ {
+ source: 'LICENSE',
+ destination: 'LICENSE',
+ type: 'file',
+ },
{
source: 'legal/notice.txt',
destination: 'legal/notice.txt',
@@ -146,6 +151,7 @@ async function createStagedFixture(
2
)}\n`
)
+ await writeFixtureFile(root, 'LICENSE', 'MIT License\n')
await writeFixtureFile(
root,
'dist/server/index.mjs',
@@ -207,7 +213,7 @@ async function createStagedFixture(
const engineBytes = nativeHeader('darwin', 'arm64')
await writeFixtureFile(root, 'extra/darwin/arm64/aria2c', engineBytes)
await chmod(path.join(root, 'extra/darwin/arm64/aria2c'), 0o755)
- contract.resourceInputs.unshift({
+ contract.resourceInputs.splice(1, 0, {
source: 'extra/{platform}/{arch}/{aria2Binary}',
destination: 'bin/{aria2Binary}',
type: 'file',
@@ -311,6 +317,17 @@ describe('verifyServerPackage', () => {
await expect(verifyFixture(fixture)).rejects.toThrow()
})
+ it('rejects a staged Server artifact without the Motrix license', async () => {
+ const fixture = await createStagedFixture()
+ await rm(path.join(fixture.stageRoot, 'LICENSE'))
+
+ await expect(verifyFixture(fixture)).rejects.toThrow('project-license')
+ const report = JSON.parse(await readFile(fixture.reportPath, 'utf8'))
+ expect(report.checks).toContainEqual(
+ expect.objectContaining({ id: 'project-license', passed: false })
+ )
+ })
+
it('rejects target drift and foreign native binaries', async () => {
const fixture = await createStagedFixture()
const stageManifestPath = path.join(