Skip to content

Commit

Permalink
Run all steps in a container
Browse files Browse the repository at this point in the history
  • Loading branch information
ellahathaway committed Nov 25, 2024
1 parent 5ef57c8 commit 76a4881
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 99 deletions.
68 changes: 33 additions & 35 deletions eng/pipelines/templates/jobs/vmr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ parameters:
default: ''

- name: container
type: string
default: ''
type: object
default:
image: ''
name: ''

- name: crossRootFs
type: string
Expand Down Expand Up @@ -114,6 +116,22 @@ jobs:
- job: ${{ parameters.buildName }}_${{ parameters.architecture }}${{ replace(format('_BuildPass{0}', coalesce(parameters.buildPass, '1')), '_BuildPass1', '') }}
pool: ${{ parameters.pool }}

# 1ES pipeline template requires that the container is specified in the job level.
# If we are using a container image, we set the container to correct name.
# Otherwise, we set the container to host so that the job runs on the host agent.
${{ if eq(variables['System.TeamProject'], 'internal') }}:
${{ if ne(parameters.container.name, '') }}:
container: ${{ parameters.container.name }}
${{ else }}:
container: host

# For public projects, we always use the container image if it is specified.
${{ else }}:
${{ if ne(parameters.container.image, '') }}:
container:
image: ${{ parameters.container.image }}
options: --privileged

# Currently, CodeQL slows the build down too much
# https://github.com/dotnet/source-build/issues/4276
${{ if and(parameters.isBuiltFromVmr, startswith(parameters.buildName, 'Windows'), eq(variables['System.TeamProject'], 'internal'), ne(variables['Build.Reason'], 'PullRequest')) }}:
Expand Down Expand Up @@ -332,17 +350,21 @@ jobs:
echo "##vso[task.setvariable variable=additionalBuildArgs]--with-sdk /vmr/.dotnet"
fi
docker run --rm -v "$(sourcesPath):/vmr" -w /vmr ${{ parameters.container }} ./prep-source-build.sh $customPrepArgs
cd $(sourcesPath)
./prep-source-build.sh $customPrepArgs
displayName: Prep the Build
- script: |
set -ex
df -h
customEnvVars=""
customPreBuildArgs=""
customBuildArgs="--ci --clean-while-building --prepareMachine"
if [[ '${{ parameters.runOnline }}' == 'True' ]]; then
customBuildArgs="$customBuildArgs --online"
else
customPreBuildArgs="$customPreBuildArgs sudo unshare -n"
fi
if [[ '${{ parameters.enablePoison }}' == 'True' ]]; then
Expand Down Expand Up @@ -402,31 +424,12 @@ jobs:
buildArgs="$(additionalBuildArgs) $customBuildArgs $extraBuildProperties"
# Only use Docker when a container is specified
if [[ -n "${{ parameters.container }}" ]]; then
# Allows Arcade to have access to the commit for the build, pass it through to the container
customEnvVars="$customEnvVars BUILD_SOURCEVERSION=$BUILD_SOURCEVERSION"
customEnvVars="$customEnvVars BUILD_BUILDNUMBER=$(Build.BuildNumber)"
customDockerRunArgs=""
for envVar in $customEnvVars; do
customDockerRunArgs="$customDockerRunArgs -e $envVar"
done
if [[ '${{ parameters.runOnline }}' == 'False' ]]; then
customDockerRunArgs="$customDockerRunArgs --network none"
fi
docker run --rm -v "$(sourcesPath):/vmr" -w /vmr $customDockerRunArgs ${{ parameters.container }} ./build.sh $buildArgs
else
for envVar in $customEnvVars; do
customEnvVarsWithBashSyntax="$customEnvVarsWithBashSyntax export $envVar;"
done
cd $(sourcesPath)
eval $customEnvVarsWithBashSyntax
./build.sh $buildArgs
fi
for envVar in $customEnvVars; do
customEnvVarsWithBashSyntax="$customEnvVarsWithBashSyntax export $envVar;"
done
cd $(sourcesPath)
eval $customEnvVarsWithBashSyntax
$customPreBuildArgs ./build.sh $buildArgs
displayName: Build
# Only run tests if enabled
Expand Down Expand Up @@ -481,13 +484,8 @@ jobs:
extraBuildProperties="$extraBuildProperties ${{ parameters.extraProperties }}"
fi
# Only use Docker when a container is specified
if [[ -n "${{ parameters.container }}" ]]; then
docker run --rm $dockerVolumeArgs -w /vmr ${{ parameters.container }} ./build.sh --test --excludeCIBinarylog /bl:artifacts/log/Release/Test.binlog $customBuildArgs $extraBuildProperties $(additionalBuildArgs)
else
cd $(sourcesPath)
./build.sh --test --excludeCIBinarylog /bl:artifacts/log/Release/Test.binlog $customBuildArgs $extraBuildProperties $(additionalBuildArgs)
fi
cd $(sourcesPath)
./build.sh --test --excludeCIBinarylog /bl:artifacts/log/Release/Test.binlog $customBuildArgs $extraBuildProperties $(additionalBuildArgs)
displayName: Run Tests
timeoutInMinutes: ${{ variables.runTestsTimeout }}
Expand Down
Loading

0 comments on commit 76a4881

Please sign in to comment.