Skip to content

Commit

Permalink
Merge pull request #64 from JFolberth/feature/cicd_sql
Browse files Browse the repository at this point in the history
Feature/cicd sql
  • Loading branch information
JFolberth authored Dec 4, 2024
2 parents 2181adc + 1d6503b commit 69a23eb
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 27 deletions.
23 changes: 21 additions & 2 deletions jobs/dacpac_deploy_env_job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,34 @@ jobs:
- template: ../variables/azure_global_variables.yml
- name: deploymentName
value: '${{ parameters.serviceName }}_app_deploy_${{ parameters.environmentName }}_${{ parameters.regionAbrv }}'
- name: sqlServerName
value: '${{ variables.sqlServerAbrv }}-${{ parameters.sqlServerName }}-${{ parameters.environmentName }}-${{ parameters.regionAbrv }}${{ variables.sqlServerURLSuffix }}'
- name: sqlDatabaseName
value: '${{ variables.sqlServerAbrv }}${{ parameters.sqlDatabaseName }}'
strategy:
runOnce:
deploy:
steps:
- template: ../tasks/dacpac_dacpac_deploy_task.yml
parameters:
azureSubscription: ${{ variables.azureServiceConnectionName }}
sqlServerName: '${{ variables.sqlServerAbrv }}-${{ parameters.sqlServerName }}-${{ parameters.environmentName }}-${{ parameters.regionAbrv }}${{ variables.sqlServerURLSuffix }}'
sqlDatabaseName: '${{ variables.sqlServerAbrv }}${{ parameters.sqlDatabaseName }}'
sqlServerName: ${{ variables.sqlServerName }}
sqlDatabaseName: ${{ variables.sqlDatabaseName }}
authenticationType: ${{ parameters.authenticationType }}
ipDetectionMethod: ${{ parameters.ipDetectionMethod }}
dacpacFilePath: '${{ parameters.dacpacFilePath }}'
deploymentAction: 'DeployReport'
deleteFirewallRule: false
- template: ../tasks/ado_copy_files_task.yml
parameters:
# $SqlDeploymentOutputFile is defined in https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/SqlAzureDacpacDeploymentV1/SqlAzureActions.ps1 since output path is hardcoded
sourceFolder: 'GeneratedOutputFiles'
targetFolder: 'postDeploy/${{ variables.sqlServerName }}/${{ variables.sqlDatabaseName }}'
- template: ../tasks/dacpac_dacpac_deploy_task.yml
parameters:
azureSubscription: ${{ variables.azureServiceConnectionName }}
sqlServerName: ${{ variables.sqlServerName }}
sqlDatabaseName: ${{ variables.sqlDatabaseName }}
authenticationType: ${{ parameters.authenticationType }}
ipDetectionMethod: ${{ parameters.ipDetectionMethod }}
dacpacFilePath: '${{ parameters.dacpacFilePath }}'
Expand Down
54 changes: 44 additions & 10 deletions jobs/dotnetcore_sql_build_publish_job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,37 @@ parameters:
startUpProjectName: ''
projectExtension: '.sqlproj'
buildArguments: ''
sqlServerName: ''
sqlDatabaseName: ''
regionAbrvs: ['cus']
authenticationType: 'servicePrincipal'
ipDetectionMethod: 'AutoDetect'
dacpacAdditionalArguments: ''

jobs:
- job: build_publish_sql_${{parameters.projectName}}_${{ parameters.buildConfiguration }}_${{ parameters.environmentName }}
variables:
srcFilePath: 'src'
projectName: ${{replace(parameters.projectName,'_','.')}}
${{ if eq(parameters.solutionName, '')}} :
projectPath: '$(Build.SourcesDirectory)/${{ variables.srcFilePath }}/${{ variables.projectName }}'
testProjectPath: '$(Build.SourcesDirectory)/${{ variables.srcFilePath }}/${{ variables.projectName }}'
startUpProjectPath: '$(Build.SourcesDirectory)/${{ variables.srcFilePath }}/${{ parameters.startUpProjectName }}'
${{ else }} :
projectPath: '$(Build.SourcesDirectory)/${{ parameters.solutionName }}/${{ variables.srcFilePath }}/${{ variables.projectName }}'
testProjectPath: '$(Build.SourcesDirectory)/${{ parameters.solutionName }}/${{ variables.srcFilePath }}/${{ variables.projectName }}'
startUpProjectPath: '$(Build.SourcesDirectory)/${{ parameters.solutionName }}/${{ variables.srcFilePath }}/${{ parameters.startUpProjectName }}'
- template: ../variables/azure_${{parameters.environmentName}}_variables.yml
- template: ../variables/azure_global_variables.yml
- name: srcFilePath
value: 'src'
- name: projectName
value: ${{replace(parameters.projectName,'_','.')}}
- ${{ if eq(parameters.solutionName, '')}} :
- name: projectPathBase
value: '${{ variables.srcFilePath }}/${{ variables.projectName }}'
- name: startUpProjectPathBase
value: '${{ variables.srcFilePath }}/${{ parameters.startUpProjectName }}'
- ${{ else }} :
- name: projectPathBase
value: '${{ parameters.solutionName }}/${{ variables.srcFilePath }}/${{ variables.projectName }}'
- name: startUpProjectPathBase
value: '${{ parameters.solutionName }}/${{ variables.srcFilePath }}/${{ parameters.startUpProjectName }}'
- name: projectPath
value: '$(Build.SourcesDirectory)/${{ variables.projectPathBase }}'
- name: startUpProjectPath
value: '$(Build.SourcesDirectory)/${{ variables.startUpProjectPathBase }}'

