본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

스크립트와 결과 (Scripts And Results)

원문 보기 위키 갱신

워크플로 스펙에 here-script(흔히 here document라고도 부릅니다)로 지정한 스크립트를 실행하는 템플릿만 있으면 충분한 경우가 많습니다. 이 예제는 그 방법을 보여줍니다.

출처: Argo Workflows 문서

본문

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: scripts-bash-
spec:
  entrypoint: bash-script-example
  templates:
  - name: bash-script-example
    steps:
    - - name: generate
        template: gen-random-int-bash
    - - name: print
        template: print-message
        arguments:
          parameters:
          - name: message
            value: "{{steps.generate.outputs.result}}"  # The result of the here-script

  - name: gen-random-int-bash
    script:
      image: debian:9.4
      command: [bash]
      source: |                                         # Contents of the here-script
        cat /dev/urandom | od -N2 -An -i | awk -v f=1 -v r=100 '{printf "%i\n", f + r * $1 / 65536}'

  - name: gen-random-int-python
    script:
      image: python:alpine3.23
      command: [python]
      source: |
        import random
        i = random.randint(1, 100)
        print(i)

  - name: gen-random-int-javascript
    script:
      image: node:9.1-alpine
      command: [node]
      source: |
        var rand = Math.floor(Math.random() * 100);
        console.log(rand);

  - name: print-message
    inputs:
      parameters:
      - name: message
    container:
      image: alpine:3.23
      command: [sh, -c]
      args: ["echo result was: {{inputs.parameters.message}}"]

script 키워드를 사용하면 source 태그로 스크립트 본문을 지정할 수 있습니다. 이렇게 하면 스크립트 본문을 담은 임시 파일이 만들어지고, 그 임시 파일의 이름이 마지막 파라미터로 command에 전달됩니다. 이 command는 스크립트 본문을 실행하는 인터프리터여야 합니다.

container 템플릿과 마찬가지로, script 기능을 사용해도 스크립트 실행의 표준 출력이 result라는 이름의 특수 출력 파라미터에 할당됩니다. 덕분에 워크플로 스펙의 나머지 부분에서 스크립트 자체의 실행 결과를 사용할 수 있습니다. 이 예제에서는 그 결과가 print-message 템플릿에 의해 단순히 에코될 뿐입니다.

더 알아보기 (Learn more)

  • script 템플릿은 bash, python, node 등 원하는 인터프리터 이미지를 그대로 쓸 수 있습니다.
  • 스크립트의 표준 출력은 자동으로 {{steps.<step>.outputs.result}} 출력 파라미터가 되므로 후속 스텝에서 바로 참조할 수 있습니다.