hal-tokyo-cello / cello-functions

バック
0 stars 0 forks source link

Azure Functionsの設置 #13

Open reone19 opened 2 years ago

reone19 commented 2 years ago

FunctionsのCI/CD

functions.ymlファイルは完成

npmの設定について

name: functions

# main ブランチに何らかの commit が追加されたら走らせる
on:
  push:
    branches:
      - main

env:
  AZURE_FUNCTIONAPP_NAME: HAL-TH22-IH4C-IW4C-G01-functions01-yoshida # functionsの名前。書き換えてください
  AZURE_FUNCTIONAPP_PACKAGE_PATH: "./" # アップロードするディレクトリ。書き換えてください(現在はルートディレクトリすべてをデプロイしている)
  NODE_VERSION: "16.x" # nodeのバージョンを指定。書き換えてください

jobs:
  functions-build-and-deploy:
    name: Functions-build-and-deploy
    runs-on: ubuntu-latest
    steps:
      - name: Checkout GitHub Action
        uses: actions/checkout@v2

      - name: Setup Node ${{ env.NODE_VERSION }} Environment
        uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Resolve Project Dependencies Using Npm
        shell: bash
        run: |
          pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
          npm install
          npm run build --if-present
          npm run test --if-present
          popd

      - name: Run Azure Functions Action
        uses: Azure/functions-action@v1
        id: fa
        with:
          app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.FUNCTIONS_NAGIDERBY }} # プロファイラを登録したNAMEを指定してください

ここの name: Resolve Project Dependencies Using Npm 項目について、バックがどのように開発しているのか分からないので、何を書けばいいのか分かりません。 バックに投げていいですか。

CornerSyrup commented 2 years ago

先にコンフィグを.github/workflowに書き込んでください バックエンドが整うまで、放置しても大丈夫です

来週あたり、バックエンドが1、2個ファンクションを作成したら、 実際動かしてもらい、PRを起こして、マージします

nagi-lc3 commented 2 years ago
name: functions

# main ブランチに何らかの commit が追加されたら走らせる
on:
  push:
    branches:
      - main

env:
  AZURE_FUNCTIONAPP_NAME: HAL-TH22-IH4C-IW4C-G01-functions01-yoshida # functionsの名前。書き換えてください
  AZURE_FUNCTIONAPP_PACKAGE_PATH: "." # アップロードするディレクトリ。書き換えてください(現在はルートディレクトリすべてをデプロイしている)
  NODE_VERSION: "16.x" # nodeのバージョンを指定。書き換えてください

jobs:
  functions-build:
    name: Functions-build
    runs-on: ubuntu-latest
    steps:

      - name: Checkout GitHub Action
        uses: actions/checkout@v2

      - name: Setup Node ${{ env.NODE_VERSION }} Environment
        uses: actions/setup-node@v2
        with:
          node-version: ${{ env.NODE_VERSION }}

      # - name: Resolve Project Dependencies Using Npm
      #   shell: bash
      #   run: |
      #     npm install
      #     npm run build --if-present
      #     npm run test --if-present

  functions-deploy:
    name: Functions-deploy
    runs-on: ubuntu-latest
    steps:

      - name: Run Azure Functions Action
        uses: Azure/functions-action@v1
        id: fa
        with:
          app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.FUNCTIONS_NAGIDERBY }} # プロファイラを登録したNAMEを指定してください

typescript関連でエラーが出るのでBuildはコメントアウト(package.jsonに書けばエラーは治る) actions-test-backでノーエラーで実行されていることを確認(本番環境はまだ作成されていないため) Build部分は追々聞きます。

コンフィグを書き込むとは????

CornerSyrup commented 2 years ago

コメントに込みこまれたコードはworkflowのコンフィグレーション このコードをactions-test-backみたいにdeploy/#13にコミットすること

コミットしたら、もちろん実行できるし、行ごとにコメントもできるし、コードの共有も便利 .gitignoreで除外されてないので、ブランチをチェックアウトすればコミットできます

nagi-lc3 commented 2 years ago

deploy/#13にプッシュしました。

nagi-lc3 commented 2 years ago

ワークフローの変更を行いました。具体的には以下のようなジョブ構成から image

このようなジョブ構成に変更しました。 image

理由としては、ビルドとデプロイが並行して行われている状態で、ビルドが失敗してもデプロイされるようになっていたからです。また、ビルドに含まれていたセットアップ、ビルド、テストの工程を直列に変更することで、視覚的に分かりやすくしました。

詳しくはymlファイルを確認してください。何か意見があればお願いします。

※この変更はフロントとバックで同じ変更を行っています。ビルドが失敗しているのはpackage.jsonの設定を行っていないことが理由なので支障はありません。

