Skip to content

Commit f8539f9

Browse files
committed
Initial
0 parents  commit f8539f9

28 files changed

Lines changed: 1670 additions & 0 deletions

.github/workflows/ci.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
on:
3+
schedule:
4+
- cron: '22 4 * * *'
5+
push:
6+
branches: ['main']
7+
pull_request:
8+
branches: ['main']
9+
10+
jobs:
11+
validate-node:
12+
name: 'Validate'
13+
uses: curium-rocks/flows/.github/workflows/node-ts.yml@main
14+
permissions:
15+
contents: read
16+
actions: read
17+
security-events: write
18+
with:
19+
extra-packages: 'lxc liblxc-dev'
20+
node_versions: '["18.x","20.x", "22.x"]'
21+
node-coverage-version: "18.x"

.github/workflows/release.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
on:
2+
release:
3+
types:
4+
- published
5+
jobs:
6+
validate-node:
7+
name: 'Validate'
8+
uses: curium-rocks/flows/.github/workflows/node-ts.yml@main
9+
permissions:
10+
contents: read
11+
actions: read
12+
security-events: write
13+
with:
14+
extra-packages: 'lxc liblxc-dev'
15+
publish-to-npm:
16+
environment: npm
17+
runs-on: ubuntu-latest
18+
needs:
19+
- validate-node
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: 18
25+
registry-url: https://registry.npmjs.org/
26+
- run: npm ci
27+
- run: npm publish
28+
env:
29+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build
2+
.vagrant
3+
.vscode
4+
node_modules
5+
.devcontainer

README.md

Whitespace-only changes.

Vagrantfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.box = "bento/ubuntu-22.04"
3+
config.vm.provision "ansible_local" do |ansible|
4+
ansible.playbook = "provision.yaml"
5+
end
6+
end

binding.gyp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'node-lxc-native-native',
5+
'sources': [ 'src/node-lxc-container.cc' ],
6+
'libraries': [
7+
'-llxc'
8+
],
9+
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
10+
'dependencies': [
11+
"<!(node -p \"require('node-addon-api').gyp\")",
12+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except"
13+
],
14+
'cflags!': [ '-fno-exceptions' ],
15+
'cflags_cc!': [ '-fno-exceptions' ],
16+
'xcode_settings': {
17+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
18+
'CLANG_CXX_LIBRARY': 'libc++',
19+
'MACOSX_DEPLOYMENT_TARGET': '10.7'
20+
},
21+
'msvs_settings': {
22+
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
23+
}
24+
}
25+
]
26+
}

