GithubHelp home page GithubHelp logo

Comments (6)

crazy-max avatar crazy-max commented on August 10, 2024

@tpolekhin

I was wondering why use multi-line string list instead of YAML array for inputs?
Maybe it's a technical limitation and it's okay if so I just wanted to check.

This is a limitation with the GitHub Actions toolkit itself yes (actions/toolkit#184).

I guess they used a list type for their output to match this action input type.

The separator used by the metadata action for tags or labels output is lf (\n).

I'm trying to reuse some of them as build args to also inject this information into the app binary, but it doesn't work because steps.meta.outputs.labels is not an array.

We could output labels, tags and other info using a JSON representation with a new output for this purpose:

{
  "tags": [
    "name/app:1.2.3",
    "name/app:1.2",
    "name/app:sha-90dd603",
    "name/app:latest"
  ],
  "labels": {
    "org.opencontainers.image.title": "Hello-World",
    "org.opencontainers.image.description": "This your first repo!",
    "org.opencontainers.image.url": "https://github.com/octocat/Hello-World",
    "org.opencontainers.image.source": "https://github.com/octocat/Hello-World",
    "org.opencontainers.image.version": "1.2.3",
    "org.opencontainers.image.created": "2020-01-10T00:30:00.000Z",
    "org.opencontainers.image.revision": "90dd6032fac8bda1b6c4436a2e65de27961ed071",
    "org.opencontainers.image.licenses": "MIT"
  }
}

This way you could use the fromJSON function expression to handle that:

      - name: Prepare image metadata
        uses: docker/metadata-action@v3
        id: meta
        with:
          images: repo/app

      - name: Build and push docker image
        uses: docker/build-push-action@v2
        with:
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          build-args: |
            BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
            VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
            REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}

from metadata-action.

tpolekhin avatar tpolekhin commented on August 10, 2024

Thank you for a quick response on that!
Currently I use workaround, pretty similar to what you proposed actually :)

      - name: Extract meta image labels
        id: extract
        run: echo ::set-output name=labels::$(jq -r -c '.target."docker-metadata-action".labels' ${{ steps.meta.outputs.bake-file }})

      - name: Build and push operator image
        uses: docker/build-push-action@v2
        with:
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          build-args: |
            BUILDTIME=${{ fromJSON(steps.extract.outputs.labels)['org.opencontainers.image.created'] }}
            VERSION=${{ fromJSON(steps.extract.outputs.labels)['org.opencontainers.image.version'] }}
            REVISION=${{ fromJSON(steps.extract.outputs.labels)['org.opencontainers.image.revision'] }}

I would definitely appreciate if you can add json format output so I can throw away this intermediate step

from metadata-action.

crazy-max avatar crazy-max commented on August 10, 2024

@tpolekhin Ok thanks for your feedback. I move this issue to the metadata repo.

from metadata-action.

crazy-max avatar crazy-max commented on August 10, 2024

@tpolekhin You can try with docker/metadata-action@master.

from metadata-action.

tpolekhin avatar tpolekhin commented on August 10, 2024

@crazy-max Works perfectly! Thanks!
https://github.com/tpolekhin/actions-playground/runs/2650265161

Are you planning to release a new version?
I'm a little concerned to use @master in the real pipeline

from metadata-action.

crazy-max avatar crazy-max commented on August 10, 2024

@tpolekhin Yes in few minutes

from metadata-action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.