hosty
Version:
A code based opinionated way to self-host and manage web apps.
44 lines • 1.46 kB
JavaScript
import { builtin } from '../ansible/tasks/index.js';
export function command(config) {
return {
...config,
type: 'command',
get_deploy_tasks: (server) => get_deploy_tasks(server, config),
get_destroy_tasks: (server) => get_destroy_tasks(server, config),
};
}
function get_deploy_tasks(server, config) {
const cmd = get_command_prefix(server, config.service) + config.cmd;
if (config.cron) {
let attrs = { name: config.name, job: cmd };
if (typeof config.cron === 'string') {
attrs.special_time = config.cron;
}
else {
attrs = { ...attrs, ...config.cron };
}
return [builtin.cron(`Setup cron ${config.name}`, attrs)];
}
return [builtin.shell(`Run command ${config.name}`, { cmd, executable: '/bin/bash' })];
}
function get_command_prefix(server, service) {
if (!service)
return '';
const service_dir = server.get_service_dir(service.name);
let container_name = service.name;
if (service.type === 'app.git')
container_name += '-1';
return `cd ${service_dir} && docker compose run --rm ${container_name} `;
}
function get_destroy_tasks(_, config) {
if (!config.cron)
return [];
return [
builtin.cron(`Delete cron ${config.name}`, {
name: config.name,
job: config.cmd,
state: 'absent',
}),
];
}
//# sourceMappingURL=command.js.map