From 07f1fc6d932a53fdb85afe98e94d2db99cd8e469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=AF=E6=9C=AC=20=E9=96=8B?= Date: Tue, 25 Jul 2023 05:51:45 +0000 Subject: [PATCH] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 133 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 107 insertions(+), 26 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e88c779..cab0fbb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,35 +1,116 @@ -# 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: tags: include: - stage-* -pool: - vmImage: ubuntu-latest - jobs: -- job: Build - pool: +- job: Job_1 + displayName: Dictation App Service Deploy + pool: vmImage: ubuntu-latest steps: - checkout: self - - 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 - displayName: 'タグが付けられたCommitがdevelopブランチに存在するか確認' - - script: echo Checked out $(Build.SourceVersion) tagged with $(Build.SourceBranch) - 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 Build" + 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-dev' + enabled: False + inputs: + ConnectedServiceName: 82047c72-0cfe-43b0-bb2f-cdfd8b165e68 + KeyVaultName: kv-odms-secret-dev + - task: Bash@3 + displayName: Bash Script (Test) + inputs: + targetType: inline + filePath: cd dictation_server && JWT_PUBLIC_KEY="$JWT_PUBLIC_KEY" && npm run test + script: cd dictation_server && npm run test + - task: Docker@0 + displayName: build + inputs: + azureSubscriptionEndpoint: 827be338-1846-4102-b006-f457c92883d3 + azureContainerRegistry: '{"loginServer":"crodmsregistrymaintenance.azurecr.io", "id" : "/subscriptions/108fb131-cdca-4729-a2be-e5bd8c0b3ba7/resourceGroups/maintenance-rg/providers/Microsoft.ContainerRegistry/registries/crOdmsRegistryMaintenance"}' + dockerFile: DockerfileServerDictation.dockerfile + imageName: $(Build.Repository.Name)/dictation:latest + - task: Docker@0 + displayName: Push + inputs: + azureSubscriptionEndpoint: 827be338-1846-4102-b006-f457c92883d3 + 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: $(Build.Repository.Name)/dictation:latest +- job: Job_2 + displayName: Dictation Static App Service Deploy + pool: + vmImage: ubuntu-latest + 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 + - task: AzureStaticWebApp@0 + displayName: 'Static Web App: ' + inputs: + app_location: /dictation_client/build + 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: Job_3 + displayName: DB migration + dependsOn: + - Job_1 + - Job_2 + pool: + name: db-migrate-pipelines + steps: + - checkout: self + clean: true + fetchDepth: 1 + - task: GoTool@0 + displayName: Use Go 1.18 + inputs: + version: 1.18 + - task: Go@0 + displayName: go install + inputs: + command: custom + customCommand: install + arguments: github.com/rubenv/sql-migrate/sql-migrate@latest + - task: AzureKeyVault@2 + displayName: 'Azure Key Vault: kv-odms-secret-dev' + inputs: + ConnectedServiceName: 82047c72-0cfe-43b0-bb2f-cdfd8b165e68 + KeyVaultName: kv-odms-secret-dev + - task: CmdLine@2 + displayName: migration + inputs: + script: >2 + # DB接続情報書き換え + sed -i -e "s/DB_NAME/$(db-name)/g" ./dictation_server/db/dbconfig.yml + sed -i -e "s/DB_PASS/$(db-pass)/g" ./dictation_server/db/dbconfig.yml + sed -i -e "s/DB_USERNAME/$(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 + /home/azureuser/go/bin/sql-migrate --version + cat ./dictation_server/db/dbconfig.yml + # migration実行 + /home/azureuser/go/bin/sql-migrate up -config=dictation_server/db/dbconfig.yml -env=ci +...