From 925f0c3ccd950339b0dffe162d8d09d4d9c79dfd Mon Sep 17 00:00:00 2001 From: James Grogan Date: Wed, 30 Nov 2022 13:45:59 +0000 Subject: [PATCH] Add initial infra --- .gitignore | 1 + infra/containers/README.md | 26 +++++++++++++++ .../ubuntu/22_04/MinimalDeps/Dockerfile | 2 ++ infra/src/ntk_infra/README.md | 29 +++++++++++++++++ infra/src/ntk_infra/__init__.py | 0 infra/src/ntk_infra/podman_interface.py | 32 +++++++++++++++++++ infra/src/ntk_infra/requirements.txt | 1 + 7 files changed, 91 insertions(+) create mode 100644 infra/containers/README.md create mode 100644 infra/containers/ubuntu/22_04/MinimalDeps/Dockerfile create mode 100644 infra/src/ntk_infra/README.md create mode 100644 infra/src/ntk_infra/__init__.py create mode 100644 infra/src/ntk_infra/podman_interface.py create mode 100644 infra/src/ntk_infra/requirements.txt diff --git a/.gitignore b/.gitignore index b4715e3..d9bfa54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .cproject .project +.pydevproject .settings/ /Debug/ /build/ diff --git a/infra/containers/README.md b/infra/containers/README.md new file mode 100644 index 0000000..dec8d59 --- /dev/null +++ b/infra/containers/README.md @@ -0,0 +1,26 @@ +# Containers + +This is a collection of CI-focused containers for testing. + +# Setup + +Install and run `podman` and activate the Rest API: + +```bash +sudo apt-get -y install podman +podman system service -t 0 & +``` + +# Build containers + +```bash +cd ubuntu/22_04/MinimalDeps +podman build -t ubuntu_22_04_minimal_deps . +``` + +# Run containers + +```bash +podman run -it -v $LOCAL_SOURCE_DIR:source ubuntu_22_04_minimal_deps:latest /bin/bash + +``` diff --git a/infra/containers/ubuntu/22_04/MinimalDeps/Dockerfile b/infra/containers/ubuntu/22_04/MinimalDeps/Dockerfile new file mode 100644 index 0000000..ce06ec5 --- /dev/null +++ b/infra/containers/ubuntu/22_04/MinimalDeps/Dockerfile @@ -0,0 +1,2 @@ +FROM ubuntu:22.04 +RUN apt-get update; apt-get -y install build-essential pkg-config cmake diff --git a/infra/src/ntk_infra/README.md b/infra/src/ntk_infra/README.md new file mode 100644 index 0000000..b6cc389 --- /dev/null +++ b/infra/src/ntk_infra/README.md @@ -0,0 +1,29 @@ +# ntk_infra + +This is a collection of Python tools to support building the Notes Toolkit (NotesTK) project. + +# Setup + +Add `~/.local/bin` to `PATH`, i.e. in `~/.bashrc` add `export PATH=$PATH:~/.local/bin` and do `source ~/.bashrc`. + +Set up virtual environment: + +```bash +sudo apt-get install python3-pip python3-venv +python3 -m venv $MY_ENV_PATH +source $MY_ENV_PATH/bin/activate +``` + +When finished do: + +```bash +deactivate +``` + +Install requirements: + +```bash +pip install -r requirements.txt +``` + + diff --git a/infra/src/ntk_infra/__init__.py b/infra/src/ntk_infra/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/infra/src/ntk_infra/podman_interface.py b/infra/src/ntk_infra/podman_interface.py new file mode 100644 index 0000000..0f57c70 --- /dev/null +++ b/infra/src/ntk_infra/podman_interface.py @@ -0,0 +1,32 @@ +#import podman + +"""Demonstrate PodmanClient.""" +import json +from podman import PodmanClient + +# Provide a URI path for the libpod service. In libpod, the URI can be a unix +# domain socket(UDS) or TCP. The TCP connection has not been implemented in this +# package yet. + +uri = "unix:///run/user/1000/podman/podman.sock" + +with PodmanClient(base_url=uri) as client: + version = client.version() + print("Release: ", version["Version"]) + print("Compatible API: ", version["ApiVersion"]) + print("Podman API: ", version["Components"][0]["Details"]["APIVersion"], "\n") + + # get all images + for image in client.images.list(): + print(image, image.id, "\n") + + # find all containers + for container in client.containers.list(): + first_name = container['Names'][0] + container = client.containers.get(first_name) + print(container, container.id, "\n") + + # available fields + print(sorted(container.attrs.keys())) + + print(json.dumps(client.df(), indent=4)) \ No newline at end of file diff --git a/infra/src/ntk_infra/requirements.txt b/infra/src/ntk_infra/requirements.txt new file mode 100644 index 0000000..5247d59 --- /dev/null +++ b/infra/src/ntk_infra/requirements.txt @@ -0,0 +1 @@ +podman