Skip to content

Commit

Permalink
Cookie updated by NetworkToCode Cookie Drift Manager Tool (#730)
Browse files Browse the repository at this point in the history
* Cookie updated by NetworkToCode Cookie Drift Manager Tool

Template:

```
{
    "template": "https://github.com/nautobot/cookiecutter-nautobot-app.git",
    "dir": "nautobot-app",
    "ref": "refs/tags/nautobot-app-v2.2.0",
    "path": null
}
```

Cookie:

```
{
    "remote": "https://github.com/nautobot/nautobot-app-golden-config.git",
    "path": "/tmp/tmptjpgbanq/nautobot-app-golden-config",
    "repository_path": "/tmp/tmptjpgbanq/nautobot-app-golden-config",
    "dir": "",
    "branch_prefix": "drift-manager",
    "context": {
        "codeowner_github_usernames": "@itdependsnetworks @jeffkala @nkallergis",
        "full_name": "Network to Code, LLC",
        "email": "[email protected]",
        "github_org": "nautobot",
        "app_name": "nautobot_golden_config",
        "verbose_name": "Golden Config",
        "app_slug": "nautobot-golden-config",
        "project_slug": "nautobot-app-golden-config",
        "repo_url": "https://github.com/nautobot/nautobot-app-golden-config",
        "base_url": "golden-config",
        "min_nautobot_version": "2.0.0",
        "max_nautobot_version": "2.9999",
        "camel_name": "NautobotGoldenConfig",
        "project_short_description": "An app for configuration on nautobot",
        "model_class_name": "None",
        "open_source_license": "Apache-2.0",
        "docs_base_url": "https://docs.nautobot.com",
        "docs_app_url": "https://docs.nautobot.com/projects/golden-config/en/latest",
        "_template": "https://github.com/nautobot/cookiecutter-nautobot-app.git",
        "_output_dir": "/tmp/tmptjpgbanq",
        "_repo_dir": "/github/home/.cookiecutters/cookiecutter-nautobot-app/nautobot-app",
        "_checkout": "refs/tags/nautobot-app-v2.2.0"
    },
    "base_branch": "develop",
    "remote_name": "origin",
    "pull_request_strategy": "PullRequestStrategy.CREATE",
    "post_actions": [
        "PostAction.BLACK"
    ],
    "baked_commit_ref": "c9dce46b70f0154a56974587202e71e82ef08bae",
    "draft": true
}
```

CLI Arguments:

```
{
    "cookie_dir": "",
    "input": false,
    "json_filename": "",
    "output_dir": "",
    "push": true,
    "template": "",
    "template_dir": "",
    "template_ref": "refs/tags/nautobot-app-v2.2.0",
    "pull_request": null,
    "post_action": [],
    "disable_post_actions": false,
    "draft": null
}
```
---------

Co-authored-by: bakebot <[email protected]>
Co-authored-by: Jan Snasel <[email protected]>
  • Loading branch information
3 people authored Mar 9, 2024
1 parent 5fbee9f commit d018661
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
"_drift_manager": {
"template": "https://github.com/nautobot/cookiecutter-nautobot-app.git",
"template_dir": "nautobot-app",
"template_ref": "refs/tags/nautobot-app-v2.1.0",
"template_ref": "refs/tags/nautobot-app-v2.2.0",
"cookie_dir": "",
"branch_prefix": "drift-manager",
"pull_request_strategy": "create",
"post_actions": [
"black"
],
"draft": true,
"baked_commit_ref": "c9dce46b70f0154a56974587202e71e82ef08bae"
"baked_commit_ref": "1f3e36613d3c301a807cdbdc4a90e849fd88c554"
}
}
}
Expand Down
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@
- [ ] Attached Screenshots, Payload Example
- [ ] Unit, Integration Tests
- [ ] Documentation Updates (when adding/changing features)
- [ ] Example App Updates (when adding/changing features)
- [ ] Outline Remaining Work, Constraints from Design
72 changes: 16 additions & 56 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Linting: black"
run: "poetry run invoke black"
bandit:
Expand All @@ -36,7 +36,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Linting: bandit"
run: "poetry run invoke bandit"
ruff:
Expand All @@ -47,7 +47,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Linting: ruff"
run: "poetry run invoke ruff"
check-docs-build:
Expand All @@ -58,7 +58,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Check Docs Build"
run: "poetry run invoke build-and-check-docs"
flake8:
Expand All @@ -69,7 +69,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Linting: flake8"
run: "poetry run invoke flake8"
poetry:
Expand All @@ -80,7 +80,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Checking: poetry lock file"
run: "poetry run invoke lock --check"
yamllint:
Expand All @@ -91,10 +91,10 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Linting: yamllint"
run: "poetry run invoke yamllint"
pylint:
check-in-docker:
needs:
- "bandit"
- "ruff"
Expand All @@ -115,7 +115,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Set up Docker Buildx"
id: "buildx"
uses: "docker/setup-buildx-action@v3"
Expand All @@ -137,53 +137,13 @@ jobs:
run: "cp development/creds.example.env development/creds.env"
- name: "Linting: pylint"
run: "poetry run invoke pylint"
check-migrations:
needs:
- "bandit"
- "ruff"
- "flake8"
- "poetry"
- "yamllint"
- "black"
runs-on: "ubuntu-22.04"
strategy:
fail-fast: true
matrix:
python-version: ["3.11"]
nautobot-version: ["2.0.0"]
env:
INVOKE_NAUTOBOT_GOLDEN_CONFIG_PYTHON_VER: "${{ matrix.python-version }}"
INVOKE_NAUTOBOT_GOLDEN_CONFIG_NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
- name: "Set up Docker Buildx"
id: "buildx"
uses: "docker/setup-buildx-action@v3"
- name: "Build"
uses: "docker/build-push-action@v5"
with:
builder: "${{ steps.buildx.outputs.name }}"
context: "./"
push: false
load: true
tags: "${{ env.APP_NAME }}/nautobot:${{ matrix.nautobot-version }}-py${{ matrix.python-version }}"
file: "./development/Dockerfile"
cache-from: "type=gha,scope=${{ matrix.nautobot-version }}-py${{ matrix.python-version }}"
cache-to: "type=gha,scope=${{ matrix.nautobot-version }}-py${{ matrix.python-version }}"
build-args: |
NAUTOBOT_VER=${{ matrix.nautobot-version }}
PYTHON_VER=${{ matrix.python-version }}
- name: "Copy credentials"
run: "cp development/creds.example.env development/creds.env"
- name: "Checking: App Config"
run: "poetry run invoke validate-app-config"
- name: "Checking: migrations"
run: "poetry run invoke check-migrations"
unittest:
needs:
- "pylint"
- "check-migrations"
- "check-in-docker"
strategy:
fail-fast: true
matrix:
Expand All @@ -205,7 +165,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Set up Docker Buildx"
id: "buildx"
uses: "docker/setup-buildx-action@v3"
Expand Down Expand Up @@ -241,7 +201,7 @@ jobs:
with:
fetch-depth: "0"
- name: "Setup environment"
uses: "networktocode/gh-action-setup-poetry-environment@v4"
uses: "networktocode/gh-action-setup-poetry-environment@v6"
- name: "Check for changelog entry"
run: |
git fetch --no-tags origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}
Expand All @@ -258,7 +218,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Set up Python"
uses: "actions/setup-python@v4"
uses: "actions/setup-python@v5"
with:
python-version: "3.11"
- name: "Install Python Packages"
Expand Down Expand Up @@ -293,7 +253,7 @@ jobs:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Set up Python"
uses: "actions/setup-python@v4"
uses: "actions/setup-python@v5"
with:
python-version: "3.11"
- name: "Install Python Packages"
Expand Down
1 change: 1 addition & 0 deletions changes/8.housekeeping
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Re-baked from the latest template.
2 changes: 1 addition & 1 deletion development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ENV INVOKE_NAUTOBOT_GOLDEN_CONFIG_LOCAL=true
# Since this is only used for development and we don't ship this container, pinning Poetry back is not expressly necessary
# We also don't need virtual environments in container
RUN which poetry || curl -sSL https://install.python-poetry.org | python3 - && \
poetry config virtualenvs.create false
poetry config virtualenvs.create false

