Skip to content

Commit

Permalink
Build docker during pr (#3867)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkurepa authored Aug 26, 2024
1 parent 3f0709e commit f51bd3e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 54 deletions.
34 changes: 21 additions & 13 deletions azure-pipelines-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ variables:
value: https://dev.azure.com/dnceng
- name: AzdoProject
value: internal
- name: configuration
value: Release

pr:
branches:
Expand Down Expand Up @@ -64,29 +66,35 @@ stages:
enablePublishUsingPipelines: ${{ variables._PublishUsingPipelines }}

jobs:
- job: Windows_NT
- job: Build
displayName: Build Repo
timeoutInMinutes: 90
pool:
name: NetCore-Public
demands: ImageOverride -equals 1es-windows-2019-open

strategy:
matrix:
debug_configuration:
_BuildConfig: Debug
_PublishType: none
_SignType: test
release_configuration:
_BuildConfig: Release
# PRs or external builds are not signed.
_PublishType: none
_SignType: test
steps:
- checkout: self
clean: true

- template: /eng/templates/steps/build.yml
parameters:
configuration: $(_BuildConfig)
configuration: $(configuration)

- template: /eng/templates/steps/test.yml
parameters:
configuration: $(configuration)

- job: Builder_Docker
displayName: Build Docker Image
pool:
name: NetCore-Public
demands: ImageOverride -equals 1es-ubuntu-2004-open

steps:
- checkout: self
clean: true

- template: /eng/templates/steps/docker-build.yml
parameters:
dockerImageName: test
41 changes: 5 additions & 36 deletions azure-pipelines-product-construction-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,44 +58,13 @@ stages:
steps:
- checkout: self

- powershell: |
Write-Host "Dev branch suffix is $(devBranchSuffix)"
$shortSha = "$(Build.SourceVersion)".Substring(0,10)
$newDockerTag = "$(Build.BuildNumber)-$(System.JobAttempt)-$shortSha$(devBranchSuffix)"
Write-Host "##vso[task.setvariable variable=newDockerImageTag]$newDockerTag"
Write-Host "set newDockerImageTag to $newDockerTag"
displayName: Generate docker image tag
- powershell: >
docker build .
-f $(Build.SourcesDirectory)/src/ProductConstructionService/ProductConstructionService.Api/Dockerfile
-t "$(dockerRegistryUrl)/$(containerName):$(newDockerImageTag)"
displayName: Build docker image
- template: eng/templates/steps/docker-build.yml
parameters:
devBranchSuffix: $(devBranchSuffix)
dockerImageName: $(dockerRegistryUrl)/$(containerName)

- ${{ if notin(variables['Build.Reason'], 'PullRequest') }}:
- task: AzureCLI@2
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az acr login --name $(containerRegistryName)
docker push "$(dockerRegistryUrl)/$(containerName):$(newDockerImageTag)"
displayName: Push docker image

- ${{ if ne(variables['Build.SourceBranch'], 'refs/heads/production') }}:
- task: AzureCLI@2
inputs:
# The Service Connection name needs to be known at compile time, so we can't use a variable for the azure subscription
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
New-Item -ItemType Directory -Path $(diffFolder)
$before = az containerapp show --name $(containerappName) -g $(resourceGroupName) --output json
Set-Content -Path $(diffFolder)/before.json -Value $before
displayName: Snapshot configuration (before)

- task: AzureCLI@2
name: GetAuthInfo
displayName: Get PCS Token
Expand All @@ -118,7 +87,7 @@ stages:
arguments: >
-resourceGroupName $(resourceGroupName)
-containerappName $(containerappName)
-newImageTag $(newDockerImageTag)
-newImageTag $(DockerTag.newDockerImageTag)
-containerRegistryName $(containerRegistryName)
-imageName $(containerName)
-token $(GetAuthInfo.Token)
Expand Down
36 changes: 36 additions & 0 deletions eng/templates/steps/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
parameters:
- name: devBranchSuffix
type: string
default: ''
- name: dockerImageName
type: string

steps:
- powershell: |
Write-Host "Dev branch suffix is ${{ parameters.devBranchSuffix }}"
$shortSha = "$(Build.SourceVersion)".Substring(0,10)
$newDockerTag = "$(Build.BuildNumber)-$(System.JobAttempt)-$shortSha${{ parameters.devBranchSuffix }}"
Write-Host "##vso[task.setvariable variable=newDockerImageTag;isOutput=true]$newDockerTag"
Write-Host "set newDockerImageTag to $newDockerTag"
displayName: Generate docker image tag
name: DockerTag

- powershell: |
mkdir $(Build.SourcesDirectory)/artifacts/log
docker build . `
-f $(Build.SourcesDirectory)/src/ProductConstructionService/ProductConstructionService.Api/Dockerfile `
-t "${{ parameters.dockerImageName }}:$(DockerTag.newDockerImageTag)" `
--progress=plain `
2>&1 | tee $(Build.SourcesDirectory)/artifacts/log/docker-build.log
displayName: Build docker image

- ${{ if notin(variables['Build.Reason'], 'PullRequest') }}:
- task: AzureCLI@2
inputs:
azureSubscription: $(serviceConnectionName)
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az acr login --name $(containerRegistryName)
docker push "$(dockerRegistryUrl)/$(containerName):$(DockerTag.newDockerImageTag)"
displayName: Push docker image
11 changes: 7 additions & 4 deletions eng/templates/steps/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
steps:
parameters:
- name: configuration
type: string

steps:
- task: Powershell@2
displayName: Install SQL Express
inputs:
Expand All @@ -14,12 +17,12 @@ steps:
$(Build.SourcesDirectory)\arcade-services.sln
custom: test
arguments: >
--configuration $(_BuildConfig)
--configuration ${{ parameters.configuration }}
--filter "TestCategory!=PostDeployment&TestCategory!=Nightly&TestCategory!=PreDeployment"
--no-build
--logger "trx;LogFilePrefix=TestResults-"
-v normal
/bl:$(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)/UnitTest.binlog
/bl:$(Build.SourcesDirectory)/artifacts/log/${{ parameters.configuration }}/UnitTest.binlog
--
"RunConfiguration.ResultsDirectory=$(Build.ArtifactStagingDirectory)\TestResults"
RunConfiguration.MapCpuCount=4
Expand All @@ -36,7 +39,7 @@ steps:
searchFolder: $(Build.ArtifactStagingDirectory)\TestResults
testRunTitle: Basic Tests
mergeTestResults: true
configuration: $(_BuildConfig)
configuration: ${{ parameters.configuration }}

- script: echo export const token = ''; > src/environments/token.ts
workingDirectory: $(Build.SourcesDirectory)/src/Maestro/maestro-angular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ COPY ["src/Microsoft.DotNet.Darc/DarcLib/Microsoft.DotNet.DarcLib.csproj", "./Mi
WORKDIR /src/ProductConstructionService
COPY ["src/ProductConstructionService/ProductConstructionService.Api/ProductConstructionService.Api.csproj", "./ProductConstructionService.Api/"]
COPY ["src/ProductConstructionService/ProductConstructionService.Common/ProductConstructionService.Common.csproj", "./ProductConstructionService.Common/"]
COPY ["src/ProductConstructionService/ProductConstructionService.DependencyFlow/ProductConstructionService.DependencyFlow.csproj", "./ProductConstructionService.DependencyFlow/"]
COPY ["src/ProductConstructionService/ProductConstructionService.LongestBuildPathUpdater/ProductConstructionService.LongestBuildPathUpdater.csproj", "./ProductConstructionService.LongestBuildPathUpdater/"]
COPY ["src/ProductConstructionService/ProductConstructionService.ServiceDefaults/ProductConstructionService.ServiceDefaults.csproj", "./ProductConstructionService.ServiceDefaults/"]
COPY ["src/ProductConstructionService/ProductConstructionService.SubscriptionTriggerer/ProductConstructionService.SubscriptionTriggerer.csproj", "./ProductConstructionService.SubscriptionTriggerer/"]
COPY ["src/ProductConstructionService/ProductConstructionService.LongestBuildPathUpdater/ProductConstructionService.LongestBuildPathUpdater.csproj", "./ProductConstructionService.LongestBuildPathUpdater/"]
COPY ["src/ProductConstructionService/ProductConstructionService.WorkItems/ProductConstructionService.WorkItems.csproj", "./ProductConstructionService.WorkItems/"]

RUN dotnet restore "./ProductConstructionService.Api/ProductConstructionService.Api.csproj"
Expand Down

0 comments on commit f51bd3e

Please sign in to comment.