ci
ci copied to clipboard
Make compatible with Docker Metadata action
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.
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