first cycle lab release
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fixture, seal } from './runtime-fixture.mjs';
|
||||
import { runtime } from '../../platform/runtime.mjs';
|
||||
import { deployOnHost, deployableRelease, releaseName, sha256 } from '../../platform/deployment.mjs';
|
||||
|
||||
export function setup(t){
|
||||
const f=fixture(t);
|
||||
const manifest=JSON.parse(fs.readFileSync(path.join(f.release,'manifest.json')));
|
||||
manifest.git={dirty:false,commit:'1'.repeat(40)};manifest.managed_files={server:[]};
|
||||
fs.writeFileSync(path.join(f.release,'manifest.json'),JSON.stringify(manifest));seal(f.release);
|
||||
// Health's actual waiting/state machine is tested separately. This adapter
|
||||
// substitutes readiness, while retaining real binding/lock/Compose checks.
|
||||
f.execute=options=>{
|
||||
const args=options.args[0]==='health'?['ps']:options.args.filter((item,index,array)=>item!=='--wait'&&item!=='--wait-timeout'&&array[index-1]!=='--wait-timeout');
|
||||
const result=runtime({...options,args});
|
||||
if(result===0&&args[0]==='up'){
|
||||
const config=path.join(options.env.MC_RELEASE_DIR,'server/config');
|
||||
for(const file of fs.readdirSync(config)){
|
||||
fs.mkdirSync(path.join(options.env.MC_ROOT,'runtime/config'),{recursive:true});fs.copyFileSync(path.join(config,file),path.join(options.env.MC_ROOT,'runtime/config',file));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
f.deploy=(release=f.release,receive)=>{
|
||||
const verified=deployableRelease(release);
|
||||
return deployOnHost({repository:f.root,root:f.host,targetName:releaseName(verified.manifest),targetIdentity:verified.identity,targetChecksums:sha256(path.join(release,'SHA256SUMS')),releaseBytes:1024,timeout:30,env:f.env,execute:f.execute,receive:receive??(stage=>fs.cpSync(release,stage,{recursive:true}))});
|
||||
};
|
||||
f.next=(version='2.0.0',edit=()=>{})=>{
|
||||
const release=path.join(f.root,'release-'+version);fs.cpSync(f.release,release,{recursive:true});
|
||||
const manifest=JSON.parse(fs.readFileSync(path.join(release,'manifest.json')));manifest.pack.version=version;
|
||||
fs.writeFileSync(path.join(release,'manifest.json'),JSON.stringify(manifest));edit(release);seal(release);return release;
|
||||
};
|
||||
f.state=()=>JSON.parse(fs.readFileSync(path.join(f.host,'deployment-state.json')));
|
||||
f.events=()=>JSON.parse(fs.readFileSync(path.join(f.root,'.tools/events.json')));
|
||||
return f;
|
||||
}
|
||||
export function addConfig(release,value='original'){
|
||||
fs.writeFileSync(path.join(release,'server/config/marker.txt'),value);
|
||||
const manifest=JSON.parse(fs.readFileSync(path.join(release,'manifest.json')));
|
||||
manifest.release_files.push({path:'server/config/marker.txt'});
|
||||
manifest.managed_files.server.push({path:'config/marker.txt',owner:'server',policy:'replace',hashes:{sha256:sha256(path.join(release,'server/config/marker.txt'))}});
|
||||
fs.writeFileSync(path.join(release,'manifest.json'),JSON.stringify(manifest));seal(release);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user