Skip to content

Commit

Permalink
v3.0.5 updates, adapt scripts to run with th either docker or podman
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Feb 15, 2023
1 parent 2abb31b commit 8633697
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

© 2021 Battelle Energy Alliance, LLC
© 2023 Battelle Energy Alliance, LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Github cisagov/network-architecture-verification-and-validation
Licensed under BSD-3 License.


© 2021 Battelle Energy Alliance, LLC
© 2023 Battelle Energy Alliance, LLC
ALL RIGHTS RESERVED

Prepared by Battelle Energy Alliance, LLC
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ See [`docker/README.md`](./docker/README.md) for setup and instructions for runn

## <a name="Footer"></a>Copyright

[NAVV](https://github.com/cisagov/network-architecture-verification-and-validation) is Copyright 2021 Battelle Energy Alliance, LLC, licensed under the BSD-3 Clause License.
[NAVV](https://github.com/cisagov/network-architecture-verification-and-validation) is Copyright 2023 Battelle Energy Alliance, LLC, licensed under the BSD-3 Clause License.

See [`LICENSE`](./LICENSE) for the terms of its release.

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:22.04

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

LABEL maintainer="[email protected]"
LABEL org.opencontainers.image.authors='[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ total 9.4M
```
## <a name="Footer"></a>Copyright

[NAVV](https://github.com/cisagov/network-architecture-verification-and-validation) is Copyright 2021 Battelle Energy Alliance, LLC, licensed under the BSD-3 Clause License.
[NAVV](https://github.com/cisagov/network-architecture-verification-and-validation) is Copyright 2023 Battelle Energy Alliance, LLC, licensed under the BSD-3 Clause License.

See [`LICENSE`](./LICENSE) for the terms of its release.
26 changes: 16 additions & 10 deletions docker/backup_docker.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
#!/usr/bin/env bash

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

set -e
set -o pipefail
set -u

ENCODING="utf-8"

# image name (can be overriden via NAVV_DOCKER_IMAGE env. var.)
NAVV_DOCKER_IMAGE="${NAVV_DOCKER_IMAGE:-ghcr.io/cisagov/network-architecture-verification-and-validation:latest}"
# container engine (docker vs. podman, can be overriden via CONTAINER_ENGINE env. var.)
CONTAINER_ENGINE="${CONTAINER_ENGINE:-docker}"

[[ "$(uname -s)" = 'Darwin' ]] && REALPATH=grealpath || REALPATH=realpath
[[ "$(uname -s)" = 'Darwin' ]] && DIRNAME=gdirname || DIRNAME=dirname
if ! (type "$REALPATH" && type "$DIRNAME" && type docker) > /dev/null; then
echo "$(basename "${BASH_SOURCE[0]}") requires docker, $REALPATH and $DIRNAME"
if ! (type "$REALPATH" && type "$DIRNAME" && type "$CONTAINER_ENGINE") > /dev/null; then
echo "$(basename "${BASH_SOURCE[0]}") requires $CONTAINER_ENGINE, $REALPATH and $DIRNAME"
exit 1
fi
export SCRIPT_PATH="$($DIRNAME $($REALPATH -e "${BASH_SOURCE[0]}"))"

# default docker image name (can be overriden via NAVV_DOCKER_IMAGE env. var.)
NAVV_DOCKER_IMAGE="${NAVV_DOCKER_IMAGE:-ghcr.io/cisagov/network-architecture-verification-and-validation:latest}"

# save tarball with image creation date and sha
DOCKER_BACKUP_FILENAME=navv-docker_$(date -d "$(docker inspect --format='{{.Created}}' "$NAVV_DOCKER_IMAGE")" +"%Y%m%d_%H%M%S")_$(docker images --no-trunc --quiet "$NAVV_DOCKER_IMAGE" | cut -d: -f2 | cut -c 1-12).tar.gz
DOCKER_BACKUP_FILENAME=navv-$CONTAINER_ENGINE-$(date -d "$($CONTAINER_ENGINE inspect --format='{{.Created}}' "$NAVV_DOCKER_IMAGE" | sed "s/ /T/" | sed "s/ +0000 UTC/Z/")" +"%Y%m%d_%H%M%S")_$($CONTAINER_ENGINE images --no-trunc --quiet "$NAVV_DOCKER_IMAGE" | cut -d: -f2 | cut -c 1-12).tar.gz

# backup docker image and navv-docker.sh
docker save "$NAVV_DOCKER_IMAGE" | gzip > "$DOCKER_BACKUP_FILENAME"
# backup image and navv-docker.sh
if [[ "$CONTAINER_ENGINE" == "podman" ]]; then
$CONTAINER_ENGINE save --format oci-archive "$NAVV_DOCKER_IMAGE" | gzip > "$DOCKER_BACKUP_FILENAME"
else
$CONTAINER_ENGINE save "$NAVV_DOCKER_IMAGE" | gzip > "$DOCKER_BACKUP_FILENAME"
fi
[[ ! -r navv-docker.sh ]] && cp "$SCRIPT_PATH"/navv-docker.sh ./

echo "Transfer $DOCKER_BACKUP_FILENAME and navv-docker.sh to destination host" | tee ./navv_export.txt
echo "Import $NAVV_DOCKER_IMAGE with docker load -i $DOCKER_BACKUP_FILENAME" | tee -a ./navv_export.txt
echo "Import $NAVV_DOCKER_IMAGE with $CONTAINER_ENGINE load -i $DOCKER_BACKUP_FILENAME" | tee -a ./navv_export.txt
echo "Run with navv-docker.sh" | tee -a ./navv_export.txt
13 changes: 9 additions & 4 deletions docker/build_docker.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
#!/usr/bin/env bash

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

set -e
set -o pipefail
set -u

ENCODING="utf-8"

# image name (can be overriden via NAVV_DOCKER_IMAGE env. var.)
NAVV_DOCKER_IMAGE="${NAVV_DOCKER_IMAGE:-ghcr.io/cisagov/network-architecture-verification-and-validation:latest}"
# container engine (docker vs. podman, can be overriden via CONTAINER_ENGINE env. var.)
CONTAINER_ENGINE="${CONTAINER_ENGINE:-docker}"

[[ "$(uname -s)" = 'Darwin' ]] && REALPATH=grealpath || REALPATH=realpath
[[ "$(uname -s)" = 'Darwin' ]] && DIRNAME=gdirname || DIRNAME=dirname
if ! (type "$REALPATH" && type "$DIRNAME" && type docker) > /dev/null; then
echo "$(basename "${BASH_SOURCE[0]}") requires docker, $REALPATH and $DIRNAME"
if ! (type "$REALPATH" && type "$DIRNAME" && type $CONTAINER_ENGINE) > /dev/null; then
echo "$(basename "${BASH_SOURCE[0]}") requires $CONTAINER_ENGINE, $REALPATH and $DIRNAME"
exit 1
fi
export SCRIPT_PATH="$($DIRNAME $($REALPATH -e "${BASH_SOURCE[0]}"))"

pushd "$SCRIPT_PATH"/.. >/dev/null 2>&1

docker build -f docker/Dockerfile -t ghcr.io/cisagov/network-architecture-verification-and-validation:latest "$@" .
$CONTAINER_ENGINE build -f docker/Dockerfile -t ghcr.io/cisagov/network-architecture-verification-and-validation:latest "$@" .

popd >/dev/null 2>&1
2 changes: 1 addition & 1 deletion docker/navv-build-for-export.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

set -o pipefail
set -u
Expand Down
27 changes: 18 additions & 9 deletions docker/navv-docker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

# navv_docker.sh
#
Expand All @@ -17,20 +17,29 @@ shopt -s nullglob

ENCODING="utf-8"

# default docker image name (can be overriden via NAVV_DOCKER_IMAGE env. var.)
# image name (can be overriden via NAVV_DOCKER_IMAGE env. var.)
NAVV_DOCKER_IMAGE="${NAVV_DOCKER_IMAGE:-ghcr.io/cisagov/network-architecture-verification-and-validation:latest}"
# container engine (docker vs. podman, can be overriden via CONTAINER_ENGINE env. var.)
CONTAINER_ENGINE="${CONTAINER_ENGINE:-docker}"
if [[ "$CONTAINER_ENGINE" == "podman" ]]; then
PUID=0
PGID=0
else
PUID=$(id -u)
PGID=$(id -g)
fi

# run navv -h to get help
function print_usage() {
docker run --rm "$NAVV_DOCKER_IMAGE" -h | sed "s/\(optional arguments\):/\1 (use short option syntax for docker):/" >&2
$CONTAINER_ENGINE run --rm "$NAVV_DOCKER_IMAGE" -h | sed "s/\(options\):/\1 (use short option syntax for $CONTAINER_ENGINE):/" >&2
}

# figure out actual executable names for realpath, dirname and basename
[[ "$(uname -s)" = 'Darwin' ]] && REALPATH=grealpath || REALPATH=realpath
[[ "$(uname -s)" = 'Darwin' ]] && DIRNAME=gdirname || DIRNAME=dirname
[[ "$(uname -s)" = 'Darwin' ]] && BASENAME=gbasename || BASENAME=basename
if ! (type "$REALPATH" && type "$DIRNAME" && type "$BASENAME" && type docker) > /dev/null; then
echo "$(basename "${BASH_SOURCE[0]}") requires $REALPATH, $DIRNAME, $BASENAME and docker"
if ! (type "$REALPATH" && type "$DIRNAME" && type "$BASENAME" && type $CONTAINER_ENGINE) > /dev/null; then
echo "$(basename "${BASH_SOURCE[0]}") requires $REALPATH, $DIRNAME, $BASENAME and $CONTAINER_ENGINE"
exit 1
fi

Expand All @@ -51,7 +60,7 @@ while getopts 'vxeho:p:z:' OPTION; do

# show version and exit
v)
docker run --rm \
$CONTAINER_ENGINE run --rm \
-e PUID=$(id -u) -e PGID=$(id -g) \
"$NAVV_DOCKER_IMAGE" --version ACME
exit 0
Expand Down Expand Up @@ -171,9 +180,9 @@ elif [[ -r "$SCRIPT_PATH"/local.zeek ]]; then
MOUNT_ARGS+=( "$SCRIPT_PATH/local.zeek:/opt/zeek/share/zeek/site/local.zeek:ro" )
fi

# run the navv docker image and remove it when it finishes
docker run --rm \
-e PUID=$(id -u) -e PGID=$(id -g) \
# run a navv container and remove it when it finishes
$CONTAINER_ENGINE run --rm \
-e PUID=$PUID -e PGID=$PUID \
-w /output \
"${MOUNT_ARGS[@]}" \
"$NAVV_DOCKER_IMAGE" \
Expand Down
2 changes: 1 addition & 1 deletion src/navv/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""This file defines the version of this module."""
__version__ = "3.0.4"
__version__ = "3.0.5"
2 changes: 1 addition & 1 deletion src/navv/data_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

import netaddr

Expand Down
2 changes: 1 addition & 1 deletion src/navv/network_analysis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

# python std library imports
import argparse
Expand Down
2 changes: 1 addition & 1 deletion src/navv/spreadsheet_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

import os
import itertools
Expand Down
2 changes: 1 addition & 1 deletion src/navv/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2021 Battelle Energy Alliance, LLC
# Copyright 2023 Battelle Energy Alliance, LLC

import os
import contextlib
Expand Down

0 comments on commit 8633697

Please sign in to comment.