Code Monkey home page Code Monkey logo

Comments (2)

Minal1409 avatar Minal1409 commented on August 28, 2024

Yes this feature will be useful as we have morethan 100 templates. Some way is required to group this templates

from netpalm.

rhwendt avatar rhwendt commented on August 28, 2024

You can load any templates you want by editing the config.json

❯ grep j2 config.json
    "jinja2_config_templates": "netpalm/backend/plugins/extensibles/j2_config_templates/",
    "jinja2_service_templates": "netpalm/backend/plugins/extensibles/j2_service_templates/",
    "webhook_jinja2_templates": "netpalm/backend/plugins/extensibles/j2_webhook_templates/",

This can be tricky if you're using netpalm as a dependency. In our case we are cloning into our main project.

For example our project looks like this from the root folder.

├── netpalm
│   ├── CODE_OF_CONDUCT.md
│   ├── config
│   ├── CONTRIBUTING.md
│   ├── docker-compose.ci.yml
│   ├── docker-compose.dev.yml
│   ├── docker-compose.yml
│   ├── dockerfiles
│   ├── gunicorn.conf.py
│   ├── LICENSE
│   ├── netpalm
│   ├── netpalm.postman_collection.json
│   ├── NOTICE
│   ├── pytest.ini
│   ├── README.md
│   ├── redis_gen_new_certs.sh
│   ├── RUNNING_TESTS.md
│   ├── static
│   ├── tests
│   └── worker.py
├── README.md
├── templates
│   ├── config
│   └── service

Our build does some ugly text replace in the netpalm dockerfiles before we build it. I'm sure this could be done easier.

    - name: change the context of netpalm controller
      replace:
        path: /conductor/netpalm/docker-compose.yml
        regexp: "^          context: ."
        replace: "          context: .."

    - name: edit the context of netpalm controller dockerfile
      lineinfile:
        path: /conductor/netpalm/docker-compose.yml
        insertafter: "^          context: .."
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
      loop:
        - { regexp: "^          dockerfile: ./dockerfiles/netpalm_controller_dockerfile",
            line: "          dockerfile: ./netpalm/dockerfiles/netpalm_controller_dockerfile" }
        - { regexp: "^          dockerfile: ./dockerfiles/netpalm_pinned_worker_dockerfile",
            line: "          dockerfile: ./netpalm/dockerfiles/netpalm_pinned_worker_dockerfile" }
        - { regexp: "^          dockerfile: ./dockerfiles/netpalm_fifo_worker_dockerfile",
            line: "          dockerfile: ./netpalm/dockerfiles/netpalm_fifo_worker_dockerfile" }

    - name: edit the dockerfile for netpalm and workers
      lineinfile:
        path: "{{ item.path }}"
        regexp: "{{ item.regexp }}"
        line: "{{ item.line }}"
      loop:
       - { regexp: "^ADD netpalm/requirements.txt /code/",
           line: "ADD ./netpalm/netpalm/requirements.txt /code/",
           path: "/conductor/netpalm/dockerfiles/netpalm_controller_dockerfile" }
       - { regexp: "^ADD netpalm/worker_requirements.txt /code/",
           line: "ADD ./netpalm/netpalm/worker_requirements.txt /code/",
           path: "/conductor/netpalm/dockerfiles/netpalm_pinned_worker_dockerfile" }
       - { regexp: "^ADD netpalm/worker_requirements.txt /code/",
           line: "ADD ./netpalm/netpalm/worker_requirements.txt /code/",
           path: "/conductor/netpalm/dockerfiles/netpalm_fifo_worker_dockerfile" }
       - { regexp: "^ADD . /code",
           line: "ADD ./netpalm /code",
           path: "/conductor/netpalm/dockerfiles/netpalm_controller_dockerfile" }
       - { regexp: "^ADD . /code",
           line: "ADD ./netpalm /code",
           path: "/conductor/netpalm/dockerfiles/netpalm_pinned_worker_dockerfile" }
       - { regexp: "^ADD . /code",
           line: "ADD ./netpalm /code",
           path: "/conductor/netpalm/dockerfiles/netpalm_fifo_worker_dockerfile" }

    - name: add the templates netpalm controller and workers
      lineinfile:
        path: "{{ item.path }}"
        line: "ADD ./templates /code/templates"
        insertafter: "^ADD ./netpalm /code"
      loop:
        - { path: "/conductor/netpalm/dockerfiles/netpalm_controller_dockerfile" }
        - { path: "/conductor/netpalm/dockerfiles/netpalm_pinned_worker_dockerfile" }
        - { path: "/conductor/netpalm/dockerfiles/netpalm_fifo_worker_dockerfile" }

    - name: Update netpalm templates directory in netpalm config
      lineinfile:
        path: /conductor/netpalm/config/config.json
        regexp: "{{ item.regex }}"
        line: "{{ item.line }}"
      loop:
        - { regex: '"jinja2_service_templates":',
            line: '    "jinja2_service_templates": "/code/templates/service/",' }
        - { regex: '"jinja2_config_templates":',
            line: '    "jinja2_config_templates": "/code/templates/config/",' }

from netpalm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.