# !!! USE CAUTION WHEN MODIFYING LINES ABOVE
# -------------------------------------------------------------------------------------
Expand Down
64 changes: 64 additions & 0 deletions development/app_config_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""App Config Schema Generator and Validator."""
import json
from importlib import import_module
from os import getenv
from pathlib import Path
from urllib.parse import urlparse

import jsonschema
import toml
from django.conf import settings
from to_json_schema.to_json_schema import SchemaBuilder


def _enrich_object_schema(schema, defaults, required):
schema["additionalProperties"] = False
for key, value in schema["properties"].items():
if required and key in required:
value["required"] = True
default_value = defaults and defaults.get(key, None)
if value["type"] == "object" and "properties" in value:
_enrich_object_schema(value, default_value, None)
elif default_value is not None:
value["default"] = default_value


def _main():
pyproject = toml.loads(Path("pyproject.toml").read_text())
url = urlparse(pyproject["tool"]["poetry"]["repository"])
_, owner, repository = url.path.split("/")
package_name = pyproject["tool"]["poetry"]["packages"][0]["include"]
app_config = settings.PLUGINS_CONFIG[package_name] # type: ignore
schema_path = Path(package_name) / "app-config-schema.json"
command = getenv("APP_CONFIG_SCHEMA_COMMAND", "")
if command == "generate":
schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": f"https://raw.githubusercontent.com/{owner}/{repository}/develop/{package_name}/app-config-schema.json",
"$comment": "TBD: Update $id, replace `develop` with the future release tag",
**SchemaBuilder().to_json_schema(app_config), # type: ignore
}
app_config = import_module(package_name).config
_enrich_object_schema(schema, app_config.default_settings, app_config.required_settings)
schema_path.write_text(json.dumps(schema, indent=4) + "\n")
print(f"\n==================\nGenerated schema:\n\n{schema_path}\n")
print(
"WARNING: Review and edit the generated file before committing.\n"
"\n"
"Its content is inferred from:\n"
"\n"
"- The current configuration in `PLUGINS_CONFIG`\n"
"- `NautobotAppConfig.default_settings`\n"
"- `NautobotAppConfig.required_settings`"
)
elif command == "validate":
schema = json.loads(schema_path.read_text())
jsonschema.validate(app_config, schema)
print(
f"\n==================\nValidated configuration using the schema:\n{schema_path}\nConfiguration is valid."
)
else:
raise RuntimeError(f"Unknown command: {command}")


_main()
4 changes: 2 additions & 2 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@
"disable_existing_loggers": False,
"formatters": {
"normal": {
"format": "%(asctime)s.%(msecs)03d %(levelname)-7s %(name)s :\n %(message)s",
"format": "%(asctime)s.%(msecs)03d %(levelname)-7s %(name)s : %(message)s",
"datefmt": "%H:%M:%S",
},
"verbose": {
"format": "%(asctime)s.%(msecs)03d %(levelname)-7s %(name)-20s %(filename)-15s %(funcName)30s() :\n %(message)s",
"format": "%(asctime)s.%(msecs)03d %(levelname)-7s %(name)-20s %(filename)-15s %(funcName)30s() : %(message)s",
"datefmt": "%H:%M:%S",
},
},
Expand Down
2 changes: 1 addition & 1 deletion development/towncrier_template.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{% if render_title %}
## v{{ versiondata.version }} ({{ versiondata.date }})
## [v{{ versiondata.version }} ({{ versiondata.date }})]({{ cookiecutter.repo_url }}/releases/tag/v{{ versiondata.version}})

{% endif %}
{% for section, _ in sections.items() %}
Expand Down
2 changes: 1 addition & 1 deletion docs/admin/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ There are no access requirements from external systems to this app.
## Install Guide

!!! note
Apps can be installed manually or using Python's `pip`. See the [nautobot documentation](https://nautobot.readthedocs.io/en/latest/plugins/#install-the-package) for more details. The pip package name for this app is [`nautobot-golden-config`](https://pypi.org/project/nautobot-golden-config/).
Apps can be installed from the [Python Package Index](https://pypi.org/) or locally. See the [Nautobot documentation](https://docs.nautobot.com/projects/core/en/stable/user-guide/administration/installation/app-install/) for more details. The pip package name for this app is [`nautobot-golden-config`](https://pypi.org/project/nautobot-golden-config/).

The app is available as a Python package via PyPI and can be installed with `pip`:

Expand Down
42 changes: 18 additions & 24 deletions docs/dev/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,30 @@ All pull requests to `next` or `develop` must include a changelog fragment file

The branching policy includes the following tenets:

- The `develop` branch is the branch for bug fixes.
- The `next` branch is the branch for new features.
- The `stable-<major>.<minor>` branch is the branch of the latest version within that major/minor version.
- The `stable-<major>.<minor>` branch will have all of the latest bug fixes and security patches, and may or may not represent the released version.
- PRs intended to add new features should be branched from and merged to the `next` branch.
- PRs intended to add new features that break backward compatibility should be discussed before a PR is created.
- PRs intended to address bug fixes and security patches should be branched from and merged to the `develop` branch.
- The `develop` branch is the branch of the next major and minor paired version planned.
- PRs intended to add new features should be sourced from the `develop` branch.
- PRs intended to fix issues in the Nautobot LTM compatible release should be sourced from the latest `ltm-<major.minor>` branch instead of `develop`.

Nautobot Golden Config will observe semantic versioning, as of 1.0. This may result in an quick turn around in minor versions to keep pace with an ever growing feature set.
Golden Config will observe semantic versioning, as of 1.0. This may result in a quick turnaround in minor versions to keep pace with an ever growing feature set.

## Release Policy

Nautobot Golden Config has currently no intended scheduled release schedule, and will release new features in minor versions.
Golden Config has currently no intended scheduled release schedule, and will release new features in minor versions.

When a new release of any kind (e.g. from `develop` to `main`, or a release of a `stable-<major>.<minor>`) is created the following should happen.
When a new release, from `develop` to `main`, is created the following should happen.

- A release PR is created:
- Add and/or update to the changelog in `docs/admin/release_notes/version_<major>.<minor>.md` file to reflect the changes.
- Update the mkdocs.yml file to include updates when adding a new release_notes version file.
- Change the version from `<major>.<minor>.<patch>-beta` to `<major>.<minor>.<patch>` in pyproject.toml.
- Set the PR to the proper branch, e.g. either `main` or `stable-<major>.<minor>`.
- A release PR is created from `develop` with:
- Update the release notes in `docs/admin/release_notes/version_<major>.<minor>.md` file to reflect the changes.
- Change the version from `<major>.<minor>.<patch>-beta` to `<major>.<minor>.<patch>` in `pyproject.toml`.
- Set the PR to the `main` branch.
- Ensure the tests for the PR pass.
- Merge the PR.
- Create a new tag:
- The tag should be in the form of `v<major>.<minor>.<patch>`.
- The title should be in the form of `v<major>.<minor>.<patch>`.
- The description should be the changes that were added to the `version_<major>.<minor>.md` document.
- If merged into `main`, then push from `main` to `develop`, in order to retain the merge commit created when the PR was merged.
- If the is a new `<major>.<minor>`, create a `stable-<major>.<minor>` for the **previous** version, so that security updates to old versions may be applied more easily.
- A post release PR is created:
- Change the version from `<major>.<minor>.<patch>` to `<major>.<minor>.<patch + 1>-beta` in pyproject.toml.
- Set the PR to the proper branch, e.g. either `develop` or `stable-<major>.<minor>`.
- Once tests pass, merge.
- The tag should be in the form of `v<major>.<minor>.<patch>`.
- The title should be in the form of `v<major>.<minor>.<patch>`.
- The description should be the changes that were added to the `version_<major>.<minor>.md` document.
- If merged into `main`, then push from `main` to `develop`, in order to retain the merge commit created when the PR was merged
- A post release PR is created with:
- Change the version from `<major>.<minor>.<patch>` to `<major>.<minor>.<patch + 1>-beta` in both `pyproject.toml` and `nautobot.__init__.__version__`.
- Set the PR to the proper branch, `develop`.
- Once tests pass, merge.
20 changes: 19 additions & 1 deletion docs/dev/dev_environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ nautobot-server migrate
!!! note
If you want to develop on the latest develop branch of Nautobot, run the following command: `poetry add --optional git+https://github.com/nautobot/nautobot@develop`. After the `@` symbol must match either a branch or a tag.

You can now run `nautobot-server` commands as you would from the [Nautobot documentation](https://nautobot.readthedocs.io/en/latest/) for example to start the development server:
You can now run `nautobot-server` commands as you would from the [Nautobot documentation](https://docs.nautobot.com/projects/core/en/stable/user-guide/administration/tools/nautobot-server/) for example to start the development server:

```shell
nautobot-server runserver 0.0.0.0:8080 --insecure
Expand Down Expand Up @@ -470,3 +470,21 @@ To run an individual test, you can run any or all of the following:
➜ invoke ruff
➜ invoke pylint
```

### App Configuration Schema

In the package source, there is the `nautobot_golden_config/app-config-schema.json` file, conforming to the [JSON Schema](https://json-schema.org/) format. This file is used to validate the configuration of the app in CI pipelines.

If you make changes to `PLUGINS_CONFIG` or the configuration schema, you can run the following command to validate the schema:

```bash
invoke validate-app-config
```

To generate the `app-config-schema.json` file based on the current `PLUGINS_CONFIG` configuration, run the following command:

```bash
invoke generate-app-config-schema
```

This command can only guess the schema, so it's up to the developer to manually update the schema as needed.
6 changes: 5 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ markdown_extensions:
anchor_linenums: true
- "pymdownx.inlinehilite"
- "pymdownx.snippets"
- "pymdownx.superfences"
- "pymdownx.superfences":
custom_fences:
- name: "mermaid"
class: "mermaid"
format: !!python/name:pymdownx.superfences.fence_code_format
- "footnotes"
plugins:
- "search"
Expand Down
Loading

0 comments on commit d018661

Please sign in to comment.