SQLServerのContainerを起動を待機するgithub Actionsを書く
CIを回す際に永続化レイヤーが欲しくなる問題
業務アプリケーションのServiceやエンドポイントを開発していると、Testの実行時に実際の永続化レイヤーへの接続が欲しくなる。
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
を利用する。Ports
に1433/tcp
を設定するhealth-cmd
に"/opt/mssql-tools/bin/sqlcmd -U SA -P h0geFuga -Q 'select 1' -b -o /dev/null"
を設定する。今回はCi
用の漏れても特に影響のない情報なのでId/password
を決め打ちにしているが、用途によってはsecretを挿すようにしたほうがいいかもしれない。