feat(deploy): publish Nodecast and Laya images together (#31)
Update the Docker build/push helper to build and push both application and Laya images, and document the configurable image targets. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
63
test/dockerBuildPushScript.test.js
Normal file
63
test/dockerBuildPushScript.test.js
Normal file
@ -0,0 +1,63 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const root = path.resolve(__dirname, '..');
|
||||
const script = path.join(root, 'scripts', 'docker-build-push.sh');
|
||||
|
||||
function runWithMockDocker(args = [], env = {}) {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nodecast-docker-build-push-'));
|
||||
const bin = path.join(dir, 'bin');
|
||||
fs.mkdirSync(bin);
|
||||
const log = path.join(dir, 'docker.log');
|
||||
const docker = path.join(bin, 'docker');
|
||||
fs.writeFileSync(docker, `#!/usr/bin/env bash\nprintf '%s\\n' "$*" >> "${log}"\n`);
|
||||
fs.chmodSync(docker, 0o755);
|
||||
const result = spawnSync('bash', [script, ...args], {
|
||||
cwd: root,
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: `${bin}${path.delimiter}${process.env.PATH}`,
|
||||
...env
|
||||
},
|
||||
encoding: 'utf8'
|
||||
});
|
||||
const commands = fs.existsSync(log) ? fs.readFileSync(log, 'utf8').trim().split('\n').filter(Boolean) : [];
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
return {
|
||||
result,
|
||||
commands
|
||||
};
|
||||
}
|
||||
|
||||
test('docker build/push script builds and pushes Nodecast and Laya images by default', () => {
|
||||
const { result, commands } = runWithMockDocker();
|
||||
assert.equal(result.status, 0, result.stderr || result.stdout);
|
||||
assert.deepEqual(commands, [
|
||||
`build --file ${path.join(root, 'Dockerfile')} --tag gitea.anthonybouteiller.ovh/blomios/nodecast-tv:latest ${root}`,
|
||||
`build --file ${path.join(root, 'Dockerfile.laya')} --tag gitea.anthonybouteiller.ovh/blomios/nodecast-tv-laya:latest ${root}`,
|
||||
'push gitea.anthonybouteiller.ovh/blomios/nodecast-tv:latest',
|
||||
'push gitea.anthonybouteiller.ovh/blomios/nodecast-tv-laya:latest'
|
||||
]);
|
||||
});
|
||||
|
||||
test('--no-push builds both images and skips both pushes', () => {
|
||||
const { result, commands } = runWithMockDocker(['--no-push']);
|
||||
assert.equal(result.status, 0, result.stderr || result.stdout);
|
||||
assert.deepEqual(commands, [
|
||||
`build --file ${path.join(root, 'Dockerfile')} --tag gitea.anthonybouteiller.ovh/blomios/nodecast-tv:latest ${root}`,
|
||||
`build --file ${path.join(root, 'Dockerfile.laya')} --tag gitea.anthonybouteiller.ovh/blomios/nodecast-tv-laya:latest ${root}`
|
||||
]);
|
||||
});
|
||||
|
||||
test('DRY_RUN=true builds both images and skips both pushes', () => {
|
||||
const { result, commands } = runWithMockDocker([], { DRY_RUN: 'true' });
|
||||
assert.equal(result.status, 0, result.stderr || result.stdout);
|
||||
assert.deepEqual(commands, [
|
||||
`build --file ${path.join(root, 'Dockerfile')} --tag gitea.anthonybouteiller.ovh/blomios/nodecast-tv:latest ${root}`,
|
||||
`build --file ${path.join(root, 'Dockerfile.laya')} --tag gitea.anthonybouteiller.ovh/blomios/nodecast-tv-laya:latest ${root}`
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user