Skip to content

Commit 0defc6a

Browse files
committed
updates artifact guide
1 parent ef59c3f commit 0defc6a

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

docs/docs/guides/artifact.mdx

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,56 @@ import ReactPlayer from 'react-player/youtube'
88

99
:::note
1010

11-
This guide has the assumption that you followed the [Creating a Jinja Rendered File (Transform)](./jinja2-transform.mdx) or [Creating a Python transform](./python-transform.mdx) guide as well as [Creating a Group](./groups.mdx) guide
12-
This is a prerequisite.
11+
This guide has the assumption that you followed the [Creating a Jinja Rendered File (Transform)](./jinja2-transform.mdx) or [Creating a Python transform](./python-transform.mdx) guide. This is a prerequisite.
1312

1413
:::
1514

1615
The goal of this guide is to define an artifact for a Jinja rendered Transform or Python transform in Infrahub. We will be using the following steps.
1716

18-
1. Creating an artifact definition
19-
2. Accessing the artifacts
17+
1. Modifying the schema
18+
2. Creating a group and adding member nodes
19+
2. Creating an artifact definition
20+
3. Accessing the artifacts
21+
22+
## Modifying the node schema
23+
24+
Before we can generate an artifact for a node, we need to modify the schema. The node will need to inherit from the `CoreArtifactTarget` generic.
25+
26+
```yaml
27+
---
28+
version: "1.0"
29+
nodes:
30+
- name: Device
31+
namespace: Network
32+
display_labels:
33+
- name__value
34+
inherit_from:
35+
- CoreArtifactTarget
36+
attributes:
37+
- name: name
38+
kind: Text
39+
label: Name
40+
optional: false
41+
unique: true
42+
- name: description
43+
kind: Text
44+
label: Description
45+
optional: true
46+
```
47+
48+
We then have to load the modified schema definition into Infrahub.
49+
50+
```bash
51+
infrahubctl schema load /tmp/schema.yml
52+
```
53+
54+
## Creating a group and adding members
55+
56+
We need to create a group for every Artifact Definition that we will define. An artifact will be generated for every member that is part of that group.
57+
58+
Create a Standard Group with the name `DeviceGroup` and add `NetworkDevice` `switch1`, `switch2` and `switch3` as a member.
59+
60+
More information can be found in the [Creating a group guide](./groups.mdx).
2061

2162
<center>
2263
<ReactPlayer url='https://www.youtube.com/watch?v=ASGMKZVLCbY' light />
@@ -26,23 +67,23 @@ The goal of this guide is to define an artifact for a Jinja rendered Transform o
2667

2768
In the last step we need to define an Artifact definition, which groups together a [transformation](../topics/transformation.mdx) with a target group and forms the definition of the artifact. Artifact definitions can be created via the frontend, via GraphQL or via a [Git repository](../topics/repository.mdx). In this guide we will be using the Git repository.
2869

29-
Add the following contents to the end of the `.infrahub.yml` file at the root of the `tags_render` repository.
70+
Add the following contents to the end of the `.infrahub.yml` file at the root of the `device_config_render` repository.
3071

3172
```yaml
3273
artifact_definitions:
33-
- name: "tags_config_file"
34-
artifact_name: "Tags configuration file"
74+
- name: "device_configuration"
75+
artifact_name: "Device configuration file"
3576
parameters:
36-
tag: "name__value"
77+
name: "name__value"
3778
content_type: "text/plain"
38-
targets: "TagConfigGroup"
39-
transformation: "my-transform"
79+
targets: "DeviceGroup"
80+
transformation: "device_config_transform"
4081
```
4182
4283
This defines an artifact with the following properties:
4384
4485
- **name**: a unique name for the artifact
45-
- **parameters**: the parameter to pass to the transformation GraphQL query, in this case this we will pass the name of the object (tag) as the tag parameter
86+
- **parameters**: the parameter to pass to the transformation GraphQL query, in this case this we will pass the name of the object (device) as the name parameter
4687
- **content type**: the content type for the resulting artifact
4788
- **targets**: the name of a group of which the members will be a target for this artifact
4889
- **transformation**: the Jinja2 or Python transformation that should be used
@@ -53,11 +94,11 @@ Commit the changes to the repository and push them to the Git server
5394

5495
```shell
5596
git add .
56-
git commit -m "add tags_config_file artifact definition"
97+
git commit -m "add device_configuration artifact definition"
5798
git push origin main
5899
```
59100

60-
The artifact definition will be created in the database, when the Task worker(s) notice the change in the Git repository. The `tags_config_file` should now be visible in the Artifact Definition view in the web interface.
101+
The artifact definition will be created in the database, when the Task worker(s) notice the change in the Git repository. The `device_configuration` should now be visible in the Artifact Definition view in the web interface.
61102
![Artifact Definition](../media/guides/artifact/artifact_definition.png)
62103

63104
## Accessing the artifacts
@@ -69,6 +110,8 @@ The artifacts are generated by the git-agents. You can find the resulting artifa
69110
Open an artifact to get the result.
70111

71112
![Artifact detail](../media/guides/artifact/artifact_detail.png)
72-
You can download the artifact by clicking on the `Storage Id` or alternatively through the rest API endpoint `http://<INFRAHUB_HOST:INFRAHUB_PORT>/api/storage/object/<storage_id>`
113+
You can download the artifact by clicking on the download button, or by using the REST API endpoint `http://<INFRAHUB_HOST:INFRAHUB_PORT>/api/storage/object/<storage_id>`. The `Storage Id` can be copied from the menu next to the artifact name.
114+
115+
![Artifact menu](../media/guides/artifact/artifact_menu.png)
73116

74-
Optionally, Infrahub can create a relation between a node and an artifact, by inheriting from the CoreArtifactTarget generic in the schema of the node. This is outside the scope of this guide, since the BuiltinTag node does not inherit from CoreArtifactTarget. More information can be found in the [artifact](../topics/artifact.mdx) topic.
117+
Alternatively we can access the artifact of an object, by navigating to the object detail view. Navigate to device `switch1`'s detail page, from the *Artifacts* tab you can access all the artifacts that were generated for this object.
-7.56 KB
Loading
-87.8 KB
Loading
109 KB
Loading
18 KB
Loading

0 commit comments

Comments
 (0)