capactio / capact

Simple way to manage applications and infrastructure.
https://capact.io
Apache License 2.0
80 stars 19 forks source link

Update populator to properly resolve requires section in Implementation #623

Closed mszostok closed 2 years ago

mszostok commented 2 years ago

Description

Changes proposed in this pull request:

Requires https://github.com/capactio/capact/pull/620 to be merged before.

Testing

  1. Build CLI: make build-tool-populator

  2. Pick some Implementation manifest and add change requires property:

        cap.core.type.platform:
          oneOf:
            - name: kubernetes
              revision: 0.1.0
            - name: cap.type.platform.cloud-foundry
              revision: 0.1.0
  3. Run Neo4j:

    docker run -d \
      -p 7687:7687 -p 7474:7474 \
      -e "NEO4J_AUTH=neo4j/okon" \
      -e "NEO4JLABS_PLUGINS=[\"apoc\"]" \
      --name hub-neo4j-instance \
      ghcr.io/capactio/neo4j:4.2.13-apoc
  4. Populate database:

    1. Build populator: make build-tool-populator

    NOTE: ensure that you use newly built populator!

    env APP_JSONPUBLISHADDR=http://$(ipconfig getifaddr en0) APP_JSON_PUBLISH_PORT="8888" APP_MANIFESTS_PATH="manifests" populator register ocf-manifests --source github.com/capactio/hub-manifests/
  5. Run Public Hub:

    cd hub-js; APP_NEO4J_ENDPOINT=bolt://localhost:7687 APP_NEO4J_PASSWORD=okon APP_HUB_MODE=public npm start
  6. Run query to fetch your Implementation (e.g. use Insomnia):

    In my case, I used "cap.implementation.mattermost.mattermost-team-edition.install":

    query Impl {
        implementation(
            path: "cap.implementation.mattermost.mattermost-team-edition.install"
        ) {
            latestRevision {
                spec {
                    requires {
                        prefix
                        oneOf {
                            typeRef {
                                path
                                revision
                            }
                            alias
                        }
                    }
                }
            }
        }
    }

    Output:

    {
      "data": {
        "implementation": {
          "latestRevision": {
            "spec": {
              "requires": [
                {
                  "prefix": "cap.core.type",
                  "oneOf": [
                    {
                        "typeRef": {
                            "path": "cap.type.platform.cloud-foundry",
                            "revision": "0.1.0"
                        },
                        "alias": null
                    },
                    {
                        "typeRef": {
                            "path": "cap.core.type.platform.kubernetes",
                            "revision": "0.1.0"
                        },
                        "alias": null
                    }
                  ]
                }
              ]
            }
          }
        }
      }
    }

Option 2

  1. Create cluster and populate it with https://github.com/mszostok/os-hub-manifests/tree/support-parent-nodes

  2. Create TypeInstance:

    cat > /tmp/helm-ti.yaml << ENDOFFILE
    typeInstances:
    - alias: helm-ti
      typeRef:
        path: cap.type.helm.storage
        revision: 0.1.0
      value:
        url: "http://example.com/grpc"
    ENDOFFILE
    
    export TI_ID=$(capact ti create -f /tmp/helm-ti.yaml -ojson | jq -r '.[].id')
  3. Create Action Policy:

    cat <<EOF > /tmp/act-policy.yaml
    rules:
    - interface:
        path: cap.interface.capactio.capact.validation.hub.install
      oneOf:
        - implementationConstraints:
            path: "cap.implementation.capactio.capact.validation.io.install"
          inject:
            additionalParameters:
              - name: "mattermost-parameters"
                value:
                  replicaCount: 3
              - name: "rocketchat-parameters"
                value:
                  replicaCount: 5
            requiredTypeInstances:
              - id: ${TI_ID}
                description: "Helm storage"
    EOF
  4. Create and run Action:

    capact act create cap.interface.capactio.capact.validation.hub.install --name test --action-policy-from-file /tmp/act-policy.yaml
    capact act run test
    capact act watch test
    argo logs test

    You should that TypeInstance was injected and details are available in workflow:

    cat /helm-storage.yaml
    url: http://example.com/grpc

    Related issue(s)