Skip to content

Commit

Permalink
feat(incus-runner): container state detection
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jan 28, 2025
1 parent 68f6d8f commit 7fc4dbc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
12 changes: 7 additions & 5 deletions extra/incus-runner/lib/actions/enter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
export default async function({config}) {
export default async function ({ config }) {
// Note, using `incus shell` would be nice but `cwd` doesn't seem right
// `incus shell --cwd /nikita/packages/$pkg` then `pwd` return `/root`
// `incus shell --cwd /nikita/packages/$pkg -- pkg` prints:
// `pwd: ignoring non-option arguments`
// `/nikita/packages/$pkg`
await this.execute({
$header: 'Container enter',
$header: "Container enter",
// To be tested
// command: `incus shell --cwd ${config.cwd} ${config.container}`,
command: `incus exec --cwd ${config.cwd} ${config.container} -- bash`,
stdio: ['inherit', 'inherit', 'inherit'],
stdio: ["inherit", "inherit", "inherit"],
stdin: process.stdin,
stdout: process.stdout,
stderr: process.stderr
stderr: process.stderr,
});
};
}
23 changes: 17 additions & 6 deletions extra/incus-runner/lib/actions/state.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
export default async function({config}) {
const {config: state} = await this.incus.state({
$header: 'Container state',
container: `${config.container}`
export default async function ({ config }) {
let state = "";
const { exists } = await this.incus.exists({
$header: "Container exists",
container: `${config.container}`,
});
process.stdout.write(JSON.stringify(state, null, 2));
};
if (!exists) {
state = "NOT_CREATED";
} else {
({ config: state } = await this.incus.state({
$if: exists,
$header: "Container state",
container: `${config.container}`,
}));
}
// process.stdout.write(JSON.stringify(state, null, 2));
return { state: state };
}
12 changes: 10 additions & 2 deletions extra/incus-runner/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export default function (config) {
},
state: {
description: `Print machine state and information.`,
handler: function ({ params }) {
return nikita({
handler: async function ({ params }) {
const { state } = await nikita({
$debug: params.debug,
})
.log.cli({
Expand All @@ -120,6 +120,14 @@ export default function (config) {
...config,
...params,
});
setImmediate(() => {
process.stdout.write(
state === "NOT_CREATED" ?
"Container is not created."
: `State could not be found, found ${state}.`,
);
process.stdout.write("\n");
});
},
},
run: {
Expand Down

0 comments on commit 7fc4dbc

Please sign in to comment.