0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

高火力DOKでAPIを使ってタスクを実行する

Posted at

はじめに

高火力 DOKでAPIを使ってタスクを実行する方法について解説します。

高火力 DOKは、さくらインターネットが提供するコンテナ型GPUサービスです。
https://www.sakura.ad.jp/koukaryoku-dok/

通常、タスクの作成や実行はダッシュボードから操作できますが、APIを利用することで自動化や外部ツールとの連携が可能になります。

前提

注意事項

  • 今回は、利用規約への同意を行なっている前提となります
    詳細はサービスを使い始めるには を参照してください
  • APIキーの権限として、以下を前提としています。
項目 設定
アクセスレベル 作成・削除
他サービスへのアクセス権 高火力DOK

参考画像
create api.png

高火力 DOK API

今回は、ubuntuイメージを使用して、printenvするタスクを作成します。

curl -u "<アクセストークン>:<アクセストークンシークレット>" \
  -X POST https://secure.sakura.ad.jp/cloud/zone/is1a/api/managed-container/1.0/tasks/ \
  -H "Content-Type: application/json" \
  -d '{
    "name": "example-task",
    "containers": [
      {
        "image": "ubuntu:latest",
        "command": ["printenv"],
        "environment": {
          "EXAMPLE_ENV": "example"
        },
        "plan": "v100-32gb"
      }
    ]
  }'

plan は使用するGPUインスタンスの種類を表します。
利用可能なプラン一覧は 公式ドキュメントを参照してください。

以下のように応答が返ってきたら成功ですYatta!!!

{
  "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "created_at": "2025-03-28T20:00:00.000000+09:00",
  "updated_at": "2025-03-28T20:10:00.000000+09:00",
  "canceled_at": null,
  "name": "example-task",
  "http_uri": null,
  "containers": [
    {
      "index": 0,
      "registry": null,
      "image": "ubuntu:latest",
      "command": [
        "printenv"
      ],
      "entrypoint": [],
      "environment": {
        "EXAMPLE_ENV": "example"
      },
      "http": null,
      "plan": "v100-32gb",
      "start_at": null,
      "stop_at": null,
      "execution_seconds": null,
      "exit_code": null
    }
  ],
  "status": "waiting",
  "error_message": "",
  "artifact": null,
  "tags": []
}

ダッシュボードからも実行を確認できました\wa-i/
dok task.png

まとめ

この記事では、高火力DOKのAPIを使ってタスクを実行する手順を説明しました。

高火力DOKではAPIを使ってログ取得やタスクの状態取得、停止なども可能なので、CI/CDやバッチ処理にも活用できます。ぜひ色々試してみてください!

ここまで読んでいただきありがとうございました 🙌

参考文献

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?