From 80d45342c3a70b55e17cfbbdd8e11c1ebaca96ef Mon Sep 17 00:00:00 2001 From: Frederico Sequeira <frederico.sequeira@ext.ec.europa.eu> Date: Mon, 13 Jan 2025 09:56:49 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=92=9A=20Add=20Pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 162 ++++++++++++++++++++++++++++++++++++++++ docker-compose copy.yml | 40 ++++++++++ 2 files changed, 202 insertions(+) create mode 100644 .gitlab-ci.yml create mode 100644 docker-compose copy.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..dbba677 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,162 @@ +include: + - project: 'digit-c4/dev/python-best-practices' + file: 'gitlab-ci/build-and-publish-package.yml' + ref: v2.0 + +default: + image: python:3.11 + tags: + - lab + - docker +stages: + - init + - lint + - test + - doc + - delivery +variables: + NETBOX_VERSION: v3.6.9 +init-job: + image: code.europa.eu:4567/digit-c4/dev/python-best-practices/python-poetry:3.11-alpine + stage: init + before_script: + - apk add jpeg-dev zlib-dev libjpeg + - pip install Pillow + + script: + - mkdir .project + - git clone https://github.com/netbox-community/netbox.git -b $NETBOX_VERSION .project/netbox + - python -m venv .project/venv + - source .project/venv/bin/activate + - pip install --upgrade pip + # - pip install -e . + - poetry install + - pip install -r .project/netbox/requirements.txt -U + artifacts: + expire_in: 30 minutes + paths: + - .project/ +lint-job: + stage: lint + before_script: + - source .project/venv/bin/activate + - pip install pylint + script: + - pylint --rcfile .pylintrc --init-hook 'import os; import sys; sys.path.append(os.getcwd() + "/.project/netbox/netbox")' ./netbox_sys_plugin/ + dependencies: + - init-job + needs: + - init-job +test-job: + image: code.europa.eu:4567/digit-c4/dev/python-best-practices/python-poetry:3.11-alpine + stage: test + services: + - postgres + - redis + variables: + POSTGRES_DB: netbox + POSTGRES_USER: netbox + POSTGRES_PASSWORD: netbox + POSTGRES_HOST_AUTH_METHOD: trust + before_script: + - source .project/venv/bin/activate + - apk add jpeg-dev zlib-dev libjpeg + - ln -s $(pwd)/netbox_configuration/configuration_testing.py .project/netbox/netbox/netbox/configuration.py + - pip install coverage + script: + - coverage run --include='*/netbox_sys_plugin/*' .project/netbox/netbox/manage.py test netbox_sys_plugin.tests -v 2 + - ls -al + - coverage report -m + - coverage xml -o .project/coverage.xml + artifacts: + expire_in: 1 day + reports: + coverage_report: + coverage_format: cobertura + path: .project/coverage.xml + dependencies: + - init-job + needs: + - init-job +doc-job: + stage: doc + services: + - postgres + - redis + #rules: + #- if: '$CI_COMMIT_BRANCH == "main"' + variables: + POSTGRES_DB: netbox + POSTGRES_USER: netbox + POSTGRES_PASSWORD: netbox + POSTGRES_HOST_AUTH_METHOD: trust + before_script: + - apt-get update + - apt-get install -y graphviz graphviz-dev + - source .project/venv/bin/activate + - python3 -m pip install --upgrade Pillow + - ln -s $(pwd)/netbox_configuration/configuration_testing.py .project/netbox/netbox/netbox/configuration.py + - ln -s $(pwd)/docs .project/docs + script: + - python3 .project/netbox/netbox/manage.py graph_models --pydot netbox_sys_plugin -o .project/docs/model/schema_diagram.png + artifacts: + expire_in: never + paths: + - .project/docs/* + dependencies: + - init-job + needs: + - init-job + +smithy-job: + stage: doc + #rules: + #- if: '$CI_COMMIT_BRANCH == "main"' + before_script: + - mkdir -p smithy-install/smithy + - curl -L https://github.com/smithy-lang/smithy/releases/download/1.43.0/smithy-cli-linux-x86_64.tar.gz -o smithy-install/smithy-cli-linux-x86_64.tar.gz + - tar xvzf smithy-install/smithy-cli-linux-x86_64.tar.gz -C smithy-install/smithy + - smithy-install/smithy/install + - ln -s $(pwd)/docs .project/docs + - cd .project/docs/definition + script: + - smithy build + - cp build/smithy/openapi-conversion/openapi/sys.openapi.json ../sys.openapi.json + artifacts: + paths: + - .project/docs/sys.openapi.json + dependencies: + - init-job + needs: + - init-job +pages: + stage: doc + rules: + - if: '$CI_COMMIT_BRANCH == "main"' + script: + - mkdir public + - cp docs/index.html public/index.html + - cp .project/docs/sys.openapi.json public/sys.openapi.json + artifacts: + paths: + - public + dependencies: + - smithy-job + needs: + - smithy-job + +build-and-publish-package: + stage: delivery + tags: + - docker + - lab + variables: + DRY_RUN: "no" + needs: + - lint-job + - test-job + rules: + - when: manual + if: '$CI_COMMIT_TAG != null' + + diff --git a/docker-compose copy.yml b/docker-compose copy.yml new file mode 100644 index 0000000..b12cc39 --- /dev/null +++ b/docker-compose copy.yml @@ -0,0 +1,40 @@ +version: '3.4' +services: + postgres: + image: postgres:15-alpine + container_name: postgres + environment: + POSTGRES_PASSWORD: password + POSTGRES_USER: username + POSTGRES_DB: netbox + volumes: + - ./local/postgresql/seed/:/docker-entrypoint-initdb.d + - ./local/postgresql/data:/var/lib/postgresql/data + ports: + - 5432:5432 + + adminer: + image: adminer + container_name: adminer + ports: + - 8080:8080 + + redis: + image: redis:7-alpine + container_name: redis + environment: + REDIS_PASSWORD: password + command: + - sh + - -c # this is to evaluate the $REDIS_PASSWORD from the env + - redis-server --appendonly yes --requirepass "$$REDIS_PASSWORD" # $$ is because of Docker + volumes: + - ./local/redis/data/:/data + ports: + - 6379:6379 + + redisinsight: + image: redislabs/redisinsight:latest + container_name: redisinsight + ports: + - 8001:8001 -- GitLab From e5b7934ec4d527949158259aa619e42e62e220cb Mon Sep 17 00:00:00 2001 From: Frederico Sequeira <frederico.sequeira@ext.ec.europa.eu> Date: Mon, 13 Jan 2025 10:26:44 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=92=9A=20Add=20index=20file=20for=20s?= =?UTF-8?q?mithy=20job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 docs/index.html diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..fdaf103 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <meta + name="description" + content="Console — Netbox SYS Plugin Service — v1.0.0" + /> + <title>Console — Netbox SYS Plugin Service — v0.0.1</title> + <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css" /> +</head> +<body> +<div id="swagger-ui"></div> +<script src="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js" crossorigin></script> +<script> + window.onload = () => { + window.ui = SwaggerUIBundle({ + url: 'sys.openapi.json', + dom_id: '#swagger-ui', + }); + }; +</script> +</body> +</html> -- GitLab From 68c098cd9bb0f84e004903fe6cb7977b9cb53963 Mon Sep 17 00:00:00 2001 From: Frederico Sequeira <frederico.sequeira@ext.ec.europa.eu> Date: Mon, 13 Jan 2025 10:54:41 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=F0=9F=9A=A8=20Fix=20T?= =?UTF-8?q?ypo=20and=20Lint=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pylintrc | 2 +- netbox_configuration/configuration_testing.py | 2 +- netbox_sys_plugin/views.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 4f39def..97d54e7 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,5 +1,5 @@ [MASTER] -disable=R0903,R0901,C0103,C0114,C0115 +disable=R0903,R0901,C0103,C0114,C0115,E1101 min-similarity-lines=10 exclude-protected=_meta,_asdict,_fields,_replace,_source,_make,os._exit ignore=migrations diff --git a/netbox_configuration/configuration_testing.py b/netbox_configuration/configuration_testing.py index e8ede64..fb257ad 100644 --- a/netbox_configuration/configuration_testing.py +++ b/netbox_configuration/configuration_testing.py @@ -15,7 +15,7 @@ DATABASE = { } PLUGINS = [ - "netbox_mac_address_plugin", + "netbox_sys_plugin", ] REDIS = { diff --git a/netbox_sys_plugin/views.py b/netbox_sys_plugin/views.py index 92eeffe..48e31e9 100644 --- a/netbox_sys_plugin/views.py +++ b/netbox_sys_plugin/views.py @@ -131,6 +131,7 @@ class CreateVmView(generic.ObjectView): def get(self, request): """Process GET Create VM Form""" + # pylint: disable=W0221 form = self.form_class() return render(request, self.template_name, {'form': form}) -- GitLab From fe4d6008dafd003c1f2d1bfca8ac84a582738a3c Mon Sep 17 00:00:00 2001 From: Frederico Sequeira <frederico.sequeira@ext.ec.europa.eu> Date: Mon, 13 Jan 2025 14:12:14 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=A5=20Remove=20duplicated=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose copy.yml | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 docker-compose copy.yml diff --git a/docker-compose copy.yml b/docker-compose copy.yml deleted file mode 100644 index b12cc39..0000000 --- a/docker-compose copy.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: '3.4' -services: - postgres: - image: postgres:15-alpine - container_name: postgres - environment: - POSTGRES_PASSWORD: password - POSTGRES_USER: username - POSTGRES_DB: netbox - volumes: - - ./local/postgresql/seed/:/docker-entrypoint-initdb.d - - ./local/postgresql/data:/var/lib/postgresql/data - ports: - - 5432:5432 - - adminer: - image: adminer - container_name: adminer - ports: - - 8080:8080 - - redis: - image: redis:7-alpine - container_name: redis - environment: - REDIS_PASSWORD: password - command: - - sh - - -c # this is to evaluate the $REDIS_PASSWORD from the env - - redis-server --appendonly yes --requirepass "$$REDIS_PASSWORD" # $$ is because of Docker - volumes: - - ./local/redis/data/:/data - ports: - - 6379:6379 - - redisinsight: - image: redislabs/redisinsight:latest - container_name: redisinsight - ports: - - 8001:8001 -- GitLab