From 86491fb427e7bbd3fec3562b55678c876d78935b Mon Sep 17 00:00:00 2001 From: davmacario Date: Sat, 5 Oct 2024 10:32:52 +0200 Subject: [PATCH 1/7] ci: update super linter version (v5 -> v7) See #44 --- .github/workflows/linter.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index e51b917..6f9a9cc 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -48,7 +48,7 @@ jobs: # Run Linter against code base # ################################ - name: Lint Code Base - uses: super-linter/super-linter/slim@v5 + uses: super-linter/super-linter/slim@v7 env: VALIDATE_ALL_CODEBASE: false VALIDATE_JSON: false @@ -56,5 +56,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Do not lint downloaded code - see https://github.com/github/super-linter FILTER_REGEX_EXCLUDE: .*/download/.*|layout.html - # EOF From 33e503852f1831fd19e0e5fc4be924c8713a319f Mon Sep 17 00:00:00 2001 From: davmacario Date: Sun, 6 Oct 2024 18:51:52 +0200 Subject: [PATCH 2/7] fix: set user and healthcheck in dockerfile --- code/oak-d-lite-module/Dockerfile | 9 +++++++++ code/oak-d-lite-module/vision_container.sh | 4 ++-- code/oak-d-lite-module/vision_webserver.py | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/code/oak-d-lite-module/Dockerfile b/code/oak-d-lite-module/Dockerfile index 5474739..a661a82 100644 --- a/code/oak-d-lite-module/Dockerfile +++ b/code/oak-d-lite-module/Dockerfile @@ -6,8 +6,17 @@ RUN git clone https://github.com/luxonis/depthai.git depthai RUN ./depthai/docker_dependencies.sh +RUN useradd -m depthai +USER depthai + RUN python3 ./depthai/install_requirements.py WORKDIR / + COPY requirements.txt . + RUN pip3 install --no-cache-dir -r requirements.txt + +HEALTHCHECK CMD curl -f http://localhost:9090/ || exit 1 + +CMD ["python3", "/oak-d-lite-module/vision_webserver.py"] diff --git a/code/oak-d-lite-module/vision_container.sh b/code/oak-d-lite-module/vision_container.sh index 8e43916..28078e3 100755 --- a/code/oak-d-lite-module/vision_container.sh +++ b/code/oak-d-lite-module/vision_container.sh @@ -1,4 +1,5 @@ #!/bin/bash + docker run --rm \ --privileged \ --name=oak-d-lite-server \ @@ -7,5 +8,4 @@ docker run --rm \ --device-cgroup-rule='c 189:* rmw' \ -p 9090:9090 \ -d \ - depthai-freisa:latest \ - python3 /oak-d-lite-module/vision_webserver.py + depthai-freisa:latest diff --git a/code/oak-d-lite-module/vision_webserver.py b/code/oak-d-lite-module/vision_webserver.py index 613e2b7..a87a716 100644 --- a/code/oak-d-lite-module/vision_webserver.py +++ b/code/oak-d-lite-module/vision_webserver.py @@ -125,7 +125,7 @@ def GET(self, *path, **params): # Return currently active model (Empty string if no active model!) return self.oak_control.getCurrentModelName() else: - cp.response.status = 418 + cp.response.status = 200 return f"Available methods:\n{json.dumps(self.supported_req)}" def POST(self, *path, **params): From 05a527c741e047be7cba1f8fa98cf7a18b1a541d Mon Sep 17 00:00:00 2001 From: davmacario Date: Sun, 6 Oct 2024 18:53:49 +0200 Subject: [PATCH 3/7] ci: raise JSCPD threshold for code duplicates --- .jscpd.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .jscpd.json diff --git a/.jscpd.json b/.jscpd.json new file mode 100644 index 0000000..710e813 --- /dev/null +++ b/.jscpd.json @@ -0,0 +1,28 @@ +{ + "threshold": 10, + "reporters": [ + "html", + "markdown" + ], + "ignore": [ + "**/node_modules/**", + "**/.git/**", + "**/.rbenv/**", + "**/.venv/**", + "**/report/**", + "**/megalinter-reports/**", + "**/hardis-report/**", + "**/*cache*/**", + "**/*.json", + "**/*.yaml", + "**/*.yml", + "**/*.md", + "**/*.html", + "**/*.xml", + "**/*.jpg", + "**/*.png", + "**/*.svg", + "**/*.zip", + "**/*.bin" + ] +} From 4774dc542347ff580a8e2a55ffa2e0a30bd88363 Mon Sep 17 00:00:00 2001 From: davmacario Date: Sun, 6 Oct 2024 18:58:44 +0200 Subject: [PATCH 4/7] fix: move linter config to right folder --- .jscpd.json => .github/linters/.jscpd.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .jscpd.json => .github/linters/.jscpd.json (100%) diff --git a/.jscpd.json b/.github/linters/.jscpd.json similarity index 100% rename from .jscpd.json rename to .github/linters/.jscpd.json From ea6ded58e985d7ff0cdb69bdc1fcc5254a759c73 Mon Sep 17 00:00:00 2001 From: davmacario Date: Sun, 6 Oct 2024 19:46:25 +0200 Subject: [PATCH 5/7] ci: improve config and remove redundant linters --- .github/linters/.hadolint.yaml | 3 +++ .github/workflows/linter.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 .github/linters/.hadolint.yaml diff --git a/.github/linters/.hadolint.yaml b/.github/linters/.hadolint.yaml new file mode 100644 index 0000000..22537ae --- /dev/null +++ b/.github/linters/.hadolint.yaml @@ -0,0 +1,3 @@ +--- +ignored: + - DL3008 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 6f9a9cc..754e954 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -11,6 +11,9 @@ name: Lint Code Base # https://help.github.com/en/articles/workflow-syntax-for-github-actions # +# Prevent writing with GH Actions token +permissions: read-all + ############################# # Start the job on all push # ############################# @@ -52,6 +55,8 @@ jobs: env: VALIDATE_ALL_CODEBASE: false VALIDATE_JSON: false + VALIDATE_JSON_PRETTIER: false + VALIDATE_SHELL_SHFMT: false DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Do not lint downloaded code - see https://github.com/github/super-linter From be2354f48ac1c4264d224037639cf9db5f114609 Mon Sep 17 00:00:00 2001 From: davmacario Date: Sun, 6 Oct 2024 19:46:49 +0200 Subject: [PATCH 6/7] fix: solve linting issues and review pylint config --- .github/linters/.python-lint | 13 ++++++++ code/oak-d-lite-module/vision_webserver.py | 35 +++++++++++----------- 2 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 .github/linters/.python-lint diff --git a/.github/linters/.python-lint b/.github/linters/.python-lint new file mode 100644 index 0000000..78c5359 --- /dev/null +++ b/.github/linters/.python-lint @@ -0,0 +1,13 @@ +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=88 + +[DESIGN] + +# Maximum number of attributes (methods/classes) +max-attributes=20 + +[MESSAGES CONTROL] + +disable=C0114,W1514,C0103,R1710,R1720,R1705,C0116 diff --git a/code/oak-d-lite-module/vision_webserver.py b/code/oak-d-lite-module/vision_webserver.py index a87a716..160acee 100644 --- a/code/oak-d-lite-module/vision_webserver.py +++ b/code/oak-d-lite-module/vision_webserver.py @@ -29,15 +29,15 @@ class VisionWebServer: ### API - GET: - /: get the API information (any method) - - /latest_inference: get the latest inference result (404 if no inference result is - available - no pipeline running) - - /models_info: get a json-formatted string containing the information of the available - models + - /latest_inference: get the latest inference result (404 if no inference + result is available - no pipeline running) + - /models_info: get a json-formatted string containing the information of the + available models - /model: get the name of the currently active model (empty string if none) - POST: - /: get the API information (for POST only) - - /change_model?model=: switch the currently active model for the one - specified in the parameter; Error 422 if model name is invalid + - /change_model?model=: switch the currently active model for the + one specified in the parameter; Error 422 if model name is invalid """ exposed = True @@ -95,7 +95,7 @@ def __init__(self, config_path: str, models_path: str, public: bool = True): self.msg_ok = {"status": "SUCCESS", "msg": "", "params": {}} self.msg_ko = {"status": "FAILURE", "msg": "", "params": {}} - def GET(self, *path, **params): + def GET(self, *path): """ GET --- @@ -114,11 +114,10 @@ def GET(self, *path, **params): # No model is currently active raise cp.HTTPError( 404, - "No inference result found - need to launch a pipeline first (POST)", + "No inference result found - need to launch a pipeline first", ) - else: - cp.response.status = 200 - return json.dumps(self.oak_control.last_inference_result) + cp.response.status = 200 + return json.dumps(self.oak_control.last_inference_result) elif str(path[0]) == "models_info": return json.dumps(self.oak_control.info_dict) elif str(path[0]) == "model": @@ -136,8 +135,8 @@ def POST(self, *path, **params): ### Possible URLs - /: get the API information (for POST only) - - /change_model?model=: switch the currently active model for the one - specified in the parameter; Error 422 if model name is invalid + - /change_model?model=: switch the currently active model for the + one specified in the parameter; Error 422 if model name is invalid """ # body = json.loads(cp.request.body.read()) if len(path) > 0 and len(params) > 0: @@ -146,7 +145,8 @@ def POST(self, *path, **params): if new_model not in self.oak_control.model_names: raise cp.HTTPError( 422, - f"Parameter 'mode' = {new_model} is invalid!\nValid models: {self.oak_control.model_names}", + f"""Parameter 'mode' = {new_model} is invalid!\nValid models: + {self.oak_control.model_names}""", ) # If valid model name, switch to that self.oak_control.selectModel(new_model) @@ -157,10 +157,9 @@ def POST(self, *path, **params): return json.dumps( self.oak_control.info_dict[self.oak_control.getCurrentModelName()] ) - else: - raise cp.HTTPError( - 404, f"Invalid POST request to {self.own_addr + str(path[0])}" - ) + raise cp.HTTPError( + 404, f"Invalid POST request to {self.own_addr + str(path[0])}" + ) else: return json.dumps(self.supported_req["POST"]) From f4e4ad994c5c0dfe8d4d4d9025d61488fd6ea401 Mon Sep 17 00:00:00 2001 From: davmacario Date: Sun, 6 Oct 2024 19:53:06 +0200 Subject: [PATCH 7/7] fix: ci: improving linters --- .github/linters/.python-lint | 2 +- .github/workflows/linter.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/linters/.python-lint b/.github/linters/.python-lint index 78c5359..2118812 100644 --- a/.github/linters/.python-lint +++ b/.github/linters/.python-lint @@ -10,4 +10,4 @@ max-attributes=20 [MESSAGES CONTROL] -disable=C0114,W1514,C0103,R1710,R1720,R1705,C0116 +disable=C0114,W1514,C0103,R1710,R1720,R1705,C0116,E0401 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 754e954..bae54c4 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -57,6 +57,7 @@ jobs: VALIDATE_JSON: false VALIDATE_JSON_PRETTIER: false VALIDATE_SHELL_SHFMT: false + VALIDATE_DOCKERFILE_HADOLINT: false DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Do not lint downloaded code - see https://github.com/github/super-linter