Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with Docker Metadata action #235

Open
aaronadamsCA opened this issue Mar 29, 2023 · 1 comment
Open

Make compatible with Docker Metadata action #235

aaronadamsCA opened this issue Mar 29, 2023 · 1 comment

Comments

@aaronadamsCA
Copy link

aaronadamsCA commented Mar 29, 2023

It would be really nice if this action were compatible with the Docker Metadata action, so that tags could be generated by that action and easily passed to this action.

Right now, if you do this:

      - id: metadata
        uses: docker/metadata-action@v4
        with:
          tags: |
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
      - uses: devcontainers/[email protected]
        with:
          imageTag: "${{ join(steps.metadata.outputs.tags) }}"

The result is a Docker error, because steps.metadata.outputs.tags is already in the format "{image}:{tag}"[], and this action prepends each tag with {image}: again. Docker doesn't like -t {image}:{image}:{tag} and errors out.

If this action could check each tag to see if it's already prepended with the image name before doing so, then I think it would be directly compatible with the official Docker action.

@nickzelei
Copy link

nickzelei commented Oct 24, 2023

Would love to see this as I just hit the same issue.

I was able to work around it by adding an intermediary step to get the tags in the format necessary.

I have the metadata outputting the tags with a , separator, but it should work in the default, multi-line format. Just update the delimiter in the script to be \n instead of ,.

The script looks like this:

prefix="ghcr.io/${{ github.repository }}/devcontainer"
input_list="$DOCKER_METADATA_OUTPUT_TAGS"
delimiter=","

result_list=$(echo "$input_list" | sed "s|${prefix}:||g")

echo "tags=$result_list" >> "$GITHUB_OUTPUT"

The workflow as such:

steps:
  - name: Checkout
    id: checkout
    uses: actions/checkout@v4

  - name: Docker meta
    id: meta
    uses: docker/metadata-action@v5
    with:
      # list of Docker images to use as base name for tags
      images: |
        name=ghcr.io/${{ github.repository }}/devcontainer
      # generate Docker tags based on the following events/attributes
      tags: |
        type=match,pattern=devcontainer/v(\d.\d.\d),group=1
      sep-tags: ","

  - name: Update Tags to Fit into devcontainers/cli format
    id: dcmeta
    run: |
      prefix="ghcr.io/${{ github.repository }}/devcontainer"
      input_list="$DOCKER_METADATA_OUTPUT_TAGS"
      delimiter=","

      result_list=$(echo "$input_list" | sed "s|${prefix}:||g")

      echo "tags=$result_list" >> "$GITHUB_OUTPUT"

  - name: Set up QEMU
    uses: docker/setup-qemu-action@v3
    with:
      platforms: linux/amd64,linux/arm64

  - name: Set up Docker Buildx
    uses: docker/setup-buildx-action@v3

  - name: Login to GHCR
    uses: docker/login-action@v3
    with:
      registry: ghcr.io
      username: ${{ github.repository_owner }}
      password: ${{ secrets.GITHUB_TOKEN }}

  - name: Build and release devcontainer Multi-Platform
    uses: devcontainers/[email protected]
    env:
      # see: https://github.com/devcontainers/ci/issues/191#issuecomment-1603857155
      BUILDX_NO_DEFAULT_ATTESTATIONS: true
    with:
      imageName: ghcr.io/${{ github.repository }}/devcontainer
      imageTag: ${{ steps.dcmeta.outputs.tags }}
      cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
      platform: linux/amd64,linux/arm64
      push: always

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants