Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ cmake-build*
integration_tests/external*
Dockerfile
.dockerignore
.gitignore
.git
appimage/Dockerfile.part
appimage/export.sh
appimage/Makefile
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ docs/html-documentation-generated*
integration_tests/external
golang/pkg/client/version.go
docs/internals/html
appimage/*.AppImage
18 changes: 18 additions & 0 deletions appimage/Dockerfile.part
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# file is needed for appimagetool when its run with --appimage-extract-and-run
# binutil is needed for strip
RUN apt-get update && apt-get install -yqq --no-install-recommends python3-pip binutils file dietlibc-dev gcc musl musl-tools \
&& pip3 install --user exodus-bundler --no-warn-script-location \
&& /root/.local/bin/exodus --verbose --tarball --output=/tmp/pktvisor.tgz $(which pktvisord) $(which pktvisor-pcap) \
&& mkdir pktvisor \
&& tar --strip=1 -xf /tmp/pktvisor.tgz -C pktvisor/ \
&& strip --verbose --strip-debug pktvisor/data/* \
&& cp $(which pktvisor-cli) /pktvisor/bin/pktvisor-cli

# get latest appimagetool
ADD https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage /bin/appimage-tool

# add entrypoints and desktop things
COPY appimage/pktvisor /pktvisor

# create appimage without fuse
RUN chmod +x /bin/appimage-tool /pktvisor/AppRun && appimage-tool --appimage-extract-and-run /pktvisor/
17 changes: 17 additions & 0 deletions appimage/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DEV_IMAGE ?= ns1labs/pktvisor:latest

# in dev mode we just use the latest image as the start point
ifneq ($(strip $(DEV_MODE)),)
DOCKERFILE_HEAD = <(echo "FROM $(DEV_IMAGE)")
else
DOCKERFILE_HEAD = docker/Dockerfile
endif

pktvisor-x86_64.AppImage: SHELL:=/bin/bash #needed for the fd when DOCKERFILE_HEAD is in DEV_MODE
pktvisor-x86_64.AppImage:
ID=$$(cd .. && cat $(DOCKERFILE_HEAD) appimage/Dockerfile.part | docker build -q -f- .) ; \
bash export.sh $$ID

.PHONEY: clean
clean:
rm pktvisor-x86_64.AppImage
28 changes: 28 additions & 0 deletions appimage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
AppImage Packaging
==================

Creates an AppImage that contains `pktvisord` `pktvisor-pcap` and `pktvisor-cli`. This implementation builds the AppImage in a docker using the assets generated by the docker [build](../docker). Because not all of the assets are statically linked we use [Exodus](https://github.com/intoli/exodus) to capture a minimal set of dependencies for the AppImage


## Build:
`make pktvisor-x86_64.AppImage`

## Development:
Because the build can take a while you may want to build the appimage from the latest docker image on docker hub. To do this you can set the `DEV_MODE=` environment to anything. Like so:

`DEV_MODE=t make pktvisor-x86_64.AppImage`

You may also specify a custom image in dev mode by setting the env file `DEV_IMAGE=` to the image you wish to build on. Example:

`DEV_IMAGE="ns1labs/pktvisor:develop" DEV_MODE=t make pktvisor-x86_64.AppImage`


## Usage:
To use the AppImage from the command line you can specify the binary you want to run as the first argument following the pattern:

`
./pktvisor-x86_64.AppImage [pktvisord|pktvisor-pcap|pktvisor-cli] <args>
`

If you don't specify a binary, all args are passed to pktvisord by default.

36 changes: 36 additions & 0 deletions appimage/export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

##
# Try to extract files from docker image as atomically as possible
#

FILES=(pktvisor-x86_64.AppImage)

die () {
echo "$@" >&2
exit 1
}

# pass in image id as $1
main () {
[[ $1 ]] || die "image name not specified"

# make a trap that see the var
id=
cleanup() {
docker rm -v "$id"
}

trap cleanup EXIT

# make it
id=$(docker create $1)
[[ $? == 0 ]] || die "failed to create container for export"

# take it
for file in "${FILES[@]}" ; do
docker cp "$id:$file" .
done
}

main "$1"
31 changes: 31 additions & 0 deletions appimage/pktvisor/AppRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
set -x

# borrowed from appimage directly
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
export PATH="${HERE}/usr/bin/:${HERE}/usr/sbin/:${HERE}/usr/games/:${HERE}/bin/:${HERE}/sbin/${PATH:+:$PATH}"
export LD_LIBRARY_PATH="${HERE}/usr/lib/:${HERE}/usr/lib/i386-linux-gnu/:${HERE}/usr/lib/x86_64-linux-gnu/:${HERE}/usr/lib32/:${HERE}/usr/lib64/:${HERE}/lib/:${HERE}/lib/i386-linux-gnu/:${HERE}/lib/x86_64-linux-gnu/:${HERE}/lib32/:${HERE}/lib64/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export PYTHONPATH="${HERE}/usr/share/pyshared/${PYTHONPATH:+:$PYTHONPATH}"
export XDG_DATA_DIRS="${HERE}/usr/share/${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
export PERLLIB="${HERE}/usr/share/perl5/:${HERE}/usr/lib/perl5/${PERLLIB:+:$PERLLIB}"
export GSETTINGS_SCHEMA_DIR="${HERE}/usr/share/glib-2.0/schemas/${GSETTINGS_SCHEMA_DIR:+:$GSETTINGS_SCHEMA_DIR}"
export QT_PLUGIN_PATH="${HERE}/usr/lib/qt4/plugins/:${HERE}/usr/lib/i386-linux-gnu/qt4/plugins/:${HERE}/usr/lib/x86_64-linux-gnu/qt4/plugins/:${HERE}/usr/lib32/qt4/plugins/:${HERE}/usr/lib64/qt4/plugins/:${HERE}/usr/lib/qt5/plugins/:${HERE}/usr/lib/i386-linux-gnu/qt5/plugins/:${HERE}/usr/lib/x86_64-linux-gnu/qt5/plugins/:${HERE}/usr/lib32/qt5/plugins/:${HERE}/usr/lib64/qt5/plugins/${QT_PLUGIN_PATH:+:$QT_PLUGIN_PATH}"

# begin entrypoint
# default to pktvisord but allow first arg to specify binary
BINARY="$1"
case "$BINARY" in
pktvisor-cli) shift ;;
pktvisor-pcap) shift ;;
pktvisord) shift ;;
*) BINARY=pktvisord ;;
esac

# not a terminal try to alert the user
if [ ! -t 1 ] ; then
xdg-open "file://${HERE}/TerminalEmulatorRequired.txt"
exit 1
else
exec "${HERE}/bin/${BINARY}" "$@"
fi
1 change: 1 addition & 0 deletions appimage/pktvisor/TerminalEmulatorRequired.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This app needs to be run from a terminal to function correctly. See the docs at https://github.com/ns1/pktvisor for more details.
7 changes: 7 additions & 0 deletions appimage/pktvisor/pktvisor.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Name=pktvisor
Terminal=true
Exec=AppRun
Icon=pktvisor
Type=Application
Categories=Utility;
Binary file added appimage/pktvisor/pktvisor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RUN \
FROM golang:latest AS gobuild
COPY golang/ /src/
WORKDIR /src/
COPY --from=cppbuild /pktvisor-src/golang/pkg/client/version.go /src/pkg/client/version.go
RUN go build -o pktvisor-cli cmd/pktvisor-cli/main.go

FROM debian:bullseye-slim AS runtime
Expand Down