追記 上の変更状態だとエラーが出たのでやっぱりSetup, Build, TestはBuildにまとめます。エラーが出ない状態でやる方法もあるけど冗長になってしまうのでこっちの方がいいかなと思います。 image

CornerSyrup commented 2 years ago

更新ありがとうございます

現状で大丈夫です、 必須ではないので、余裕があればキャッシュする方法を検討してください

キャッシュの内容はプロジェクトのルート直下のnode_modulesです、 CI/CDがトリガーするたびに依存性を一からダウンロードするのが嫌なので

Cache - Github Action Marketplace

KzzzDev commented 2 years ago

リソース名

th22ih4ciw4cg01celloFunctions

設定項目


{
    "id": "/subscriptions/a72894b1-d378-4041-9df7-390f238d8814/resourceGroups/HAL-TH22-RG-IH4C-IW4C-G01/providers/Microsoft.Web/sites/th22ih4ciw4cg01celloFunctions",
    "name": "th22ih4ciw4cg01celloFunctions",
    "type": "Microsoft.Web/sites",
    "kind": "functionapp,linux",
    "location": "Japan East",
    "tags": {
        "CELLO": "G01"
    },
    "properties": {
        "name": "th22ih4ciw4cg01celloFunctions",
        "state": "Running",
        "hostNames": [
            "th22ih4ciw4cg01cellofunctions.azurewebsites.net"
        ],
        "webSpace": "HAL-TH22-RG-IH4C-IW4C-G01-JapanEastwebspace-Linux",
        "selfLink": "https://waws-prod-ty1-021.api.azurewebsites.windows.net:454/subscriptions/a72894b1-d378-4041-9df7-390f238d8814/webspaces/HAL-TH22-RG-IH4C-IW4C-G01-JapanEastwebspace-Linux/sites/th22ih4ciw4cg01celloFunctions",
        "repositorySiteName": "th22ih4ciw4cg01celloFunctions",
        "owner": null,
        "usageState": 0,
        "enabled": true,
        "adminEnabled": true,
        "enabledHostNames": [
            "th22ih4ciw4cg01cellofunctions.azurewebsites.net",
            "th22ih4ciw4cg01cellofunctions.scm.azurewebsites.net"
        ],
        "siteProperties": {
            "metadata": null,
            "properties": [
                {
                    "name": "LinuxFxVersion",
                    "value": "Node|16"
                },
                {
                    "name": "WindowsFxVersion",
                    "value": null
                }
            ],
            "appSettings": null
        },
        "availabilityState": 0,
        "sslCertificates": null,
        "csrs": [],
        "cers": null,
        "siteMode": null,
        "hostNameSslStates": [
            {
                "name": "th22ih4ciw4cg01cellofunctions.azurewebsites.net",
                "sslState": 0,
                "ipBasedSslResult": null,
                "virtualIP": null,
                "thumbprint": null,
                "toUpdate": null,
                "toUpdateIpBasedSsl": null,
                "ipBasedSslState": 0,
                "hostType": 0
            },
            {
                "name": "th22ih4ciw4cg01cellofunctions.scm.azurewebsites.net",
                "sslState": 0,
                "ipBasedSslResult": null,
                "virtualIP": null,
                "thumbprint": null,
                "toUpdate": null,
                "toUpdateIpBasedSsl": null,
                "ipBasedSslState": 0,
                "hostType": 1
            }
        ],
        "computeMode": null,
        "serverFarm": null,
        "serverFarmId": "/subscriptions/a72894b1-d378-4041-9df7-390f238d8814/resourceGroups/HAL-TH22-RG-IH4C-IW4C-G01/providers/Microsoft.Web/serverfarms/ASP-HALTH22RGIH4CIW4CG01-a393",
        "reserved": true,
        "isXenon": false,
        "hyperV": false,
        "lastModifiedTimeUtc": "2022-06-28T06:37:24.98",
        "storageRecoveryDefaultState": "Running",
        "contentAvailabilityState": 0,
        "runtimeAvailabilityState": 0,
        "vnetRouteAllEnabled": false,
        "siteConfig": {
            "numberOfWorkers": 1,
            "defaultDocuments": null,
            "netFrameworkVersion": null,
            "phpVersion": null,
            "pythonVersion": null,
            "nodeVersion": null,
            "powerShellVersion": null,
            "linuxFxVersion": "Node|16",
            "windowsFxVersion": null,
            "requestTracingEnabled": null,
            "remoteDebuggingEnabled": null,
            "remoteDebuggingVersion": null,
            "httpLoggingEnabled": null,
            "azureMonitorLogCategories": null,
            "acrUseManagedIdentityCreds": false,
            "acrUserManagedIdentityID": null,
            "logsDirectorySizeLimit": null,
            "detailedErrorLoggingEnabled": null,
            "publishingUsername": null,
            "publishingPassword": null,
            "appSettings": null,
            "metadata": null,
            "connectionStrings": null,
            "machineKey": null,
            "handlerMappings": null,
            "documentRoot": null,
            "scmType": null,
            "use32BitWorkerProcess": null,
            "webSocketsEnabled": null,
            "alwaysOn": false,
            "javaVersion": null,
            "javaContainer": null,
            "javaContainerVersion": null,
            "appCommandLine": null,
            "managedPipelineMode": null,
            "virtualApplications": null,
            "winAuthAdminState": null,
            "winAuthTenantState": null,
            "customAppPoolIdentityAdminState": null,
            "customAppPoolIdentityTenantState": null,
            "runtimeADUser": null,
            "runtimeADUserPassword": null,
            "loadBalancing": null,
            "routingRules": null,
            "experiments": null,
            "limits": null,
            "autoHealEnabled": null,
            "autoHealRules": null,
            "tracingOptions": null,
            "vnetName": null,
            "vnetRouteAllEnabled": null,
            "vnetPrivatePortsCount": null,
            "publicNetworkAccess": null,
            "cors": null,
            "push": null,
            "apiDefinition": null,
            "apiManagementConfig": null,
            "autoSwapSlotName": null,
            "localMySqlEnabled": null,
            "managedServiceIdentityId": null,
            "xManagedServiceIdentityId": null,
            "keyVaultReferenceIdentity": null,
            "ipSecurityRestrictions": null,
            "scmIpSecurityRestrictions": null,
            "scmIpSecurityRestrictionsUseMain": null,
            "http20Enabled": false,
            "minTlsVersion": null,
            "minTlsCipherSuite": null,
            "supportedTlsCipherSuites": null,
            "scmMinTlsVersion": null,
            "ftpsState": null,
            "preWarmedInstanceCount": null,
            "functionAppScaleLimit": 200,
            "healthCheckPath": null,
            "fileChangeAuditEnabled": null,
            "functionsRuntimeScaleMonitoringEnabled": null,
            "websiteTimeZone": null,
            "minimumElasticInstanceCount": 0,
            "azureStorageAccounts": null,
            "http20ProxyFlag": null,
            "sitePort": null,
            "antivirusScanEnabled": null,
            "storageType": null
        },
        "deploymentId": "th22ih4ciw4cg01celloFunctions",
        "slotName": null,
        "trafficManagerHostNames": null,
        "sku": "Dynamic",
        "scmSiteAlsoStopped": false,
        "targetSwapSlot": null,
        "hostingEnvironment": null,
        "hostingEnvironmentProfile": null,
        "clientAffinityEnabled": false,
        "clientCertEnabled": false,
        "clientCertMode": 0,
        "clientCertExclusionPaths": null,
        "hostNamesDisabled": false,
        "domainVerificationIdentifiers": null,
        "customDomainVerificationId": "4F20A7E13A24AA2C5EEFF61C9E670F4E007481FFA2837C511C84018BCB4287C1",
        "kind": "functionapp,linux",
        "inboundIpAddress": "40.79.195.0",
        "possibleInboundIpAddresses": "40.79.195.0",
        "ftpUsername": "th22ih4ciw4cg01celloFunctions\\$th22ih4ciw4cg01celloFunctions",
        "ftpsHostName": "ftps://waws-prod-ty1-021.ftp.azurewebsites.windows.net/site/wwwroot",
        "outboundIpAddresses": "40.79.195.0,13.78.114.158,40.115.166.91,52.185.171.44,20.37.98.11",
        "possibleOutboundIpAddresses": "40.79.195.0,13.78.114.158,40.115.166.91,52.185.171.44,20.37.98.11,13.78.117.54,13.78.116.92,13.78.119.6,13.78.117.38,13.78.116.142",
        "containerSize": 1536,
        "dailyMemoryTimeQuota": 0,
        "suspendedTill": null,
        "siteDisabledReason": 0,
        "functionExecutionUnitsCache": null,
        "maxNumberOfWorkers": null,
        "homeStamp": "waws-prod-ty1-021",
        "cloningInfo": null,
        "hostingEnvironmentId": null,
        "tags": {
            "CELLO": "G01"
        },
        "resourceGroup": "HAL-TH22-RG-IH4C-IW4C-G01",
        "defaultHostName": "th22ih4ciw4cg01cellofunctions.azurewebsites.net",
        "slotSwapStatus": null,
        "httpsOnly": false,
        "redundancyMode": 0,
        "inProgressOperationId": null,
        "geoDistributions": null,
        "privateEndpointConnections": [],
        "publicNetworkAccess": null,
        "buildVersion": null,
        "targetBuildVersion": null,
        "migrationState": null,
        "eligibleLogCategories": "FunctionAppLogs",
        "storageAccountRequired": false,
        "virtualNetworkSubnetId": null,
        "keyVaultReferenceIdentity": "SystemAssigned"
    }
}