SQLServerのContainerを起動を待機するgithub Actionsを書く

CIを回す際に永続化レイヤーが欲しくなる問題

業務アプリケーションのServiceやエンドポイントを開発していると、Testの実行時に実際の永続化レイヤーへの接続が欲しくなる。

github.com

name: .NET CI

on:
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest

    services:
      mssql-kashilog:
        image: ghcr.io/creatiovitae/kashilogdb:2023-11.14
        ports:
          - 1433/tcp
          - 1433:1433
        options: >-
          --health-cmd "/opt/mssql-tools/bin/sqlcmd -U SA -P h0geFuga -Q 'select 1' -b -o /dev/null"
          --health-interval 60s
          --health-timeout 30s
          --health-start-period 20s
          --health-retries 3
    steps:
    - uses: actions/checkout@v4
    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '8.0.x'
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --no-restore --verbosity normal
      env:
        TEST_ENVIRONMENT: Ci

ポイント

  • Container Imageは例によって ghcr.io/creatiovitae/kashilogdb を利用する。
  • Ports1433/tcpを設定する
  • health-cmd"/opt/mssql-tools/bin/sqlcmd -U SA -P h0geFuga -Q 'select 1' -b -o /dev/null" を設定する。今回はCi用の漏れても特に影響のない情報なのでId/passwordを決め打ちにしているが、用途によってはsecretを挿すようにしたほうがいいかもしれない。