Build portable Linux native runtime
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
'use strict'
|
||||
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/explicit-function-return-type */
|
||||
|
||||
const { chmodSync, existsSync, mkdirSync, rmSync } = require('fs')
|
||||
const { join, resolve } = require('path')
|
||||
const { spawnSync } = require('child_process')
|
||||
|
||||
const projectRoot = resolve(__dirname, '..')
|
||||
const buildRoot = join(projectRoot, 'runtime-build', 'linux-x64')
|
||||
const stagingRoot = join(projectRoot, 'dist', 'native-runtime', 'linux-x64-stage')
|
||||
const archive = join(projectRoot, 'dist', 'native-runtime', 'aurora-native-0.1.0-linux-x64.tar.gz')
|
||||
|
||||
function run(command, args) {
|
||||
const result = spawnSync(command, args, { cwd: projectRoot, stdio: 'inherit' })
|
||||
if (result.error) throw result.error
|
||||
if (result.status !== 0) throw new Error(`${command} failed with exit code ${result.status}`)
|
||||
}
|
||||
|
||||
if (process.platform !== 'linux' || process.arch !== 'x64')
|
||||
throw new Error('This builder targets Linux x64 only.')
|
||||
mkdirSync(stagingRoot, { recursive: true })
|
||||
rmSync(stagingRoot, { recursive: true, force: true })
|
||||
mkdirSync(stagingRoot, { recursive: true })
|
||||
run('docker', ['build', '--pull', '--output', `type=local,dest=${stagingRoot}`, buildRoot])
|
||||
for (const executable of [
|
||||
'aurora-exec',
|
||||
'php',
|
||||
'php-fpm',
|
||||
'nginx',
|
||||
'mariadbd',
|
||||
'mariadb-install-db'
|
||||
]) {
|
||||
const path = join(stagingRoot, 'bin', executable)
|
||||
if (!existsSync(path)) throw new Error(`Builder did not produce ${path}`)
|
||||
chmodSync(path, 0o755)
|
||||
}
|
||||
run('node', ['scripts/smoke-native-runtime.cjs', stagingRoot])
|
||||
run('node', ['scripts/package-native-runtime.cjs', stagingRoot, archive])
|
||||
@@ -0,0 +1,40 @@
|
||||
'use strict'
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
|
||||
const { existsSync, readFileSync } = require('fs')
|
||||
const { join, resolve } = require('path')
|
||||
const { spawnSync } = require('child_process')
|
||||
|
||||
const root = resolve(process.argv[2] || '')
|
||||
if (!root || !existsSync(join(root, 'runtime.template.json')))
|
||||
throw new Error('Usage: node scripts/smoke-native-runtime.cjs <staging-directory>')
|
||||
const template = JSON.parse(readFileSync(join(root, 'runtime.template.json'), 'utf8'))
|
||||
const checks = [
|
||||
[
|
||||
'PHP',
|
||||
join(root, 'bin/php'),
|
||||
['--version'],
|
||||
template.components.find((item) => item.id === 'php')?.version
|
||||
],
|
||||
[
|
||||
'nginx',
|
||||
join(root, 'bin/nginx'),
|
||||
['-v'],
|
||||
template.components.find((item) => item.id === 'nginx')?.version
|
||||
],
|
||||
[
|
||||
'MariaDB',
|
||||
join(root, 'bin/mariadbd'),
|
||||
['--version'],
|
||||
template.components.find((item) => item.id === 'mariadb')?.version
|
||||
]
|
||||
]
|
||||
for (const [name, command, args, version] of checks) {
|
||||
const result = spawnSync(command, args, { encoding: 'utf8' })
|
||||
const output = `${result.stdout || ''}${result.stderr || ''}`
|
||||
if (result.error || result.status !== 0)
|
||||
throw result.error || new Error(`${name} smoke check failed: ${output}`)
|
||||
if (!version || !output.includes(version))
|
||||
throw new Error(`${name} did not report expected version ${version}: ${output}`)
|
||||
process.stdout.write(`${name} ${version} OK\n`)
|
||||
}
|
||||
Reference in New Issue
Block a user