LoginSignup
3
1

More than 1 year has passed since last update.

.NET 6 と Daprを使った分散サービス開発 その14 tye あれこれ

Posted at

Tyeあれこれ

今まで、各サービスとDaprを一緒に起動してくれたり、ビルドしてくれたり、 Kubernetes にデプロイしてくれたりと便利なTyeですが、ここではTyeの他の機能について少し触れてみたいと思います。


依存するDockerコンテナを自動で起動

サービスをローカルで開発するにあたって、様々な依存コンテナやクラウドでのサービスのエミュレータ起動などが必要となるケースがあります。
例えば、Azlite (OSSのAzure Storage エミュレータ) や Azure CosmosDBなどはコンテナイメージでエミュレータがありますので、サービスと共にローカル起動するなどしたい所です。
また、マイクロサービスの場合、別のチームは .NET以外の言語で開発しているケースなどで、一緒に駆動させたいケースなどでも活用できると思います。

早速、Tyeに設定を組み込みます。

tye.yaml
# tye application configuration file
# read all about it at https://github.com/dotnet/tye
#
# when you've given us a try, we'd love to know what you think:
#    https://aka.ms/AA7q20u
#
name: dapr
extensions:
  - name: dapr

    # log-level configures the log level of the dapr sidecar
    log-level: debug

    # config allows you to pass additional configuration into the dapr sidecar
    # config will be interpreted as a named k8s resource when deployed, and will be interpreted as
    # a file on disk when running locally at `./components/myconfig.yaml`
    #
    # config: myconfig

    # components-path configures the components path of the dapr sidecar
    components-path: "./components/"

    # If not using the default Dapr placement service or otherwise using a placement service on a nonstandard port,
    # you can configure the Dapr sidecar to use an explicit port.
    # placement-port: 6050
services:
  - name: service-a
    project: ServiceA/ServiceA.csproj
  - name: service-b
    project: ServiceB/ServiceB.csproj
  - name: app
    project: App/App.csproj
  - name: stateservice
    project: StateService/StateService.csproj
  - name: worker-service
    project: WorkerService/WorkerService.csproj
  - name: pub-service
    project: PubService/PubService.csproj
  - name: sub-service
    project: SubService/SubService.csproj
  - name: sub-service2
    project: SubService2/SubService2.csproj

  # This may conflict with the redis instance that dapr manages.
  #
  # Doing a `docker ps` can show if its already running. If that's the case
  # then comment out out when running locally.
  # - name: redis
  #   image: redis
  #   bindings:
  #   - port: 6379
  - name: Azlite
    image: mcr.microsoft.com/azure-storage/azurite
    bindings:
      - port: 20000
        containerPort: 10000
        protocol: https
        name: blob
      - port: 20001
        containerPort: 10001
        protocol: https
        name: queue
      - port: 20002
        containerPort: 10002
        protocol: https
        name: table

tye runをしてみると、プロジェクトをビルドする前にイメージをPullして、ローカルで実行してくれている様子がわかります。

$ tye run
Loading Application Details...
Launching Tye Host...

[13:01:29 INF] Executing application from C:\Users\kahiro\DaprQiita\tye.yaml
[13:01:29 INF] Dashboard running on http://127.0.0.1:8000
[13:01:30 INF] Running docker command pull mcr.microsoft.com/azure-storage/azurite
[13:01:30 INF] mcr.microsoft.com/azure-storage/azurite: Using default tag: latest
[13:01:35 INF] mcr.microsoft.com/azure-storage/azurite: latest: Pulling from azure-storage/azurite
[13:01:41 INF] mcr.microsoft.com/azure-storage/azurite: mcr.microsoft.com/azure-storage/azurite:latest
[13:01:41 INF] Creating docker network tye_network_231890b8-7
[13:01:41 INF] Running docker command network create --driver bridge tye_network_231890b8-7
...
[13:01:41 INF] Running image mcr.microsoft.com/azure-storage/azurite for azlite_35d0025b-5
[13:01:41 INF] Building projects
[13:01:41 INF] Build Watcher: Watching for builds...
...
[13:02:46 INF] Replica worker-service-dapr_415de17a-e is moving to a ready state

以下のように、docker psで確認すると起動している事がわかります。

$ docker ps
4139c4a127fa   mcr.microsoft.com/azure-storage/azurite   "docker-entrypoint.s…"   19 seconds ago   Up 18 seconds           0.0.0.0:20000->10000/tcp, 0.0.0.0:20001->10001/tcp, 0.0.0.0:20002->10002/tcp   azlite_299a4b7d-9
3
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1