Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 lib #629

Open
wants to merge 125 commits into
base: master
Choose a base branch
from
Open

v2 lib #629

wants to merge 125 commits into from

Conversation

stavros-k
Copy link
Contributor

@stavros-k stavros-k commented Oct 7, 2024

V2 lib aims to

  • Have a standard API to use within templates.
  • Validate and fail as early as possible in development with clear messages
  • Automate some fields that are coming from known structures, like resources, network, storage etc
  • Have tests so we can ensure we don't break things in the future
  • Minimize the need to use jinja templating as much as possible, in order to avoid its quirks.
  • Provide a cleaner way to define apps
  • be extendable

So far there are few things that have been added, but few bigs are missing.

  • Storage
  • Dependencies (predefined) eg postgres/mariadb/redis/perms
  • Networks (Will be done in a later PR)

Currently the imports are duplicated, once with a relative import and one without inside a try/except block.
That is because in jinja it wont work without the relative import, but pytest wont work with relative imports.
If there is a way to fix that, please let me know!

@stavros-k stavros-k changed the title initial v2 lib v2 lib Oct 8, 2024
@stavros-k
Copy link
Contributor Author

stavros-k commented Oct 8, 2024

This is how a compose file will look like for a single container

{% set tpl = ix_lib.base.render.Render(values) %}

{% set c1 = tpl.add_container(values.consts.app_container_name, "image") %}

{% set perm_container = tpl.deps.perms("perm_container_name") %}
{% set perms_config = {"uid": 1000, "gid": 1000, "mode": "check"} %} # optional
{% set vol_config1 = { .. } %} # this will come from questions
{% set vol_config2 = { .. } %} # this will come from questions

{% do c1.volume_mounts.add_volume_mount("/some/mount/path", vol_config1) %}
{% do c1.volume_mounts.add_volume_mount("/some/mount/path2", vol_config2) %}
{% do perm_container.add_or_skip_action("action_id1", vol_config1, perms_config) %}
{% do perm_container.add_or_skip_action("action_id2", vol_config2, perms_config) %}

{% for store in values.storage.additional_storage %}
  {% do c1.volumes.mount_volume(store.mount_path, store) %}
{% endfor %}

{% do c1.ports.add_port(values.network.web_port, values.network.web_port) %}

{% do c1.environment.add_user_envs(values.app.additional_envs) %}
{% do c1.environment.add_env("HOST", "0.0.0.0") %}
{% do c1.environment.add_env("PORT", values.network.web_port) %}

{% do c1.healthcheck.set_test("curl", {"port": values.network.web_port, "path": "/health"}) %}

{# if add_or_skip_action might had parsed config and found no reason to add an action #}
{% if perm_container.has_actions() %}
  {% do perm_container.activate() %}
  {% do c1.depends.add_dependency(tpl.permissions_container_name(), "service_copleted_successfully") %}
{% endif %}

{{ tpl.render() | tojson }}

@stavros-k
Copy link
Contributor Author

I think this is fine for initial review, and potentially merge and start using it on new apps for now.
To make sure everything works smoothly, before we start using it on existing apps.

@stavros-k stavros-k marked this pull request as ready for review October 21, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant