From 86336976dc14e3742b22be8c26b8e2c92d44edec Mon Sep 17 00:00:00 2001 From: Seth Grover Date: Wed, 15 Feb 2023 08:52:54 -0700 Subject: [PATCH] v3.0.5 updates, adapt scripts to run with th either docker or podman --- LICENSE | 2 +- NOTICE | 2 +- README.md | 2 +- docker/Dockerfile | 2 +- docker/README.md | 2 +- docker/backup_docker.sh | 26 ++++++++++++++++---------- docker/build_docker.sh | 13 +++++++++---- docker/navv-build-for-export.sh | 2 +- docker/navv-docker.sh | 27 ++++++++++++++++++--------- src/navv/_version.py | 2 +- src/navv/data_types.py | 2 +- src/navv/network_analysis.py | 2 +- src/navv/spreadsheet_tools.py | 2 +- src/navv/utilities.py | 2 +- 14 files changed, 54 insertions(+), 34 deletions(-) diff --git a/LICENSE b/LICENSE index 1e93898..01be9d5 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/NOTICE b/NOTICE index 8b77b3e..d44ec29 100644 --- a/NOTICE +++ b/NOTICE @@ -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 diff --git a/README.md b/README.md index 3022247..949003a 100644 --- a/README.md +++ b/README.md @@ -255,7 +255,7 @@ See [`docker/README.md`](./docker/README.md) for setup and instructions for runn ## 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. diff --git a/docker/Dockerfile b/docker/Dockerfile index b69726e..86e2d77 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:22.04 -# Copyright 2021 Battelle Energy Alliance, LLC +# Copyright 2023 Battelle Energy Alliance, LLC LABEL maintainer="seth.grover@inl.gov" LABEL org.opencontainers.image.authors='seth.grover@inl.gov' diff --git a/docker/README.md b/docker/README.md index 23a6e09..299afa1 100644 --- a/docker/README.md +++ b/docker/README.md @@ -104,6 +104,6 @@ total 9.4M ``` ## 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. \ No newline at end of file diff --git a/docker/backup_docker.sh b/docker/backup_docker.sh index 30279fb..71da746 100755 --- a/docker/backup_docker.sh +++ b/docker/backup_docker.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright 2021 Battelle Energy Alliance, LLC +# Copyright 2023 Battelle Energy Alliance, LLC set -e set -o pipefail @@ -8,24 +8,30 @@ 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 diff --git a/docker/build_docker.sh b/docker/build_docker.sh index 43c472f..c7c4b48 100755 --- a/docker/build_docker.sh +++ b/docker/build_docker.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright 2021 Battelle Energy Alliance, LLC +# Copyright 2023 Battelle Energy Alliance, LLC set -e set -o pipefail @@ -8,16 +8,21 @@ 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 diff --git a/docker/navv-build-for-export.sh b/docker/navv-build-for-export.sh index 4b4706e..c419b68 100755 --- a/docker/navv-build-for-export.sh +++ b/docker/navv-build-for-export.sh @@ -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 diff --git a/docker/navv-docker.sh b/docker/navv-docker.sh index 5a9fce2..c066e90 100755 --- a/docker/navv-docker.sh +++ b/docker/navv-docker.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright 2021 Battelle Energy Alliance, LLC +# Copyright 2023 Battelle Energy Alliance, LLC # navv_docker.sh # @@ -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 @@ -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 @@ -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" \ diff --git a/src/navv/_version.py b/src/navv/_version.py index fab2e88..3bc269f 100644 --- a/src/navv/_version.py +++ b/src/navv/_version.py @@ -1,2 +1,2 @@ """This file defines the version of this module.""" -__version__ = "3.0.4" +__version__ = "3.0.5" diff --git a/src/navv/data_types.py b/src/navv/data_types.py index aca6931..21fa17d 100644 --- a/src/navv/data_types.py +++ b/src/navv/data_types.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2021 Battelle Energy Alliance, LLC +# Copyright 2023 Battelle Energy Alliance, LLC import netaddr diff --git a/src/navv/network_analysis.py b/src/navv/network_analysis.py index ecd85f9..58f4421 100644 --- a/src/navv/network_analysis.py +++ b/src/navv/network_analysis.py @@ -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 diff --git a/src/navv/spreadsheet_tools.py b/src/navv/spreadsheet_tools.py index 0302d2a..a3d9cf5 100644 --- a/src/navv/spreadsheet_tools.py +++ b/src/navv/spreadsheet_tools.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2021 Battelle Energy Alliance, LLC +# Copyright 2023 Battelle Energy Alliance, LLC import os import itertools diff --git a/src/navv/utilities.py b/src/navv/utilities.py index 3715751..26619eb 100644 --- a/src/navv/utilities.py +++ b/src/navv/utilities.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2021 Battelle Energy Alliance, LLC +# Copyright 2023 Battelle Energy Alliance, LLC import os import contextlib