Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sysdig Inspect container image #47

Merged
merged 24 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
555a857
Add script to create Docker container image
davideschiera Nov 20, 2018
0b4befd
Dockerfile
davideschiera Nov 20, 2018
9d0dce6
Refactor the server to accommodate the execution in container
davideschiera Nov 20, 2018
34e3f59
Readme
davideschiera Nov 20, 2018
7ea38e1
Fix build
davideschiera Nov 20, 2018
02a86cb
Minor changes
davideschiera Nov 20, 2018
40469a1
Add script to create Docker container image
davideschiera Nov 20, 2018
427c6db
Dockerfile
davideschiera Nov 20, 2018
276b8aa
Refactor the server to accommodate the execution in container
davideschiera Nov 20, 2018
26f4b39
Readme
davideschiera Nov 20, 2018
3733a54
Fix build
davideschiera Nov 20, 2018
978aa5f
Minor changes
davideschiera Nov 20, 2018
64ad002
Better command line to build container
davideschiera Mar 12, 2019
5aa0203
Use same Sysdig version used by build and add comments
davideschiera Mar 12, 2019
359ae12
How to use the Sysdig Inspect container
davideschiera Mar 12, 2019
e37a4c9
Merge remote-tracking branch 'origin/dockerization' into dockerization
davideschiera Mar 12, 2019
7e78330
Wording
davideschiera Mar 12, 2019
f7b8c14
Use "latest" image tag to avoid specific versions in the readme
davideschiera Mar 12, 2019
c89219e
Merge branch 'dev' into dockerization
davideschiera Mar 12, 2019
ca5d983
Update package-lock file
davideschiera Mar 12, 2019
325cfb7
Review sysdig/csysdig process error handling
davideschiera Mar 14, 2019
2b0ede1
Add readi/liveness probe endpoints
davideschiera Mar 14, 2019
f8214b3
Add health check
davideschiera Mar 14, 2019
073c9ad
Improve error UI
davideschiera Mar 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,30 @@ The environment setup and app builds will create several artifacts. Here is how
start fresh:

* `npm run clean:win`


## Container

You can also create a Docker image to run Sysdig Inspect. This will make Sysdig Inspect available as web application, already bundled with sysdig.

First, make sure to follow the _Prepare the environment_ sections above. Then, here's how you can build the image:

```
npm run make:docker-image

# build the image with Docker
docker build . -t sysdig-inspect:0.1
```

You can now start the container:

```
docker run -d -v /local/path/to/captures/:/captures -p8080:3000 sysdig-inspect:0.1
```

Note that:

1. It's recommended to mount the directory where you have the Sysdig capture files (`/local/path/to/captures` in the example) to the directory you will use in Sysdig Inspect (`/captures` in the example)
2. You can pick the TCP port you'll use in the browser to launch Sysdig Inspect (`8080` in the example). The container will expose port 3000/tcp

And that's it! Now you can open http://localhost:8080 and open a capture file like `/captures/my-capture.scap`.
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM sysdig/sysdig:0.24.1

#
# Install node.js (v10)
#
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 10.5.0
ENV NVM_VERSION 0.31.2

RUN curl -s -o- https://raw.githubusercontent.com/creationix/nvm/v$NVM_VERSION/install.sh | bash

RUN /bin/bash -c "source $NVM_DIR/nvm.sh && \
nvm install $NODE_VERSION && \
nvm alias default $NODE_VERSION && \
nvm use default"

RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

#
# Setup environment
#
ENV NODE_ENV production
ENV SYSDIG_SERVER_PORT 3000
ENV SYSDIG_PATH /usr/bin
ENV SYSDIG_SERVER_HOSTNAME 0.0.0.0

#
# Add Sysdig Inspect
#
ADD dist /usr/bin/sysdig-inspect
WORKDIR /usr/bin/sysdig-inspect

#
# Configure health check
#
HEALTHCHECK --interval=1m --timeout=20s \
CMD curl -f http://localhost:3000/health || exit 1

#
# Expose Sysdig Inspect UI endpoint
#
EXPOSE 3000

