-
Notifications
You must be signed in to change notification settings - Fork 118
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
Handle multiple prefixes with Bake #124
Comments
@felipecrs If I understand correctly you want to transpose the bake target name as a tag? |
@crazy-max this specific point is just a coincidence. One solution would be to:
Then, metadata-action instead of outputting a single target, it would output multiple targets. |
I'm trying to do something similar to this. I have a repo with multiple micro-services, each service is pushed to a registry ( |
I had this exact problem, and figured that the bake files are just JSON files that can be merged with - name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ...
bake-target: docker-metadata-action
tags: ...
- name: Docker meta (debug variant)
id: meta-debug
uses: docker/metadata-action@v3
with:
images: ...
bake-target: docker-metadata-action-debug
tags: ...
- name: Merge buildx bake files
run: |
jq -s '.[0] * .[1]' ${{ steps.meta.outputs.bake-file }} ${{ steps.meta-debug.outputs.bake-file }} > docker-bake.override.json That way I have two different targets filled in my bake file: https://github.com/matrix-org/matrix-authentication-service/blob/1df5cf42e32abaeedddc504afeb431d77154f78f/docker-bake.hcl#L4-L6 |
There is a buildx bug that is related: docker/buildx#756 |
Here is what I'm currently doing, which does not require jq merging the JSONs. # docker-bake.hcl
target "base" {
context = "."
target = "base"
}
target "github" {
inherits = ["base"]
target = "github"
} # .github/workflows/ci.yaml
[...]
steps:
- name: Docker meta (base)
id: docker-meta-base
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=schedule,pattern=nightly
type=schedule,pattern={{date 'YYYYMMDD'}}
type=ref,event=branch
type=ref,event=pr
type=sha,enable=${{ github.event_name == 'push' }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event_name == 'schedule' }}
type=raw,value=base,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || github.event_name == 'schedule' }}
bake-target: base
- name: Docker meta (github)
id: docker-meta-github
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
prefix=github-
tags: |
type=schedule,pattern=nightly
type=schedule,pattern={{date 'YYYYMMDD'}}
type=ref,event=branch
# Prefix needs to be repeated for these, refs:
# https://github.com/docker/metadata-action/issues/270
type=ref,event=pr,prefix=github-pr-
type=sha,prefix=github-sha-,enable=${{ github.event_name == 'push' }}
bake-target: github
- name: Build and push
uses: docker/bake-action@v4
with:
pull: true
no-cache: true
push: ${{ ! startsWith(github.ref, 'refs/pull/') }}
files: |
./docker-bake.hcl
${{ steps.docker-meta-base.outputs.bake-file }}
${{ steps.docker-meta-github.outputs.bake-file }} |
Let's say I have a Dockerfile like so:
And a
docker-bake.hcl
like so:Any suggestions on how could I integrate the Metadata Action with the Bake Action so I would have tags generated with prefixes like:
And of course, tagging with semver like
my-image:alpine-1.1.0
.The text was updated successfully, but these errors were encountered: