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

added multistage dockerfile to run tests in actions and deploy to pypi #23

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENV=
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,6 @@ dmypy.json
# Pyre type checker
.pyre/

# End of https://www.gitignore.io/api/python,pycharm,jetbrains
# End of https://www.gitignore.io/api/python,pycharm,jetbrains

.env
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM condaforge/mambaforge:24.3.0-0 as conda

COPY bandit-agents-dev-env-linux-64.lock lib/bandit-agents-dev-env-linux-64.lock

COPY build_env.sh /lib/build_env.sh

RUN chmod +x /lib/build_env.sh

ENV ENV="BUILD"

RUN ./lib/build_env.sh

FROM debian:stable-slim as unit-test-image

COPY --from=conda /env /env

ENV ENV="TEST"

COPY BanditAgents /lib/BanditAgents
COPY Tests /lib/Tests
COPY tox.ini /lib/tox.ini

WORKDIR /lib

CMD ["/env/bin/python3", "-m", "tox", "--current-env"]

FROM debian:stable-slim as publish-lib-image

RUN apt-get -y update; apt-get -y install curl

COPY --from=conda /env /env

ARG ENV
ENV ENV=$ENV

WORKDIR /lib

ENTRYPOINT ["/app/launch_server.sh"]
4 changes: 2 additions & 2 deletions Tests/BanditAgents/src/solvers/test_weight_solver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Generator, Iterable, List
from typing import Iterable, List
import unittest
from unittest.mock import patch

Expand Down Expand Up @@ -38,7 +38,7 @@ def make_mock_base_solver(action_keys: Iterable[actionKey]) -> BaseSolver:
return BaseSolverBuilder().with_action_keys(action_keys).build()


def mock__steps(x: ndarray[int], y: ndarray[float]) -> Generator[bool]:
def mock__steps(x: ndarray[int], y: ndarray[float]) -> Iterable[bool]:
return (True for _ in x)


Expand Down
10 changes: 9 additions & 1 deletion bandit-agents-dev-env-linux-64.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by conda-lock.
# platform: linux-64
# input_hash: 2e1d5b848aca3965630c49dd7f3377094a30ca3b18aaedee74ba7ed4147c1afd
# input_hash: 34b6a0f01ee56af448af8ff240e9dc28dc0f036c439c9129d764a9705b81498b
@EXPLICIT
https://repo.anaconda.com/pkgs/main/linux-64/_libgcc_mutex-0.1-main.conda#c3473ff8bdb3d124ed5ff11ec380d6f9
https://repo.anaconda.com/pkgs/main/linux-64/blas-1.0-mkl.conda#9a7a051e9bd41da46523acb017d8a517
Expand Down Expand Up @@ -31,29 +31,37 @@ https://repo.anaconda.com/pkgs/main/linux-64/sqlite-3.45.3-h5eee18b_0.conda#acf9
https://repo.anaconda.com/pkgs/main/linux-64/python-3.12.0-h996f2a0_0.conda#9bfdaa3ac3249dc0b8f9f22227f0ba07
https://repo.anaconda.com/pkgs/main/linux-64/cfgv-3.4.0-py312h06a4308_0.conda#765ea9eb7e1f5cd3791fcbae54fc6a8f
https://repo.anaconda.com/pkgs/main/linux-64/click-8.1.7-py312h06a4308_0.conda#a0d97fc547780b4ddefc91139e633e02
https://repo.anaconda.com/pkgs/main/linux-64/colorama-0.4.6-py312h06a4308_0.conda#6175699c700cc4e4bf18ffc86778e488
https://repo.anaconda.com/pkgs/main/linux-64/distlib-0.3.8-py312h06a4308_0.conda#3763a64961ca016ccf828044029cc5c0
https://repo.anaconda.com/pkgs/main/linux-64/filelock-3.13.1-py312h06a4308_0.conda#6a0b440821945eda176c2bd78fd64a56
https://repo.anaconda.com/pkgs/main/linux-64/mkl-service-2.4.0-py312h5eee18b_2.conda#4c74c6d49097f7bba2cd219e0c759048
https://repo.anaconda.com/pkgs/main/linux-64/mypy_extensions-1.0.0-py312h06a4308_0.conda#79bbb864c9fffd761fbc7f5bc149dcef
https://repo.anaconda.com/pkgs/main/linux-64/packaging-24.2-py312h06a4308_0.conda#cece1340aae4560340b6f061cd3bae2f
https://repo.anaconda.com/pkgs/main/linux-64/pathspec-0.10.3-py312h06a4308_0.conda#adca67c357ada01d137d476d8c2d7f41
https://repo.anaconda.com/pkgs/main/linux-64/platformdirs-3.10.0-py312h06a4308_0.conda#39dc9eb538e73250dadcdec7a8ed6595
https://repo.anaconda.com/pkgs/main/linux-64/pluggy-1.5.0-py312h06a4308_0.conda#1287a7b660a041fbbb8931defb9111d6
https://repo.anaconda.com/pkgs/main/noarch/py-1.11.0-pyhd3eb1b0_0.conda#7205a898ed2abbf6e9b903dff6abe08e
https://repo.anaconda.com/pkgs/main/noarch/pycparser-2.21-pyhd3eb1b0_0.conda#135a72ff2a31150a3a3ff0b1edd41ca9
https://repo.anaconda.com/pkgs/main/noarch/python-tzdata-2023.3-pyhd3eb1b0_0.conda#479c037de0186d114b9911158427624e
https://repo.anaconda.com/pkgs/main/linux-64/pytz-2024.1-py312h06a4308_0.conda#f8a72213ea02624e802216fedff222e1
https://repo.anaconda.com/pkgs/main/linux-64/pyyaml-6.0.2-py312h5eee18b_0.conda#757daf8bab7a35c165f3dc6c9355ea9b
https://repo.anaconda.com/pkgs/main/linux-64/setuptools-72.1.0-py312h06a4308_0.conda#bab64ac5186aa07014788baf1fbe3ca9
https://repo.anaconda.com/pkgs/main/noarch/six-1.16.0-pyhd3eb1b0_1.conda#34586824d411d36af2fa40e799c172d0
https://repo.anaconda.com/pkgs/main/linux-64/tomli-2.0.1-py312h06a4308_1.conda#8770c279821e6ba382d5fa7562a8391b
https://repo.anaconda.com/pkgs/main/linux-64/wheel-0.44.0-py312h06a4308_0.conda#6d495438dd44e8f16b1a05d0a8648644
https://repo.anaconda.com/pkgs/main/linux-64/zipp-3.21.0-py312h06a4308_0.conda#b3ad8cca3dcd963260b5f84401cfc6ae
https://repo.anaconda.com/pkgs/main/linux-64/black-24.8.0-py312h06a4308_0.conda#45db94c5c4cc7ec895f3620198365987
https://repo.anaconda.com/pkgs/main/linux-64/cffi-1.17.1-py312h1fdaa30_1.conda#e3c5735b1a5c0ec929f62407410890bb
https://repo.anaconda.com/pkgs/main/linux-64/importlib-metadata-8.5.0-py312h06a4308_0.conda#c7395d8d9fc78756d72104f0e9d468f5
https://repo.anaconda.com/pkgs/main/linux-64/nodeenv-1.7.0-py312h06a4308_0.conda#23c0441e6b4e88642027f364e62f8566
https://repo.anaconda.com/pkgs/main/linux-64/numpy-base-2.2.1-py312h0da6c21_0.conda#6ec469e931f2d1f7f08494b1d5668cc5
https://repo.anaconda.com/pkgs/main/linux-64/pip-24.2-py312h06a4308_0.conda#798cbea8112672434d0cd7551f8fc4b9
https://repo.anaconda.com/pkgs/main/linux-64/python-dateutil-2.9.0post0-py312h06a4308_2.conda#06c8706a892aaaae74325c0b46c86d01
https://repo.anaconda.com/pkgs/main/linux-64/virtualenv-20.28.0-py312h06a4308_0.conda#f3843ea4e7a86a4fc2429cb0a25277a2
https://conda.anaconda.org/conda-forge/noarch/tox-3.27.1-pyhd8ed1ab_0.tar.bz2#62b743e1030b17163c70654601afb60d
https://repo.anaconda.com/pkgs/main/linux-64/ukkonen-1.0.1-py312hdb19cb5_1.conda#bbeaa2aff1b32149b4380d5cd80b4b25
https://repo.anaconda.com/pkgs/main/linux-64/identify-2.5.5-py312h06a4308_0.conda#f41d506d423ed77f2fd4ae67020ae659
https://conda.anaconda.org/conda-forge/noarch/tox-current-env-0.0.11-pyhd8ed1ab_0.conda#ca5420198ae4fe23bc4fe924be99635c
https://repo.anaconda.com/pkgs/main/linux-64/pre-commit-3.4.0-py312h06a4308_1.conda#8570303eeae34305d21b118782de1834
https://repo.anaconda.com/pkgs/main/linux-64/bottleneck-1.4.2-py312ha883a20_0.conda#ff0a95c8810f5c091da3d93e565c7763
https://repo.anaconda.com/pkgs/main/linux-64/mkl_fft-1.3.11-py312h5eee18b_0.conda#8e39abc21446208f8efa84140549e137
Expand Down
2 changes: 2 additions & 0 deletions bandit_agents_dev_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies:
- scipy
- pandas
- black
- tox
- tox-current-env

platforms:
- linux-64
44 changes: 40 additions & 4 deletions build_env.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
#!/bin/sh +x
if [ -e $CONDA_PREFIX_1/envs/bandit_agents_dev_env ]; then

if [ $ENV = "BUILD" ]; then
mamba create \
--copy -p ./env \
--file /lib/bandit-agents-dev-env-linux-64.lock \
&& conda clean -afy

find -name '*.a' -delete &&
rm -rf /env/conda-meta &&
rm -rf /env/include &&
rm /env/lib/libpython3.12.so.1.0 &&
find -name '__pycache__' -type d -exec rm -rf '{}' '+' &&
rm -rf /env/lib/python3.12/site-packages/pip /env/lib/python3.12/idlelib /env/lib/python3.12/ensurepip \
/env/lib/libasan.so.5.0.0 \
/env/lib/libtsan.so.0.0.0 \
/env/lib/liblsan.so.0.0.0 \
/env/lib/libubsan.so.1.0.0 \
/env/bin/x86_64-conda-linux-gnu-ld \
/env/bin/sqlite3 \
/env/bin/openssl \
/env/share/terminfo &&
find /env/lib/python3.12/site-packages/scipy -name 'tests' -type d -exec rm -rf '{}' '+' &&
find /env/lib/python3.12/site-packages/numpy -name 'tests' -type d -exec rm -rf '{}' '+' &&
find /env/lib/python3.12/site-packages/pandas -name 'tests' -type d -exec rm -rf '{}' '+' &&
find /env/lib/python3.12/site-packages -name '*.pyx' -delete &&
rm -rf /env/lib/python3.12/site-packages/uvloop/loop.c

else
if [ -e $CONDA_PREFIX_1/envs/bandit_agents_dev_env ]; then
echo erase bandit_agents_dev_env
rm -r $CONDA_PREFIX_1/envs/bandit_agents_dev_env
fi
fi

echo creating environment
conda create \
echo creating environment
conda create \
--name bandit_agents_dev_env \
--file bandit-agents-dev-env-linux-64.lock -y

echo adding dev dependencies
conda update \
--name bandit_agents_dev_env \
--freeze-installed \
--no-update-deps \
--file bandit-agents-dev-env-linux-64.lock
fi
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
mb-assistant-v2:
build:
context: .
dockerfile: Dockerfile
target: publish-lib-image
args:
ENV: $ENV

unit-tests:
build:
context: .
dockerfile: Dockerfile
target: unit-test-image
19 changes: 19 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[flake8]
max-line-length = 300
inline-quotes = single
literal-inline-quotes = single
exclude =
.git,
__pycache__,
old,
build,
dist,
env,
env_files,
deployment

extend-ignore = E203, E704, F541


[testenv]
commands = /env/bin/python3 -m unittest