$schema: "pipeline.schema.v1"
serviceGroup: Microsoft.Azure.ARO.HCP.Maestro.Agent
rolloutName: Maestro Agent Rollout
resourceGroups:
- name: '{{ .global.rg }}'
  subscription: '{{ .global.subscription }}'
  steps:
  - name: mirror-image
    action: Shell
    command: ../../image-sync/on-demand/sync.sh
    dryRun:
      variables:
      - name: DRY_RUN
        value: "true"
    variables:
    - name: TARGET_ACR
      configRef: 'acr.svc.name'
    - name: SOURCE_REGISTRY
      configRef: maestro.image.registry
    - name: REPOSITORY
      configRef: maestro.image.repository
    - name: DIGEST
      configRef: maestro.image.digest
    - name: PULL_SECRET_KV
      configRef: global.keyVault.name
    - name: PULL_SECRET
      configRef: imageSync.componentSync.pullSecretName
- name: '{{ .regionRG  }}'
  subscription: '{{ .svc.subscription  }}'
  steps:
  - name: region-output
    action: ARM
    template: ../../dev-infrastructure/templates/output-region.bicep
    parameters: ../../dev-infrastructure/configurations/output-region.tmpl.bicepparam
    deploymentLevel: ResourceGroup
    outputOnly: true
- name: '{{ .mgmt.rg  }}'
  subscription: '{{ .mgmt.subscription  }}'
  aksCluster: '{{ .mgmt.aks.name  }}'
  steps:
  - name: deploy
    action: Shell
    command: make deploy
    dryRun:
      variables:
      - name: DRY_RUN
        value: "true"
    variables:
    - name: EVENTGRID_NAME
      configRef: maestro.eventGrid.name
    - name: REGION_RG
      configRef: regionRG
    - name: MGMT_RG
      configRef: mgmt.rg
    - name: CONSUMER_NAME
      configRef: maestro.agent.consumerName
    - name: MAESTRO_LOG_LEVEL
      configRef: maestro.agent.loglevel
    - name: KEYVAULT_NAME
      configRef: mgmtKeyVault.name
    - name: IMAGE_REPO
      configRef: maestro.image.repository
    - name: IMAGE_DIGEST
      configRef: maestro.image.digest
    - name: SIDECAR_IMAGE_REGISTRY
      configRef: maestro.agent.sidecar.image.registry
    - name: SIDECAR_IMAGE_REPOSITORY
      configRef: maestro.agent.sidecar.image.repository
    - name: SIDECAR_IMAGE_DIGEST
      configRef: maestro.agent.sidecar.image.digest
    - name: ACR_NAME
      configRef: acr.svc.name
    - name: EVENTGRID_HOSTNAME
      input:
        step: region-output
        name: maestroEventGridNamespacesHostname
    dependsOn:
    - mirror-image
    - region-output
- name: '{{ .svc.rg  }}'
  subscription: '{{ .svc.subscription  }}'
  aksCluster: '{{ .svc.aks.name  }}'
  steps:
  - name: register-agent-with-server
    action: Shell
    command: make -C ../registration deploy
    dryRun:
      variables:
      - name: DRY_RUN
        value: "true"
    variables:
    - name: CONSUMER_NAME
      configRef: maestro.agent.consumerName
    - name: NAMESPACE
      configRef: maestro.server.k8s.namespace
    dependsOn:
    - deploy
