microsoft / bedrock-cli

The CLI for Bedrock
https://microsoft.github.io/bedrock-cli/commands/
MIT License
28 stars 12 forks source link

`bedrock hld init` should produce a templated pipeline #56

Open andrebriggs opened 4 years ago

andrebriggs commented 4 years ago

Related to https://github.com/microsoft/bedrock/issues/1423

Currently we produce a AzDO pipeline yaml that looks like this:

# GENERATED WITH BEDROCK VERSION 0.6.5
trigger:
  branches:
    include:
      - master
variables:
  - group: quick-start-vg
pool:
  vmImage: ubuntu-latest
steps:
  - checkout: self
    persistCredentials: true
    clean: true
  - task: HelmInstaller@1
    inputs:
      helmVersionToInstall: 2.16.3
  - script: |-
      set -e
      # Download build.sh
      curl $BEDROCK_BUILD_SCRIPT > build.sh
      chmod +x ./build.sh
    displayName: Download bedrock bash scripts
    env:
      BEDROCK_BUILD_SCRIPT: $(BUILD_SCRIPT_URL)
  - script: |-
      set -e
      commitId=$(Build.SourceVersion)
      commitId=$(echo "${commitId:0:7}")
      . ./build.sh --source-only
      get_bedrock_version
      download_bedrock
      pullrequestid=$(az repos pr list --organization $(System.TeamFoundationCollectionUri) --project $(System.TeamProject) --status completed | jq -r --arg commitid "$(Build.SourceVersion)" '.[] | select(.lastMergeCommit.commitId | startswith($commitid))' | jq '.pullRequestId')
      if [[ -z "$pullrequestid" ]]; then
      ./bedrock/bedrock deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId
      else
      ./bedrock/bedrock deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --hld-commit-id $commitId --pr $pullrequestid
      fi
    displayName: 'If configured, update manifest pipeline details in Spektate db before manifest generation'
    condition: 'and(ne(variables[''INTROSPECTION_ACCOUNT_NAME''], ''''), ne(variables[''INTROSPECTION_ACCOUNT_KEY''], ''''),ne(variables[''INTROSPECTION_TABLE_NAME''], ''''),ne(variables[''INTROSPECTION_PARTITION_KEY''], ''''), ne(variables[''Build.Reason''], ''PullRequest''))'
    env:
      AZURE_DEVOPS_EXT_PAT: $(PAT)
  - task: ShellScript@2
    displayName: Validate fabrikate definitions
    inputs:
      scriptPath: build.sh
    condition: 'eq(variables[''Build.Reason''], ''PullRequest'')'
    env:
      VERIFY_ONLY: 1
  - task: ShellScript@2
    displayName: Transform fabrikate definitions and publish to YAML manifests to repo
    inputs:
      scriptPath: build.sh
    condition: 'ne(variables[''Build.Reason''], ''PullRequest'')'
    env:
      ACCESS_TOKEN_SECRET: $(PAT)
      COMMIT_MESSAGE: $(Build.SourceVersionMessage)
      REPO: $(MANIFEST_REPO)
      BRANCH_NAME: $(Build.SourceBranchName)
  - script: |-
      set -e
      . ./build.sh --source-only
      cd "$HOME"/${MANIFEST_REPO##*/}
      latest_commit=$(git rev-parse --short HEAD)
      url=$(git remote --verbose | grep origin | grep fetch | cut -f2 | cut -d' ' -f1)
      repourl=${url##*@}
      get_bedrock_version
      download_bedrock
      ./bedrock/bedrock deployment create -n $(INTROSPECTION_ACCOUNT_NAME) -k $(INTROSPECTION_ACCOUNT_KEY) -t $(INTROSPECTION_TABLE_NAME) -p $(INTROSPECTION_PARTITION_KEY) --p3 $(Build.BuildId) --manifest-commit-id $latest_commit --repository $repourl
    displayName: 'If configured, update manifest pipeline details in Spektate db after manifest generation'
    condition: 'and(ne(variables[''INTROSPECTION_ACCOUNT_NAME''], ''''), ne(variables[''INTROSPECTION_ACCOUNT_KEY''], ''''),ne(variables[''INTROSPECTION_TABLE_NAME''], ''''),ne(variables[''INTROSPECTION_PARTITION_KEY''], ''''), ne(variables[''Build.Reason''], ''PullRequest''))'

Based upon information in https://github.com/microsoft/bedrock/issues/1423 We should create a version of this Yaml that is templated.

evanlouie commented 4 years ago

@bnookala Thoughts on this for this week?