Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(devcontainer): 🧑‍💻 add support for reproducible env #141

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .devcontainer/aws_secrets_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.9-bookworm",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "make install-dev",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"mypy-type-checker.interpreter": [
"/usr/local/bin/python"
]
},
"extensions": [
"streetsidesoftware.code-spell-checker",
"ms-python.vscode-pylance",
"ms-python.python",
"ms-python.mypy-type-checker",
"ms-toolsai.jupyter",
"tamasfe.even-better-toml"
]
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"mounts": [
"source=${localWorkspaceFolder}/.devcontainer/aws_secrets_example,target=/home/vscode/.aws/secrets,type=bind,consistency=cached"
]
}
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ jobs:
- name: Run Tests
run: |
make test
test-notebooks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run notebook tests in devcontainer
uses: devcontainers/[email protected]
with:
cacheFrom: mcr.microsoft.com/devcontainers/python:1-3.9-bookworm
push: never
runCmd: make test-notebooks
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,7 @@ cython_debug/
.idea/

# Notebook Model Downloads
notebooks/KerasModels
notebooks/PyTorchModels/
pytorch-model-scan-results.json
notebooks/TensorFlowModels/
notebooks/XGBoostModels/
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ clean:
test:
poetry run pytest

test-notebooks:
poetry run pytest --nbmake notebooks/pytorch_sentiment_analysis.ipynb notebooks/xgboost_diabetes_classification.ipynb
build:
poetry build

Expand Down
15 changes: 6 additions & 9 deletions notebooks/keras_fashion_mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"source": [
"import tensorflow as tf\n",
"import os\n",
"\n",
"tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n",
"from utils.tensorflow_fashion_mnist_model import train_model, get_predictions"
]
Expand Down Expand Up @@ -107,7 +108,9 @@
"\n",
"safe_model_path = os.path.join(model_directory, \"safe_model.h5\")\n",
"model = train_model()\n",
"model.save(safe_model_path,)"
"model.save(\n",
" safe_model_path,\n",
")"
]
},
{
Expand Down Expand Up @@ -208,16 +211,10 @@
"source": [
"safe_model_loaded = tf.keras.models.load_model(safe_model_path)\n",
"\n",
"attack = ( \n",
" lambda x: os.system(\n",
" \"\"\"cat ~/.aws/secrets\"\"\"\n",
" )\n",
" or x\n",
")\n",
"attack = lambda x: os.system(\"\"\"cat ~/.aws/secrets\"\"\") or x\n",
"\n",
"lambda_layer = tf.keras.layers.Lambda(attack)(safe_model_loaded.outputs[-1])\n",
"unsafe_model = tf.keras.Model(inputs=safe_model_loaded.inputs, outputs=lambda_layer)\n",
"\n"
"unsafe_model = tf.keras.Model(inputs=safe_model_loaded.inputs, outputs=lambda_layer)"
]
},
{
Expand Down
Loading