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

Migrate to 1ES templates for internal builds #19016

Merged
merged 38 commits into from
Mar 15, 2024
Merged

Conversation

MiYanni
Copy link
Member

@MiYanni MiYanni commented Mar 12, 2024

Summary

This effort is to migrate to the 1ES pipeline templates (1ES PT). This repo shows a migration to these templates with a repo that uses Arcade. Arcade pushed an update for their pipeline templates that work with the 1ES templates. This PR extends the 1ES PT and updates the internal pipeline to use the updated Arcade templates. Our internal pipeline uses .vsts-ci.yml and our external (PR) pipeline uses .vsts-pr.yml.

Below, I've included my notes on the process as I went through the process of adopting these templates. Note that these notes may have some specifics that apply to only Arcade repos or only this repo, so these instructions aren't complete for every situation.

High-Level Notes

  • I used this PR as a reference: https://dnceng.visualstudio.com/internal/_git/dotnet-symreader/pullrequest/37739
    • This isn't a great reference as some of the information is wrong/inaccurate, so take it with a grain of salt
    • This is a bad example. Use this PR itself as an example.
  • In VSCode/your editor of choice, turn on View -> Appearance -> Render Whitespace
    • This helps with seeing correct indentation, which is required for YAML.
  • Verify you have the ability to create internal branches on your repo for testing
  • Prior to this PR being merged, switch the PR pipeline to new pr yml file
  • You may need to do split-diff view AND ignore whitespace changes on this PR to view it, since indentation gets shifted around

Process

Extend 1ES PT

  • Add the 1ESPipelineTemplates repo as a resource
    • Note: You may already have a resources: node or even repositories: under it. This is an additional repository object in that array.

Example

resources:
  repositories:
  - repository: 1esPipelines
    type: git
    name: 1ESPipelineTemplates/1ESPipelineTemplates
    ref: refs/tags/release
  • Extend the 1ES template and indent stages: as a parameters: property
    • The template: is referencing the repository above and the YAML file in that repo
    • The sourceAnalysisPool: sets the pool information for running the SDL tools. See the section on updating build pools for more context.
    • The customBuildTags: adds tags to your pipeline runs for 1ES.

Before

stages:
- stage: Build
  jobs:
...

After

extends:
  template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines
  parameters:
    sdl:
      sourceAnalysisPool:
        name: $(DncEngInternalBuildPool)
        image: 1es-windows-2022
        os: windows
    customBuildTags:
    - ES365AIMigrationTooling
    stages:
    - stage: Build
      jobs:
...

Update local template paths

Arcade Templates

Before

template: /eng/common/templates/job/job.yml

After

template: /eng/common/templates-official/job/job.yml@self

Non-Arcade Templates

Before

template: eng/build.yml

After

template: eng/build.yml@self

Update pool information

  • Update the image information
    • For Windows, images starting with windows.vs2022 or 1es will work with 1ES PT.
    • For Linux, images starting with 1es will work with 1ES PT.
    • For MacOS, the only working image is from the public Azure Pipelines pool. Additional information (see example below) is required for using this with 1ES PT.
    • Image information can be found here: https://helix.dot.net/#1esPools

Before (Windows)

name: $(DncEngInternalBuildPool)
demands: ImageOverride -equals windows.vs2022preview.amd64

After (Windows)

name: $(DncEngInternalBuildPool)
image: windows.vs2022preview.amd64
os: windows

Before (Linux)

name: $(DncEngInternalBuildPool)
demands: ImageOverride -equals build.ubuntu.1804.amd64

After (Linux)

name: $(DncEngInternalBuildPool)
image: 1es-ubuntu-1804
os: linux

Before (Mac)

vmImage: 'macOS-latest'

After (Mac)

name: Azure Pipelines
image: macOS-latest
os: macOS
  • If your pipeline did not use the $(DncEngInternalBuildPool) variable for the pool name previously, you will need to add this variable template to your variables: section

Example

variables:
...
- template: /eng/common/templates-official/variables/pool-providers.yml

Update publish tasks

  • Replace publish: tasks with task: 1ES.PublishPipelineArtifact@1

Before

- publish: $(Build.SourcesDirectory)\eng\buildConfiguration
  artifact: buildConfiguration
  displayName: Publish Build Config

After

