diff --git a/azure-pipelines.yml b/azure-pipelines.yml index af93855..7c2e626 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,19 +1,160 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -trigger: -- develop - -pool: - vmImage: ubuntu-latest - -steps: -- script: echo Hello, world! - displayName: 'Run a one-line script' - -- script: | - echo Add other tasks to build, test, and deploy your project. - echo See https://aka.ms/yaml - displayName: 'Run a multi-line script' +stages: +- stage: __default + jobs: + - job: initialize + displayName: Initialize + pool: + vmImage: ubuntu-latest + steps: + - task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1 + inputs: + repository: self + clean: true + fetchDepth: 1 + persistCredentials: true + - task: CmdLine@2 + displayName: 'タグが付けられたCommitがmainブランチに存在するか確認' + inputs: + script: | + git fetch origin main:main + if git merge-base --is-ancestor $(Build.SourceVersion) main; then + echo "This commit is in the main branch." + else + echo "This commit is not in the main branch." + exit 1 + fi + - job: backend_build + dependsOn: + - initialize + condition: succeeded('initialize') + displayName: Build And Push Backend Image + pool: + name: odms-deploy-pipeline + steps: + - task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1 + inputs: + repository: self + clean: true + fetchDepth: 1 + - task: Npm@1 + displayName: npm ci + inputs: + command: ci + workingDir: dictation_server + verbose: false + - task: AzureKeyVault@2 + displayName: 'Azure Key Vault: kv-odms-secret-stg' + inputs: + ConnectedServiceName: 'omds-service-connection-stg' + KeyVaultName: kv-odms-secret-stg + SecretsFilter: '*' + - task: Bash@3 + displayName: Bash Script (Test) + inputs: + targetType: inline + script: | + cd dictation_server + npm run test + env: + JWT_PUBLIC_KEY: $(token-public-key) + JWT_PRIVATE_KEY: $(token-private-key) + SENDGRID_API_KEY: $(sendgrid-api-key) + NOTIFICATION_HUB_NAME: $(notification-hub-name) + NOTIFICATION_HUB_CONNECT_STRING: $(notification-hub-connect-string) + STORAGE_ACCOUNT_NAME_US: $(storage-account-name-us) + STORAGE_ACCOUNT_NAME_AU: $(storage-account-name-au) + STORAGE_ACCOUNT_NAME_EU: $(storage-account-name-eu) + STORAGE_ACCOUNT_KEY_US: $(storage-account-key-us) + STORAGE_ACCOUNT_KEY_AU: $(storage-account-key-au) + STORAGE_ACCOUNT_KEY_EU: $(storage-account-key-eu) + STORAGE_ACCOUNT_ENDPOINT_US: $(storage-account-endpoint-us) + STORAGE_ACCOUNT_ENDPOINT_AU: $(storage-account-endpoint-au) + STORAGE_ACCOUNT_ENDPOINT_EU: $(storage-account-endpoint-eu) + ADB2C_TENANT_ID: $(adb2c-tenant-id) + ADB2C_CLIENT_ID: $(adb2c-client-id) + ADB2C_CLIENT_SECRET: $(adb2c-client-secret) + MAIL_FROM: xxxxxx + APP_DOMAIN: xxxxxxxxx + EMAIL_CONFIRM_LIFETIME: 0 + TENANT_NAME: xxxxxxxxxxxx + SIGNIN_FLOW_NAME: xxxxxxxxxxxx + STORAGE_TOKEN_EXPIRE_TIME: 0 + REFRESH_TOKEN_LIFETIME_WEB: 86400000 + REFRESH_TOKEN_LIFETIME_DEFAULT: 2592000000 + ACCESS_TOKEN_LIFETIME_WEB: 7200000 + REDIS_HOST: xxxxxxxxxxxx + REDIS_PORT: 0 + REDIS_PASSWORD: xxxxxxxxxxxx + ADB2C_CACHE_TTL: 0 + - 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: DockerfileServerDictation.dockerfile + imageName: odmscloud/staging/dictation:$(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:$(Build.SourceVersion) + - job: backend_deploy + dependsOn: + - backend_build + condition: succeeded('backend_build') + displayName: Backend Deploy + pool: + vmImage: ubuntu-latest + steps: + - task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1 + inputs: + repository: 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: smoke_test + dependsOn: + - backend_deploy + condition: succeeded('backend_deploy') + displayName: 'smoke test' + pool: + name: odms-deploy-pipeline + steps: + - task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1 + inputs: + repository: self + clean: true + fetchDepth: 1 + - job: swap_slot + dependsOn: + - smoke_test + condition: succeeded('smoke_test') + displayName: 'Swap Staging and Production' + pool: + name: odms-deploy-pipeline + steps: + - task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1 + inputs: + repository: 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