steps:
- template: ../tasks/dotnet_sdk_task.yml
parameters:
Expand All @@ -35,7 +52,24 @@ jobs:
command: 'build'
projectPath: '${{ variables.projectPath }}/*${{ parameters.projectExtension }}'
arguments: '--configuration ${{ parameters.buildConfiguration }} ${{ parameters.buildArguments }}'

- ${{ each regionAbrv in parameters.regionAbrvs }} :
- template: ../tasks/dacpac_dacpac_deploy_task.yml
parameters:
azureSubscription: ${{ variables.azureServiceConnectionName }}
sqlServerName: '${{ variables.sqlServerAbrv }}-${{ parameters.sqlServerName }}-${{ parameters.environmentName }}-${{ regionAbrv }}${{ variables.sqlServerURLSuffix }}'
sqlDatabaseName: '${{ variables.sqlServerAbrv }}${{ parameters.sqlDatabaseName }}'
authenticationType: ${{ parameters.authenticationType }}
ipDetectionMethod: ${{ parameters.ipDetectionMethod }}
dacpacFilePath: 's/${{variables. projectPathBase }}/bin/${{ parameters.buildConfiguration }}/${{ parameters.projectName }}.dacpac'
deploymentAction: 'DeployReport'
- template: ../tasks/ado_copy_files_task.yml
parameters:
# $SqlDeploymentOutputFile is defined in https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/SqlAzureDacpacDeploymentV1/SqlAzureActions.ps1 since output path is hardcoded
sourceFolder: 'GeneratedOutputFiles'
targetFolder: '${{ variables.projectPath }}/bin/${{ parameters.buildConfiguration }}/${{ regionAbrv }}'
- template: ../tasks/ado_publish_pipeline_task.yml
parameters:
artifactName: '${{ parameters.projectName }}_${{ parameters.buildConfiguration }}_${{ parameters.environmentName }}'
targetPath: '${{ variables.projectPath }}/bin/${{ parameters.buildConfiguration }}'

37 changes: 22 additions & 15 deletions stages/dotnet_sql_build_stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parameters:
buildArguments: ''
environmentName: 'dev'
buildConfiguration: 'Release'
regionAbrvs: ['cus']
solutionName: ''
serviceName: ''
sdkVersion: ''
Expand All @@ -27,18 +28,24 @@ stages:
artifactname: ${{ parameters.artifactToPublish }}

- ${{ each projectNamesConfiguration in parameters.projectNamesConfigurations }} :
- template: ../jobs/dotnetcore_sql_build_publish_job.yml
parameters:
solutionName: ${{ parameters.solutionName }}
projectName: ${{replace(projectNamesConfiguration.projectName,'.','_')}}
publishWebProject: ${{ projectNamesConfiguration.publishWebProject }}
sdkVersion: ${{ parameters.sdkVersion }}
dotNetTest: ${{ projectNamesConfiguration.dotnetTest }}
zipAfterPublish: ${{ parameters.zipAppAfterPublish }}
publishArguments: ${{ parameters.publishArguments }}
startUpProjectName: ${{ projectNamesConfiguration.startUpProjectName }}
projectExtension: ${{ projectNamesConfiguration.projectExtension }}
buildArguments: ${{ projectNamesConfiguration.buildArguments }}
environmentName: ${{ projectNamesConfiguration.environmentName }}
buildConfiguration: ${{ projectNamesConfiguration.buildConfiguration }}

- template: ../jobs/dotnetcore_sql_build_publish_job.yml
parameters:
solutionName: ${{ parameters.solutionName }}
projectName: ${{replace(projectNamesConfiguration.projectName,'.','_')}}
publishWebProject: ${{ projectNamesConfiguration.publishWebProject }}
sdkVersion: ${{ parameters.sdkVersion }}
dotNetTest: ${{ projectNamesConfiguration.dotnetTest }}
zipAfterPublish: ${{ parameters.zipAppAfterPublish }}
publishArguments: ${{ parameters.publishArguments }}
startUpProjectName: ${{ projectNamesConfiguration.startUpProjectName }}
projectExtension: ${{ projectNamesConfiguration.projectExtension }}
buildArguments: ${{ projectNamesConfiguration.buildArguments }}
environmentName: ${{ projectNamesConfiguration.environmentName }}
buildConfiguration: ${{ projectNamesConfiguration.buildConfiguration }}
sqlServerName: ${{ projectNamesConfiguration.sqlServerName }}
sqlDatabaseName: ${{ projectNamesConfiguration.sqlDatabaseName }}
regionAbrvs: ${{ projectNamesConfiguration.regionAbrvs }}
authenticationType: ${{ projectNamesConfiguration.authenticationType }}
ipDetectionMethod: ${{ projectNamesConfiguration.ipDetectionMethod }}
dacpacAdditionalArguments: ${{ projectNamesConfiguration.dacpacAdditionalArguments }}

0 comments on commit 69a23eb

Please sign in to comment.