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?

Workflowsにデプロイしてみた【GCP】

Last updated at Posted at 2024-12-25

まずyamlファイルを用意します。

hello.yaml
main:
  steps:
    - step1:
        call: http.post
        args:
          url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
          auth:
            type: OAuth2
          body:
            overrides:
              containerOverrides:
                - name: main-container
                  args:
                    - npm
                    - run
                    - helloA
        result: runHelloA
    - checkRunHelloAStatus:
        switch:
          - condition: ${runHelloA.code == 200}
            next: step2
          - condition: ${runHelloA.code != 200}
            next: logFailure
    - logFailure:
        call: sys.log
        args:
          text: ${runHelloA.code}
    - step2:
        call: http.post
        args:
          url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
          auth:
            type: OAuth2
          body:
            overrides:
              containerOverrides:
                - name: main-container
                  args:
                    - "npm"
                    - "run"
                    - "helloB"

URLの形式
https://{REGION}-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/{PROJECT_ID}/jobs/{JOB_NAME}:run

ロジックは非常に簡単で、hellosをnpm run helloAで実行し、ステータスコード200が返ってくれば、helloBを実行し、そうでなければステータスコードをログに表示するだけです。

デプロイコマンド

gcloud workflows deploy {workflowsName} --source="yamlファイル名"
root@9e8a85ceee38:/app# gcloud workflows deploy myHello --source="hello.yaml"
WARNING: The default location(us-central1) was used since the location flag was not specified.
Waiting for operation [operation-1735086887458-62a0d6594d698-0124134f-cda1ddd5] to complete...done.
createTime: '2024-12-24T06:14:12.139981072Z'
name: projects/myProject/locations/us-central1/workflows/myHello
revisionCreateTime: '2024-12-25T00:34:47.630451435Z'
revisionId: 
serviceAccount: mailto:projects/myproject/serviceaccounts/-compute@developer.gserviceaccount.com
sourceContents: |
  main:
    steps:
      - step1:
          call: http.post
          args:
            url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
            auth:
              type: OAuth2
            body:
              overrides:
                containerOverrides:
                  - name: main-container
                    args:
                      - npm
                      - run
                      - helloA
          result: runHelloA
      - checkRunHelloAStatus:
          switch:
            - condition: ${runHelloA.code == 200}
              next: step2
            - condition: ${runHelloA.code != 200}
              next: logFailure
      - logFailure:
          call: sys.log
          args:
            text: ${runHelloA.code}
      - step2:
          call: http.post
          args:
            url: "https://asia-northeast1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/myProject/jobs/hellos:run"
            auth:
              type: OAuth2
            body:
              overrides:
                containerOverrides:
                  - name: main-container
                    args:
                      - "npm"
                      - "run"
                      - "helloB"
state: ACTIVE
updateTime: '2024-12-25T00:34:47.732630309Z'

上記のようになればデプロイ成功です!

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?