diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index affefff2..ce9816f9 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.4' +version: '3.8' services: netkan: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d43872a..928d5509 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,4 +19,4 @@ jobs: context: ./netkan file: ./netkan/Dockerfile push: false - target: production + target: test diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1d46a398..80f849e7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,6 +19,14 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Run tests before deploying + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./netkan + file: ./netkan/Dockerfile + push: false + target: test - name: Build and push NetKAN-infra id: docker_build uses: docker/build-push-action@v2 diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml deleted file mode 100644 index 2341e9a4..00000000 --- a/.github/workflows/mypy.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Mypy - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - name: Mypy - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Install Dependencies - run: | - pip install netkan/.[test] - - name: mypy - working-directory: ./netkan - run: | - mypy . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..59db6ba1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,21 @@ +name: Test + +on: + - push + - pull_request + +jobs: + pytest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Install test dependencies + working-directory: netkan + run: pip install .[test] + - name: Run pytest + working-directory: netkan + run: pytest --mypy -v diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml deleted file mode 100644 index a64e2017..00000000 --- a/.github/workflows/unittest.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: unittest - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - name: unittest - steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Install Dependencies - run: | - pip install netkan/.[test] - - name: Run unittest - working-directory: ./netkan - run: | - python -m unittest -v diff --git a/.gitignore b/.gitignore index 5a9c8469..d9621227 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /pr_tester __pycache__ .mypy_cache/ +.pytest_cache/ +.eggs diff --git a/.vscode/settings.json b/.vscode/settings.json index 8d456f5b..538b017f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,16 +13,10 @@ "files.exclude": { "**/__pycache__": true }, - "python.testing.unittestArgs": [ - "-v", - "-s", - "./netkan", - "-p", - "tests/__init__.py" - ], - "python.testing.pytestEnabled": false, + "python.testing.pytestArgs": ["--verbose", "--exitfirst", "netkan/tests"], + "python.testing.pytestEnabled": true, "python.testing.nosetestsEnabled": false, - "python.testing.unittestEnabled": true, + "python.testing.unittestEnabled": false, "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, "files.trimFinalNewlines": true diff --git a/dev-stack.py b/dev-stack.py index 49c9e083..b7823824 100644 --- a/dev-stack.py +++ b/dev-stack.py @@ -1,5 +1,5 @@ -# Converted from SQS_With_CloudWatch_Alarms.template located at: -# http://aws.amazon.com/cloudformation/aws-cloudformation-templates/ +#!/usr/bin/env python3 +# mypy: ignore_errors=True import os import sys diff --git a/netkan/Dockerfile b/netkan/Dockerfile index 202ad9cd..f6a08758 100644 --- a/netkan/Dockerfile +++ b/netkan/Dockerfile @@ -3,12 +3,9 @@ RUN useradd -ms /bin/bash netkan ADD . /netkan WORKDIR /netkan RUN pip install pip --upgrade -RUN pip install mypy RUN chown -R netkan:netkan /netkan USER netkan -RUN pip install --user . --no-warn-script-location --force-reinstall -RUN mypy . -RUN python -m unittest -v +RUN pip install --user . --no-warn-script-location FROM python:3.7 as production COPY --from=base /home/netkan /home/netkan @@ -22,14 +19,24 @@ RUN /home/netkan/.local/bin/netkan --help ENTRYPOINT [".local/bin/netkan"] CMD ["--help"] +FROM production as test +USER root +RUN pip install pip --upgrade +ADD . /netkan +RUN chown -R netkan:netkan /netkan +USER netkan +WORKDIR /netkan +RUN pip install --user .[test] +RUN /home/netkan/.local/bin/pytest --mypy -v + FROM production as dev USER root +RUN pip install pip --upgrade ADD . /netkan RUN chown -R netkan:netkan /netkan ADD run_dev.sh /usr/local/bin/ USER netkan RUN pip install --user /netkan/.[development] -RUN pip install --user /netkan/.[test] ENTRYPOINT ["/usr/local/bin/run_dev.sh"] FROM production diff --git a/netkan/pytest.ini b/netkan/pytest.ini new file mode 100644 index 00000000..6b4b5e3d --- /dev/null +++ b/netkan/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = tests/__init__.py diff --git a/netkan/setup.py b/netkan/setup.py index dc355a38..7ff990bc 100644 --- a/netkan/setup.py +++ b/netkan/setup.py @@ -38,8 +38,13 @@ 'pylint', 'autopep8', 'troposphere', + 'pytest', + 'pytest-mypy', + 'mypy', ], 'test': [ + 'pytest', + 'pytest-mypy', 'mypy', ] }, diff --git a/prod-stack.py b/prod-stack.py index e5f34d50..d5bf9943 100644 --- a/prod-stack.py +++ b/prod-stack.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python3 +# mypy: ignore_errors=True + import os import sys from troposphere import GetAtt, Output, Ref, Template, Sub, Base64