From 6dd8c44163685acabd9e519fffcf57b842e5c609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20J=2E=20Salmer=C3=B3n-Garc=C3=ADa?= Date: Mon, 23 Oct 2023 11:30:30 +0200 Subject: [PATCH] [bitnami/tensorflow] chore: :construction_worker: Add VIB integration (#52039) * [bitnami/tensorflow] chore: :construction_worker: Add VIB integration Signed-off-by: Javier Salmeron Garcia * test: :white_check_mark: Add basic example Signed-off-by: Javier Salmeron Garcia --------- Signed-off-by: Javier Salmeron Garcia --- .vib/tensorflow/goss/goss.yaml | 14 ++++ .vib/tensorflow/goss/tensorflow.yaml | 15 +++++ .../goss/testfiles/basic_example.py | 41 ++++++++++++ .vib/tensorflow/goss/vars.yaml | 10 +++ .vib/tensorflow/vib-verify.json | 66 +++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 .vib/tensorflow/goss/goss.yaml create mode 100644 .vib/tensorflow/goss/tensorflow.yaml create mode 100644 .vib/tensorflow/goss/testfiles/basic_example.py create mode 100644 .vib/tensorflow/goss/vars.yaml create mode 100644 .vib/tensorflow/vib-verify.json diff --git a/.vib/tensorflow/goss/goss.yaml b/.vib/tensorflow/goss/goss.yaml new file mode 100644 index 000000000000..04e3c7fab249 --- /dev/null +++ b/.vib/tensorflow/goss/goss.yaml @@ -0,0 +1,14 @@ +# Copyright VMware, Inc. +# SPDX-License-Identifier: APACHE-2.0 + +gossfile: + # Goss tests exclusive to the current container + ../../tensorflow/goss/tensorflow.yaml: {} + # Load scripts from .vib/common/goss/templates + ../../common/goss/templates/check-app-version.yaml: {} + ../../common/goss/templates/check-binaries.yaml: {} + ../../common/goss/templates/check-broken-symlinks.yaml: {} + ../../common/goss/templates/check-ca-certs.yaml: {} + ../../common/goss/templates/check-directories.yaml: {} + ../../common/goss/templates/check-linked-libraries.yaml: {} + ../../common/goss/templates/check-spdx.yaml: {} diff --git a/.vib/tensorflow/goss/tensorflow.yaml b/.vib/tensorflow/goss/tensorflow.yaml new file mode 100644 index 000000000000..44013fca914a --- /dev/null +++ b/.vib/tensorflow/goss/tensorflow.yaml @@ -0,0 +1,15 @@ +# Copyright VMware, Inc. +# SPDX-License-Identifier: APACHE-2.0 + +user: + tensorflow: + exists: true + uid: 1001 + gid: 0 +command: + basic-example: + exec: python ./tensorflow/goss/testfiles/basic_example.py + timeout: 120000 + stdout: + - shape=(5, 10) + exit-status: 0 diff --git a/.vib/tensorflow/goss/testfiles/basic_example.py b/.vib/tensorflow/goss/testfiles/basic_example.py new file mode 100644 index 000000000000..2bd8611a2f65 --- /dev/null +++ b/.vib/tensorflow/goss/testfiles/basic_example.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +# Taken from https://www.tensorflow.org/tutorials/quickstart/beginner +import tensorflow as tf + +mnist = tf.keras.datasets.mnist + +(x_train, y_train), (x_test, y_test) = mnist.load_data() +x_train, x_test = x_train / 255.0, x_test / 255.0 + +model = tf.keras.models.Sequential([ + tf.keras.layers.Flatten(input_shape=(28, 28)), + tf.keras.layers.Dense(128, activation='relu'), + tf.keras.layers.Dropout(0.2), + tf.keras.layers.Dense(10) +]) + +predictions = model(x_train[:1]).numpy() + +tf.nn.softmax(predictions).numpy() + +loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True) + +loss_fn(y_train[:1], predictions).numpy() + +model.compile(optimizer='adam', + loss=loss_fn, + metrics=['accuracy']) + +model.fit(x_train, y_train, epochs=5) + + +model.evaluate(x_test, y_test, verbose=2) + + +probability_model = tf.keras.Sequential([ + model, + tf.keras.layers.Softmax() +]) + +print(probability_model(x_test[:5])) diff --git a/.vib/tensorflow/goss/vars.yaml b/.vib/tensorflow/goss/vars.yaml new file mode 100644 index 000000000000..f4922f176b1f --- /dev/null +++ b/.vib/tensorflow/goss/vars.yaml @@ -0,0 +1,10 @@ +binaries: + - python +root_dir: /opt/bitnami +directories: + - paths: + # Paths to the client and server directories + - /opt/bitnami/python +version: + bin_name: python + flag: "-c 'import tensorflow; print(tensorflow.__version__)'" diff --git a/.vib/tensorflow/vib-verify.json b/.vib/tensorflow/vib-verify.json new file mode 100644 index 000000000000..223180a611b7 --- /dev/null +++ b/.vib/tensorflow/vib-verify.json @@ -0,0 +1,66 @@ +{ + "context": { + "resources": { + "url": "{SHA_ARCHIVE}", + "path": "{VIB_ENV_PATH}" + }, + "runtime_parameters": "Y29tbWFuZDogWyJ0YWlsIiwgIi1mIiwgIi9kZXYvbnVsbCJd" + }, + "phases": { + "package": { + "actions": [ + { + "action_id": "container-image-package", + "params": { + "application": { + "details": { + "name": "{VIB_ENV_CONTAINER}", + "tag": "{VIB_ENV_TAG}" + } + }, + "architectures": ["linux/amd64", "linux/arm64"] + } + }, + { + "action_id": "container-image-lint", + "params": { + "threshold": "error" + } + } + ] + }, + "verify": { + "actions": [ + { + "action_id": "goss", + "params": { + "resources": { + "path": "/.vib" + }, + "tests_file": "tensorflow/goss/goss.yaml", + "vars_file": "tensorflow/goss/vars.yaml", + "remote": { + "pod": { + "workload": "deploy-tensorflow" + } + } + } + }, + { + "action_id": "trivy", + "params": { + "threshold": "CRITICAL", + "vuln_type": ["OS"] + } + }, + { + "action_id": "grype", + "params": { + "threshold": "CRITICAL", + "package_type": ["OS"] + } + } + ] + } + } +}