#
# Start it!
#
CMD ["npx", "forever", "main.js"]
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ To use Sysdig Inspect, you need capture files collected on Linux with [sysdig](h

Where to start?
---
**Sysdig Inspect container**

**Installing Sysdig Inspect**
Sysdig Inspect is available as Docker container image.

```
docker run -d -v /local/path/to/captures:/captures -p8080:3000 sysdiglabs/sysdig-inspect:latest
```

Sysdig Inspect will be available in your browser at http://localhost:8080!


**Sysdig Inspect desktop**

Here are the installers available for the latest version:

Expand Down
143 changes: 106 additions & 37 deletions ember-electron/backend/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,24 @@ const fs = require('fs');

class Controller {
constructor(sysdigPath) {
this.sysdigPath = sysdigPath || path.join(__dirname, '../resources/sysdig/');
this.sysdigPath = sysdigPath;

if (process.platform === 'win32') {
this.sysdigExe = this.sysdigPath + 'sysdig.exe';
this.csysdigExe = this.sysdigPath + 'csysdig.exe';
this.sysdigExe = path.join(this.sysdigPath, '/sysdig.exe');
this.csysdigExe = path.join(this.sysdigPath, '/csysdig.exe');
} else {
this.sysdigExe = this.sysdigPath + 'sysdig';
this.csysdigExe = this.sysdigPath + 'csysdig';
this.sysdigExe = path.join(this.sysdigPath, '/sysdig');
this.csysdigExe = path.join(this.sysdigPath, '/csysdig');
}

if (!fs.existsSync(this.sysdigExe) || !fs.existsSync(this.csysdigExe)) {
console.log(`sysdig/csysdig executables not found in path ${this.sysdigPath}`);
if (fs.existsSync(this.sysdigExe) === false) {
console.error(`sysdig executable not found at ${this.sysdigExe}`);
process.exit();
}
if (fs.existsSync(this.csysdigExe) === false) {
console.error(`csysdig executable not found at ${this.csysdigExe}`);
process.exit();
}
}

sendError(message, response) {
let resBody = { reason: message };

response.status(500);
response.send(JSON.stringify(resBody));
}

runCsysdig(args, response) {
Expand All @@ -60,29 +57,101 @@ class Controller {
_run(exe, args, response) {
let options = { cwd: this.sysdigPath };

console.log(`spawning ${exe} with args: ${args}`);
this.prc = spawn(exe, args, options);

this.prc.stdout.setEncoding('utf8');
this.prc.stderr.setEncoding('utf8');
this.prc.stdin.setEncoding('utf8');

this.prc.stdout.on('data', (data) => {
response.write(data);
});

this.prc.stderr.on('data', (data) => {
this.sendError(data, response);
});

this.prc.on('close', (code) => {
response.end();
console.log(`sysdig process exited with code ${code}`);
});

this.prc.on('error', (err) => {
console.log('Cannot start csysdig. Make sure sysdig is installed correctly.');
console.log(err);
console.log(`spawning ${this.sysdigPath}/${exe} with args`, args);
const prc = spawn(exe, args, options);

prc.stdout.setEncoding('utf8');
prc.stderr.setEncoding('utf8');
prc.stdin.setEncoding('utf8');

//
// Use state to understand how to handle responses:
// - If data has been received, you can only change the status and you'll need to close the stream
// - If no data has been received, in case of failure you can send the error message
// - Don't handle errors more than once
//
let execState = 'STARTED';

return new Promise((resolve, reject) => {
prc.stdout.on('data', (data) => {
console.log(`${this.sysdigPath}/${exe}`, args, 'receiving data');

if (execState !== 'FAILED') {
if (response) {
response.write(data);
}

execState = 'DATA_RECEIVED';
}
});

prc.stderr.on('data', (data) => {
console.error(`${this.sysdigPath}/${exe}`, args, 'error read from STDERR', data);

if (execState !== 'FAILED') {
const message = { reason: data };

if (response) {
response.status(500);

if (execState === 'STARTED') {
response.send(JSON.stringify(message));
}
}

execState = 'FAILED';

reject(message);
}
});

prc.on('error', (err) => {
//
// NOTE: Exit event may or may not fire after
//
console.error(`${this.sysdigPath}/${exe}`, args, 'error: cannot start (make sure sysdig is installed correctly)', err);

if (execState !== 'FAILED') {
const message = { reason: 'Cannot start csysdig. Make sure sysdig is installed correctly.', details: err };

if (response) {
response.status(500);

if (execState === 'STARTED') {
response.send(JSON.stringify({ reason: message.reason }));
}
}

execState = 'FAILED';

reject(message);
}
});

prc.on('close', (code, signal) => {
console.error(`${this.sysdigPath}/${exe}`, args, `exited with code ${code} ${signal}`);

if (response) {
if (execState === 'DATA_RECEIVED') {
// Close stream only if anything has been sent
response.end();
} else if (execState === 'STARTED') {
// Send 'no content' if nothing happened
response.status(204).send();
}
}

if (execState !== 'FAILED') {
if (code === 0) {
resolve({code});
} else {
const message = { reason: 'Unexpected exit', details: code };
reject(message);
}
}

execState = 'COMPLETED';
});
});
}
}
Expand Down
11 changes: 9 additions & 2 deletions ember-electron/backend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ const path = require('path');
const argv = require('yargs').argv;
const backendServer = require('./server');

let absPath = argv.p ? path.resolve(__dirname, argv.p) + '/' : undefined;
let absPath;
if (argv.p) {
absPath = path.resolve(__dirname, argv.p);
} else if (process.env.SYSDIG_PATH) {
absPath = path.resolve(__dirname, process.env.SYSDIG_PATH);
} else {
absPath = path.join(__dirname, '../resources/sysdig/');
}

backendServer(absPath).start();
backendServer(absPath, process.env.SYSDIG_SERVER_PORT, process.env.SYSDIG_SERVER_HOSTNAME).start();
console.log('press CTRL+C for exit');
Loading