488 lines
17 KiB
YAML
488 lines
17 KiB
YAML
# Pipeline側でKeyVaultやDocker、AppService等に対する操作権限を持ったServiceConenctionを作成しておくこと
|
|
# また、環境変数 STATIC_DICTATION_DEPLOYMENT_TOKEN の値として静的WebAppsのデプロイトークンを設定しておくこと
|
|
trigger:
|
|
branches:
|
|
include:
|
|
- release-ph2
|
|
tags:
|
|
include:
|
|
- stage-*
|
|
|
|
# Job 1 : Initialize
|
|
jobs:
|
|
- job: initialize
|
|
displayName: Initialize
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
persistCredentials: true
|
|
- script: |
|
|
git fetch origin release-ph2:release-ph2
|
|
if git merge-base --is-ancestor $(Build.SourceVersion) release-ph2; then
|
|
echo "Commit is in the release-ph2 branch."
|
|
else
|
|
echo "Commit is not in the release-ph2 branch."
|
|
exit 1
|
|
fi
|
|
displayName: 'タグが付けられたCommitがrelease-ph2ブランチに存在するか確認'
|
|
|
|
# Job 2 : Backend Test
|
|
- job: backend_test
|
|
dependsOn: initialize
|
|
condition: succeeded('initialize')
|
|
displayName: Unit Test Backend
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Bash@3
|
|
displayName: Bash Script (Backend Unit Tests)
|
|
inputs:
|
|
targetType: inline
|
|
workingDirectory: dictation_server/.devcontainer
|
|
script: |
|
|
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
sudo chmod +x /usr/local/bin/docker-compose
|
|
docker-compose --version
|
|
docker-compose -f pipeline-docker-compose.yml build
|
|
docker-compose -f pipeline-docker-compose.yml up -d
|
|
docker-compose exec -T dictation_server sudo npm ci
|
|
docker-compose exec -T dictation_server sudo npm run migrate:up:test
|
|
docker-compose exec -T dictation_server sudo npm run test
|
|
|
|
# Job 3 : Backend Build & Push
|
|
- job: backend_build
|
|
dependsOn: backend_test
|
|
condition: succeeded('backend_test')
|
|
displayName: Build and Push Backend Image
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Npm@1
|
|
displayName: npm ci
|
|
inputs:
|
|
command: ci
|
|
workingDir: dictation_server
|
|
verbose: false
|
|
- task: Docker@0
|
|
displayName: Build Backend Image
|
|
inputs:
|
|
azureSubscriptionEndpoint: 'omds-service-connection-stg'
|
|
azureContainerRegistry: '{"loginServer":"crodmsregistrymaintenance.azurecr.io", "id" : "/subscriptions/108fb131-cdca-4729-a2be-e5bd8c0b3ba7/resourceGroups/maintenance-rg/providers/Microsoft.ContainerRegistry/registries/crOdmsRegistryMaintenance"}'
|
|
dockerFile: DockerfileServerDictation.dockerfile
|
|
imageName: odmscloud/staging/dictation:$(Build.SourceVersion)
|
|
buildArguments: |
|
|
BUILD_VERSION=$(Build.SourceVersion)
|
|
- task: Docker@0
|
|
displayName: Push Backend Image
|
|
inputs:
|
|
azureSubscriptionEndpoint: 'omds-service-connection-stg'
|
|
azureContainerRegistry: '{"loginServer":"crodmsregistrymaintenance.azurecr.io", "id" : "/subscriptions/108fb131-cdca-4729-a2be-e5bd8c0b3ba7/resourceGroups/maintenance-rg/providers/Microsoft.ContainerRegistry/registries/crOdmsRegistryMaintenance"}'
|
|
action: Push an image
|
|
imageName: odmscloud/staging/dictation:$(Build.SourceVersion)
|
|
|
|
# Job 4 : Frontend Staging Build
|
|
- job: frontend_build_staging
|
|
dependsOn: backend_build
|
|
condition: succeeded('backend_build')
|
|
displayName: Build Frontend Files(staging)
|
|
variables:
|
|
storageAccountName: saomdspipeline
|
|
environment: staging
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Npm@1
|
|
displayName: npm ci
|
|
inputs:
|
|
command: ci
|
|
workingDir: dictation_client
|
|
verbose: false
|
|
- task: Bash@3
|
|
displayName: Bash Script
|
|
inputs:
|
|
targetType: inline
|
|
script: cd dictation_client && npm run build:stg
|
|
- task: ArchiveFiles@2
|
|
inputs:
|
|
rootFolderOrFile: dictation_client/build
|
|
includeRootFolder: false
|
|
archiveType: 'zip'
|
|
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.SourceVersion).zip'
|
|
replaceExistingArchive: true
|
|
- task: AzureCLI@2
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
scriptType: 'bash'
|
|
scriptLocation: 'inlineScript'
|
|
inlineScript: |
|
|
az storage blob upload \
|
|
--auth-mode login \
|
|
--account-name $(storageAccountName) \
|
|
--container-name $(environment) \
|
|
--name $(Build.SourceVersion).zip \
|
|
--type block \
|
|
--overwrite \
|
|
--file $(Build.ArtifactStagingDirectory)/$(Build.SourceVersion).zip
|
|
|
|
# Job 5 : Frontend Production Build
|
|
- job: frontend_build_production
|
|
dependsOn: frontend_build_staging
|
|
condition: succeeded('frontend_build_staging')
|
|
displayName: Build Frontend Files(production)
|
|
variables:
|
|
storageAccountName: saomdspipeline
|
|
environment: production
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Npm@1
|
|
displayName: npm ci
|
|
inputs:
|
|
command: ci
|
|
workingDir: dictation_client
|
|
verbose: false
|
|
- task: Bash@3
|
|
displayName: Bash Script
|
|
inputs:
|
|
targetType: inline
|
|
script: cd dictation_client && npm run build:prod
|
|
- task: ArchiveFiles@2
|
|
inputs:
|
|
rootFolderOrFile: dictation_client/build
|
|
includeRootFolder: false
|
|
archiveType: 'zip'
|
|
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.SourceVersion).zip'
|
|
replaceExistingArchive: true
|
|
- task: AzureCLI@2
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
scriptType: 'bash'
|
|
scriptLocation: 'inlineScript'
|
|
inlineScript: |
|
|
az storage blob upload \
|
|
--auth-mode login \
|
|
--account-name $(storageAccountName) \
|
|
--container-name $(environment) \
|
|
--name $(Build.SourceVersion).zip \
|
|
--type block \
|
|
--overwrite \
|
|
--file $(Build.ArtifactStagingDirectory)/$(Build.SourceVersion).zip
|
|
|
|
# Job 6 : Function Unit Test
|
|
- job: function_test
|
|
dependsOn: frontend_build_production
|
|
condition: succeeded('frontend_build_production')
|
|
displayName: Unit Test Function
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Bash@3
|
|
displayName: Bash Script (Test)
|
|
inputs:
|
|
targetType: inline
|
|
workingDirectory: dictation_function/.devcontainer
|
|
script: |
|
|
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
sudo chmod +x /usr/local/bin/docker-compose
|
|
docker-compose --version
|
|
docker-compose -f pipeline-docker-compose.yml build
|
|
docker-compose -f pipeline-docker-compose.yml up -d
|
|
docker-compose exec -T dictation_function sudo npm ci
|
|
docker-compose exec -T dictation_function sudo npm run test
|
|
|
|
# Job 7 : Function Build & Push
|
|
- job: function_build
|
|
dependsOn: function_test
|
|
condition: succeeded('function_test')
|
|
displayName: Build And Push Function Image
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Npm@1
|
|
displayName: npm ci
|
|
inputs:
|
|
command: ci
|
|
workingDir: dictation_function
|
|
verbose: false
|
|
- task: Docker@0
|
|
displayName: build
|
|
inputs:
|
|
azureSubscriptionEndpoint: 'omds-service-connection-stg'
|
|
azureContainerRegistry: '{"loginServer":"crodmsregistrymaintenance.azurecr.io", "id" : "/subscriptions/108fb131-cdca-4729-a2be-e5bd8c0b3ba7/resourceGroups/maintenance-rg/providers/Microsoft.ContainerRegistry/registries/crOdmsRegistryMaintenance"}'
|
|
dockerFile: DockerfileFunctionDictation.dockerfile
|
|
imageName: odmscloud/staging/dictation_function:$(Build.SourceVersion)
|
|
buildArguments: |
|
|
BUILD_VERSION=$(Build.SourceVersion)
|
|
- task: Docker@0
|
|
displayName: push
|
|
inputs:
|
|
azureSubscriptionEndpoint: 'omds-service-connection-stg'
|
|
azureContainerRegistry: '{"loginServer":"crodmsregistrymaintenance.azurecr.io", "id" : "/subscriptions/108fb131-cdca-4729-a2be-e5bd8c0b3ba7/resourceGroups/maintenance-rg/providers/Microsoft.ContainerRegistry/registries/crOdmsRegistryMaintenance"}'
|
|
action: Push an image
|
|
imageName: odmscloud/staging/dictation_function:$(Build.SourceVersion)
|
|
|
|
# Job 8 : Convert Audio File Test
|
|
- job: convert_audio_file_service_test
|
|
dependsOn: function_build
|
|
condition: succeeded('function_build')
|
|
displayName: Unit Test Convert Audio File
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Bash@3
|
|
displayName: Bash Script (Convert Audio File Unit Tests)
|
|
inputs:
|
|
targetType: inline
|
|
workingDirectory: dictation_auto_transcription_file_server/.devcontainer
|
|
script: |
|
|
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
sudo chmod +x /usr/local/bin/docker-compose
|
|
docker-compose --version
|
|
docker-compose -f pipeline-docker-compose.yml build
|
|
docker-compose -f pipeline-docker-compose.yml up -d
|
|
docker-compose exec -T dictation_auto_transcription_file_server sudo npm ci
|
|
docker-compose exec -T dictation_auto_transcription_file_server npm run test
|
|
|
|
# Job 9 : Convert Audio File Build & Push
|
|
- job: convert_audio_file_service_build
|
|
dependsOn: convert_audio_file_service_test
|
|
condition: succeeded('convert_audio_file_service_test')
|
|
displayName: Build and Push Convert Audio File Image
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: Npm@1
|
|
displayName: npm ci
|
|
inputs:
|
|
command: ci
|
|
workingDir: dictation_auto_transcription_file_server
|
|
verbose: false
|
|
- task: Docker@0
|
|
displayName: Build Convert Audio File Image
|
|
inputs:
|
|
azureSubscriptionEndpoint: 'omds-service-connection-stg'
|
|
azureContainerRegistry: '{"loginServer":"crodmsregistrymaintenance.azurecr.io", "id" : "/subscriptions/108fb131-cdca-4729-a2be-e5bd8c0b3ba7/resourceGroups/maintenance-rg/providers/Microsoft.ContainerRegistry/registries/crOdmsRegistryMaintenance"}'
|
|
dockerFile: DockerfileServerAutoTranscription.dockerfile
|
|
imageName: odmscloud/staging/auto_transcription:$(Build.SourceVersion)
|
|
buildArguments: |
|
|
BUILD_VERSION=$(Build.SourceVersion)
|
|
- task: Docker@0
|
|
displayName: Push Convert Audio File Image
|
|
inputs:
|
|
azureSubscriptionEndpoint: 'omds-service-connection-stg'
|
|
azureContainerRegistry: '{"loginServer":"crodmsregistrymaintenance.azurecr.io", "id" : "/subscriptions/108fb131-cdca-4729-a2be-e5bd8c0b3ba7/resourceGroups/maintenance-rg/providers/Microsoft.ContainerRegistry/registries/crOdmsRegistryMaintenance"}'
|
|
action: Push an image
|
|
imageName: odmscloud/staging/auto_transcription:$(Build.SourceVersion)
|
|
|
|
# Job 10 : Backend Deploy
|
|
- job: backend_deploy
|
|
dependsOn: convert_audio_file_service_build
|
|
condition: succeeded('convert_audio_file_service_build')
|
|
displayName: Backend Deploy
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: AzureWebAppContainer@1
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
appName: 'app-odms-dictation-stg'
|
|
deployToSlotOrASE: true
|
|
resourceGroupName: 'stg-application-rg'
|
|
slotName: 'staging'
|
|
containers: 'crodmsregistrymaintenance.azurecr.io/odmscloud/staging/dictation:$(Build.SourceVersion)'
|
|
|
|
# Job 11 : Frontend Deploy
|
|
- job: frontend_deploy
|
|
dependsOn: backend_deploy
|
|
condition: succeeded('backend_deploy')
|
|
displayName: Deploy Frontend Files
|
|
variables:
|
|
storageAccountName: saomdspipeline
|
|
environment: staging
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: AzureCLI@2
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
scriptType: 'bash'
|
|
scriptLocation: 'inlineScript'
|
|
inlineScript: |
|
|
az storage blob download \
|
|
--auth-mode login \
|
|
--account-name $(storageAccountName) \
|
|
--container-name $(environment) \
|
|
--name $(Build.SourceVersion).zip \
|
|
--file $(Build.SourcesDirectory)/$(Build.SourceVersion).zip
|
|
- task: Bash@3
|
|
displayName: Bash Script
|
|
inputs:
|
|
targetType: inline
|
|
script: unzip $(Build.SourcesDirectory)/$(Build.SourceVersion).zip -d $(Build.SourcesDirectory)/$(Build.SourceVersion)
|
|
- task: AzureStaticWebApp@0
|
|
displayName: 'Static Web App: '
|
|
inputs:
|
|
workingDirectory: '$(Build.SourcesDirectory)'
|
|
app_location: '/$(Build.SourceVersion)'
|
|
config_file_location: /dictation_client
|
|
skip_app_build: true
|
|
skip_api_build: true
|
|
is_static_export: false
|
|
verbose: false
|
|
azure_static_web_apps_api_token: $(STATIC_DICTATION_DEPLOYMENT_TOKEN)
|
|
|
|
# Job 12 : Function Deploy
|
|
- job: function_deploy
|
|
dependsOn: frontend_deploy
|
|
condition: succeeded('frontend_deploy')
|
|
displayName: Function Deploy
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: AzureFunctionAppContainer@1
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
appName: 'func-odms-dictation-stg'
|
|
imageName: 'crodmsregistrymaintenance.azurecr.io/odmscloud/staging/dictation_function:$(Build.SourceVersion)'
|
|
|
|
# Job 13 : Convert Audio File Deploy
|
|
- job: convert_audio_file_service_deploy
|
|
dependsOn: function_deploy
|
|
condition: succeeded('function_deploy')
|
|
displayName: Convert Audio File Deploy
|
|
pool:
|
|
vmImage: ubuntu-latest
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: AzureWebAppContainer@1
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
appName: 'app-odms-convert-audio-stg'
|
|
deployToSlotOrASE: true
|
|
resourceGroupName: 'stg-application-rg'
|
|
slotName: 'staging'
|
|
containers: 'crodmsregistrymaintenance.azurecr.io/odmscloud/staging/auto_transcription:$(Build.SourceVersion)'
|
|
|
|
# Job 14 : Smoke Test
|
|
- job: smoke_test
|
|
dependsOn: convert_audio_file_service_deploy
|
|
condition: succeeded('convert_audio_file_service_deploy')
|
|
displayName: 'smoke test'
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
# スモークテスト用にjobを確保
|
|
|
|
# Job 15 : Backend Slot Swap
|
|
- job: backend_swap_slot
|
|
dependsOn: smoke_test
|
|
condition: succeeded('smoke_test')
|
|
displayName: 'Swap Backend Staging and Production'
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: AzureAppServiceManage@0
|
|
displayName: 'Azure App Service Manage: app-odms-dictation-stg'
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
action: 'Swap Slots'
|
|
WebAppName: 'app-odms-dictation-stg'
|
|
ResourceGroupName: 'stg-application-rg'
|
|
SourceSlot: 'staging'
|
|
SwapWithProduction: true
|
|
|
|
# Job 16 : Convert Audio File Slot Swap
|
|
- job: convert_audio_file_swap_slot
|
|
dependsOn: backend_swap_slot
|
|
condition: succeeded('backend_swap_slot')
|
|
displayName: 'Swap Convert Audio File Staging and Production'
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: AzureAppServiceManage@0
|
|
displayName: 'Azure App Service Manage: app-odms-convert-audio-stg'
|
|
inputs:
|
|
azureSubscription: 'omds-service-connection-stg'
|
|
action: 'Swap Slots'
|
|
WebAppName: 'app-odms-convert-audio-stg'
|
|
ResourceGroupName: 'stg-application-rg'
|
|
SourceSlot: 'staging'
|
|
SwapWithProduction: true
|
|
|
|
# Job 17 : DB migration
|
|
- job: migration
|
|
dependsOn: convert_audio_file_swap_slot
|
|
condition: succeeded('convert_audio_file_swap_slot')
|
|
displayName: DB migration
|
|
pool:
|
|
name: odms-deploy-pipeline
|
|
steps:
|
|
- checkout: self
|
|
clean: true
|
|
fetchDepth: 1
|
|
- task: AzureKeyVault@2
|
|
displayName: 'Azure Key Vault: kv-odms-secret-stg'
|
|
inputs:
|
|
ConnectedServiceName: 'omds-service-connection-stg'
|
|
KeyVaultName: kv-odms-secret-stg
|
|
- task: CmdLine@2
|
|
displayName: migration
|
|
inputs:
|
|
script: >2
|
|
# DB接続情報書き換え
|
|
sed -i -e "s/DB_NAME/$(db-name-ph2)/g" ./dictation_server/db/dbconfig.yml
|
|
sed -i -e "s/DB_PASS/$(admin-db-pass)/g" ./dictation_server/db/dbconfig.yml
|
|
sed -i -e "s/DB_USERNAME/$(admin-db-user)/g" ./dictation_server/db/dbconfig.yml
|
|
sed -i -e "s/DB_PORT/$(db-port)/g" ./dictation_server/db/dbconfig.yml
|
|
sed -i -e "s/DB_HOST/$(db-host)/g" ./dictation_server/db/dbconfig.yml
|
|
sql-migrate --version
|
|
cat ./dictation_server/db/dbconfig.yml
|
|
# migration実行
|
|
sql-migrate up -config=./dictation_server/db/dbconfig.yml -env=ci |