Skip to content

Commit

Permalink
feat(incus): support agent:config in vm
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed May 6, 2024
1 parent 70dd2c7 commit cc39db9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
20 changes: 16 additions & 4 deletions packages/incus/lib/init/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// Dependencies
import dedent from "dedent";
import definitions from "./schema.json" assert { type: "json" };
import { escapeshellarg as esa } from "@nikitajs/core/utils/string";

// Action
export default {
handler: async function({config}) {
const command_init = [
const configValue = Object.entries(config.config).map(([key, value]) => `--config ${key}=${value}`).join(` `)
const commandInit = [
"incus",
"init",
config.image,
config.container,
configValue,
config.network && `--network ${config.network}`,
config.storage && `--storage ${config.storage}`,
config.ephemeral && "--ephemeral",
Expand All @@ -18,13 +21,22 @@ export default {
config.target && `--target ${config.target}`,
].filter(Boolean).join(" ");
// Execution
const {$status} = (await this.execute({
const {$status} = await this.execute({
command: dedent`
incus info ${config.container} >/dev/null && exit 42
echo '' | ${command_init}
echo '' | ${commandInit}
`,
code: [0, 42]
}));
});
if (config.vm) {
// See `agent:config` annoucement in 0.5.1
// https://discuss.linuxcontainers.org/t/incus-0-5-1-has-been-released/18848
await this.execute({
command: dedent`
incus config device add ${esa(config.container)} agent disk source=agent:config
`,
});
}
await this.incus.start({
$if: config.start,
container: config.container
Expand Down
5 changes: 5 additions & 0 deletions packages/incus/lib/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"type": "string",
"description": "Profile to set this container up."
},
"config": {
"type": "object",
"default": {},
"description": "Config key/value to apply to the new instance."
},
"ephemeral": {
"type": "boolean",
"default": false,
Expand Down
8 changes: 4 additions & 4 deletions packages/incus/test/wait/ready.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe 'incus.wait.ready', ->
image: "images:centos/7"
container: 'nikita-wait-2'
vm: true
properties:
config:
'security.secureboot': false
start: true
{$status} = await @incus.wait.ready 'nikita-wait-2'
Expand All @@ -72,7 +72,7 @@ describe 'incus.wait.ready', ->
image: "images:centos/7"
container: 'nikita-wait-3'
vm: true
properties:
config:
'security.secureboot': false
start: true
await @incus.wait.ready 'nikita-wait-3'
Expand Down Expand Up @@ -102,10 +102,10 @@ describe 'incus.wait.ready', ->
image: "images:centos/7"
container: 'nikita-wait-4'
vm: true
properties:
config:
'security.secureboot': false
start: true
{$status} = await @incus.exec
await @incus.exec
container: 'nikita-wait-4'
command: '''
echo "hello"
Expand Down

0 comments on commit cc39db9

Please sign in to comment.