Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Lab 04: Artifacts

Artifacts = files/dirs passed between steps (or in/out of the workflow), stored in an artifact repository. Parameters are small strings, artifacts are for anything bigger or binary.

  • output artifact: outputs.artifacts[].path, uploaded by the wait container after the main container exits
  • input artifact: inputs.artifacts[].path, downloaded into the pod before main starts
  • needs an artifact repository (S3, GCS, MinIO, Azure, Artifactory…)

MinIO as the repository

Skip this if you used the quick-start manifest, it already ships MinIO and an artifact-repositories ConfigMap.

minio.yaml:

apiVersion: v1
kind: Secret
metadata:
  name: minio-credentials
  namespace: argo
stringData:
  accesskey: minio
  secretkey: minio123
---
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: argo
spec:
  ports:
    - port: 9000
  selector:
    app: minio
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minio
  namespace: argo
spec:
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      containers:
        - name: minio
          image: minio/minio:RELEASE.2024-01-13T07-53-03Z
          args: [server, /data]
          env:
            - name: MINIO_ROOT_USER
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: accesskey } }
            - name: MINIO_ROOT_PASSWORD
              valueFrom:
                { secretKeyRef: { name: minio-credentials, key: secretkey } }
          ports:
            - containerPort: 9000
          volumeMounts:
            - { name: data, mountPath: /data }
      volumes:
        - name: data
          emptyDir: {}
kubectl apply -f minio.yaml
kubectl -n argo wait --for=condition=ready pod -l app=minio --timeout=120s
  • emptyDir = data is lost when the pod restarts, fine for a lab

Create the bucket:

kubectl -n argo run mc --rm -i --restart=Never --image=minio/mc:RELEASE.2024-01-13T08-44-48Z --command -- \
  sh -c 'mc alias set m http://minio:9000 minio minio123 && mc mb --ignore-existing m/argo-artifacts'

Point the controller at it (key is artifactRepository, the value is a yaml string):

kubectl apply -n argo -f - <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: workflow-controller-configmap
  namespace: argo
data:
  artifactRepository: |
    archiveLogs: true
    s3:
      bucket: argo-artifacts
      endpoint: minio.argo.svc.cluster.local:9000
      insecure: true
      accessKeySecret: {name: minio-credentials, key: accesskey}
      secretKeySecret: {name: minio-credentials, key: secretkey}
EOF
  • the controller reads the configmap on change, kubectl -n argo rollout restart deployment workflow-controller if it doesn’t pick it up
  • this overwrites the whole configmap, merge instead of apply if you have other keys
  • the secret must be in the namespace the workflows run in

Output artifact

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: artifact-output-
spec:
  serviceAccountName: argo
  entrypoint: main
  templates:
    - name: main
      container:
        image: alpine:3.20
        command: [sh, -c]
        args: ['echo hello > /tmp/hello.txt']
      outputs:
        artifacts:
          - name: hello
            path: /tmp/hello.txt
  • UI: workflow node, Artifacts tab, download link
  • argo get -n argo @latest -o yaml | grep -A8 archiveLocation shows the bucket/key
  • default key = <workflow>/<pod>/<artifact>.tgz, single files and dirs are tarred+gzipped

Passing between steps

templates:
  - name: main
    steps:
      - - name: create
          template: create
      - - name: process
          template: process
          arguments:
            artifacts:
              - name: input-file
                from: '{{steps.create.outputs.artifacts.data}}'

  - name: create
    container:
      image: alpine:3.20
      command: [sh, -c]
      args: ['seq 1 10 > /tmp/data.txt']
    outputs:
      artifacts:
        - name: data
          path: /tmp/data.txt

  - name: process
    inputs:
      artifacts:
        - name: input-file
          path: /tmp/input.txt
    container:
      image: alpine:3.20
      command: [sh, -c]
      args: ['wc -l /tmp/input.txt']
  • from: "{{steps.<step>.outputs.artifacts.<name>}}", in a DAG {{tasks.<task>.outputs.artifacts.<name>}}
  • several artifacts = several entries in outputs.artifacts / arguments.artifacts
  • the consumer picks the path where the file lands, name doesn’t need to match

Artifact sources

Inputs can come from outside the repository:

inputs:
  artifacts:
    - name: source
      path: /src
      git:
        repo: https://github.com/argoproj/argo-workflows.git
        revision: main
        depth: 1
    - name: data
      path: /tmp/data.json
      http:
        url: https://jsonplaceholder.typicode.com/posts/1
    - name: config
      path: /tmp/config.yaml
      raw:
        data: |
          key1: value1
  • git clones (supports sshPrivateKeySecret/usernameSecret for private repos), http downloads, raw writes inline text
  • s3, gcs, azure, artifactory, hdfs also work as inputs with their own key/secret refs

Archive and compression

outputs:
  artifacts:
    - name: files
      path: /tmp/data
      archive:
        none: {}
  • default archive: tar: {compressionLevel} = tar.gz
  • none: {} uploads the dir as plain files (fine for S3/MinIO), single files are uploaded as is. Use it for already compressed data
  • zip: {} also exists

Cleanup

argo delete -n argo --all
kubectl delete -n argo -f minio.yaml

Next: Lab 05, Lab 06