lib/binding.d.ts

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
export type AttachOptions = {
2+
/**
3+
* - Flags to control the attach behavior.
4+
*/
5+
attachFlags?: number;
6+
/**
7+
* - Namespaces to be used.
8+
*/
9+
namespaces?: number;
10+
/**
11+
* - Personality to be set.
12+
*/
13+
personality?: number;
14+
/**
15+
* - Initial working directory.
16+
*/
17+
initialCwd?: string;
18+
/**
19+
* - User ID to be set.
20+
*/
21+
uid?: number;
22+
/**
23+
* - Group ID to be set.
24+
*/
25+
gid?: number;
26+
/**
27+
* - Environment policy to be set.
28+
*/
29+
envPolicy?: number;
30+
/**
31+
* - Extra environment variables.
32+
*/
33+
extraEnvVars?: string[];
34+
/**
35+
* - Extra environment variables to keep.
36+
*/
37+
extraKeepEnv?: string[];
38+
/**
39+
* - File descriptor for standard input.
40+
*/
41+
stdinFd?: number;
42+
/**
43+
* - File descriptor for standard output.
44+
*/
45+
stdoutFd?: number;
46+
/**
47+
* - File descriptor for standard error.
48+
*/
49+
stderrFd?: number;
50+
/**
51+
* - File descriptor for logging.
52+
*/
53+
logFd?: number;
54+
/**
55+
* - LSM (Linux Security Module) label.
56+
*/
57+
lsmLabel?: string;
58+
/**
59+
* - Array of group IDs.
60+
*/
61+
groups?: number[];
62+
};
63+
export type CreateFromTemplateOpts = {
64+
distro: string;
65+
release: string;
66+
arch: string;
67+
};
68+
/**
69+
* @typedef {Object} AttachOptions
70+
* @property {number} [attachFlags] - Flags to control the attach behavior.
71+
* @property {number} [namespaces] - Namespaces to be used.
72+
* @property {number} [personality] - Personality to be set.
73+
* @property {string} [initialCwd] - Initial working directory.
74+
* @property {number} [uid] - User ID to be set.
75+
* @property {number} [gid] - Group ID to be set.
76+
* @property {number} [envPolicy] - Environment policy to be set.
77+
* @property {string[]} [extraEnvVars] - Extra environment variables.
78+
* @property {string[]} [extraKeepEnv] - Extra environment variables to keep.
79+
* @property {number} [stdinFd] - File descriptor for standard input.
80+
* @property {number} [stdoutFd] - File descriptor for standard output.
81+
* @property {number} [stderrFd] - File descriptor for standard error.
82+
* @property {number} [logFd] - File descriptor for logging.
83+
* @property {string} [lsmLabel] - LSM (Linux Security Module) label.
84+
* @property {number[]} [groups] - Array of group IDs.
85+
*/
86+
/**
87+
* @typedef {Object} CreateFromTemplateOpts
88+
* @property {string} distro
89+
* @property {string} release
90+
* @property {string} arch
91+
*/
92+
export class LxcContainer {
93+
/**
94+
* Lists all LXC containers.
95+
*
96+
* @function
97+
* @name listContainers
98+
* @param {string} lxcPath
99+
* @static
100+
* @returns {Promise<string[]>} - An array of container names.
101+
*/
102+
static listContainers(lxcPath: string): Promise<string[]>;
103+
constructor(opts: any);
104+
/**
105+
* Runs a command and waits for it to finish.
106+
*
107+
* @function
108+
* @name runWait
109+
* @memberof LxcContainer
110+
* @param {Object} params - The parameters for the program to run in the container.
111+
* @param {string} params.program - The program to run.
112+
* @param {string[]} params.argv - The arguments to provide to the command/program.
113+
* @param {AttachOptions} params.options - The attach options.
114+
* @returns {Promise<number>}
115+
*/
116+
runWait(params: {
117+
program: string;
118+
argv: string[];
119+
options: AttachOptions;
120+
}): Promise<number>;
121+
/**
122+
* Queries the console output of the LXC container.
123+
*
124+
* @function
125+
* @name queryConsole
126+
* @returns {Promise<string>} - The console output.
127+
*/
128+
queryConsole(): Promise<string>;
129+
/**
130+
* Gets the network interfaces of the LXC container.
131+
*
132+
* @function
133+
* @name getInterfaces
134+
* @returns {Promise<string[]>} - An array of network interfaces.
135+
*/
136+
getInterfaces(): Promise<string[]>;
137+
/**
138+
* Gets the IP addresses of the LXC container.
139+
*
140+
* @function
141+
* @name getIps
142+
* @param {string} interfaceName
143+
* @param {string} family
144+
* @param {number?} scope
145+
* @returns {Promise<string[]>} - An array of IP addresses.
146+
*/
147+
getIps(
148+
interfaceName: string,
149+
family: string,
150+
scope: number | null,
151+
): Promise<string[]>;
152+
/**
153+
* Gets the PID of the LXC container.
154+
*
155+
* @function
156+
* @name getPid
157+
* @returns {Promise<number>} - The PID of the container.
158+
*/
159+
getPid(): Promise<number>;
160+
/**
161+
* Reboots the LXC container.
162+
*
163+
* @function
164+
* @name reboot
165+
* @param {number} timeoutSeconds
166+
* @returns {Promise<void>}
167+
*/
168+
reboot(timeoutSeconds: number): Promise<void>;
169+
/**
170+
* Shuts down the LXC container.
171+
*
172+
* @function
173+
* @name shutdown
174+
* @param {number} timeoutSeconds
175+
* @returns {Promise<void>}
176+
*/
177+
shutdown(timeoutSeconds: number): Promise<void>;
178+
/**
179+
* Destroys the LXC container.
180+
*
181+
* @function
182+
* @name destroy
183+
* @returns {Promise<void>}
184+
*/
185+
destroy(): Promise<void>;
186+
/**
187+
* Waits for the LXC container to reach a specific state.
188+
*
189+
* @function
190+
* @name waitForState
191+
* @param {string} state - The state to wait for.
192+
* @param {number} timeSeconds - The time to wait for the container to enter the state
193+
* @returns {Promise<void>}
194+
*/
195+
waitForState(state: string, timeoutSeconds: any): Promise<void>;
196+
/**
197+
* Gets the state of the LXC container.
198+
*
199+
* @function
200+
* @name getState
201+
* @returns {Promise<string>} - The state of the container.
202+
*/
203+
getState(): Promise<string>;
204+
/**
205+
* Creates an LXC container from a template.
206+
*
207+
* @function
208+
* @name createFromTemplate
209+
* @memberof LxcContainer
210+
* @param {CreateFromTemplateOpts} opts
211+
* @returns {Promise<void>}
212+
*/
213+
createFromTemplate(opts: CreateFromTemplateOpts): Promise<void>;
214+
/**
215+
* Stops the LXC container.
216+
*
217+
* @function
218+
* @name stop
219+
* @param {number} timeoutSeconds
220+
* @returns {Promise<void>}
221+
*/
222+
stop(timeoutSeconds: number): Promise<void>;
223+
/**
224+
* Starts the LXC container.
225+
*
226+
* @function
227+
* @name start
228+
* @returns {Promise<void>}
229+
*/
230+
start(): Promise<void>;
231+
#private;
232+
}

0 commit comments

Comments
 (0)