- task: 1ES.PublishPipelineArtifact@1
  displayName: Publish Build Config
  inputs:
    targetPath: $(Build.SourcesDirectory)\eng\buildConfiguration
    artifactName: buildConfiguration
  • Replace the task PublishBuildArtifacts@1 with 1ES.PublishBuildArtifacts@1 (just prepend 1ES. to the name)
    • No task values should need to change beyond the task name
    • If you have task errors, you may need to investigate them accordingly

Other Notes (but might apply to you)

  • I needed to duplicate the local eng/build.yml to eng/build-pr.yml so that the PR pipeline uses the original (non-1ES PT) logic
    • I updated the .vsts-pr.yml to reference the eng/build-pr.yml template.
    • Different repos may need to handle their local templates differently, depending on how they are used and what they contain.

Builds

…separate build-pr.yml for PR pipeline to use. Modified CI and normal build.yml to no longer have public conditional logic. Changed to using PT image for migration testing. Updated localization.yml to use the new templates.
…dows agent to PT agent. Fixed Ubuntu agent to PT Ubuntu agent.
…f MicroBuild. Trying only ignoring .packages for component governance.
@@ -1,3 +1,5 @@
# Pipeline: https://dnceng.visualstudio.com/internal/_build?definitionId=286
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added these pipeline link comments to the top of the YAML files so it is easy to get to them.

.vsts-ci.yml Outdated Show resolved Hide resolved
.vsts-ci.yml Outdated Show resolved Hide resolved
@MiYanni
Copy link
Member Author

MiYanni commented Mar 13, 2024

/azp run

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@@ -69,36 +69,42 @@ parameters:
default: false

jobs:
- template: common/templates/job/job.yml
- template: common/templates-official/job/job.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@MiYanni MiYanni Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@self is only needed when you're providing a path as a parameter for a file in another repo, such as the 1ES template. Here, this file is in this repo and the path is in the repo, so it doesn't need it.

Meaning, template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines sets the context to @1esPipelines which is a reference to the 1ESPipelineTemplates repo (set in the resources: node at the top of the pipeline). So, providing parameters to that template will use that path within the context of that repo. Here, that context doesn't exist as this is just a file within the Installer repo with a path to a file within Installer repo. Does that make sense?

eng/build.yml Show resolved Hide resolved
@@ -168,7 +174,7 @@ jobs:
/p:DotNetPublishUsingPipelines=$(_PublishUsingPipelines)
$(_PgoInstrument)

- template: /eng/common/templates/variables/pool-providers.yml
- template: /eng/common/templates-official/variables/pool-providers.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See explanation above.

- ${{ if eq(variables['System.TeamProject'], 'internal') }}:
- group: DotNetBuilds storage account read tokens
- name: _InternalRuntimeDownloadArgs
value: /p:DotNetRuntimeSourceFeed=https://dotnetbuilds.blob.core.windows.net/internal
/p:DotNetRuntimeSourceFeedKey=$(dotnetbuilds-internal-container-read-token-base64)
/p:dotnetbuilds-internal-container-read-token-base64=$(dotnetbuilds-internal-container-read-token-base64)
- template: /eng/common/templates-official/variables/pool-providers.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See explanation above.

- template: eng/build.yml@self
parameters:
agentOs: Linux
jobName: Build_CentOS_8_Stream_Debug_x64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these all debug images?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't. That's not specifying the image used. It is just the name of the job. Debug here means the configuration, specified 2 lines down: buildConfiguration: Debug

@mthalman
Copy link
Member

@MiYanni - This has been causing failures in the Guardian analysis of all the internal CI builds.

@MiYanni
Copy link
Member Author

MiYanni commented Mar 22, 2024

@mthalman True. The failure is the fault of the MicroBuild signing plugin. I've attempted to add baselines that would normally resolve the build issue. However, the file it is failing on, MicroBuild/Plugins/nuget.config, changes every install, which means it cannot be baselined. Discussions have been taking place in the 1ES Pipeline Templates teams channel. Let me know if you'd like a link to that.

So far, I tested one workaround which did not seem to work with how Arcade is using the plugin. I'm currently trying the brute force method of just disabling the tooling temporarily to unblock builds. I'll have a PR soon if that is successful.

@MiYanni
Copy link
Member Author

MiYanni commented Mar 23, 2024

@mthalman I've merged a temporary fix to allow Installer builds of main to work properly again. I'll revert this fix next week when the Arcade updates flow in.

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.

3 participants