### Image Interface Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/07-types.md An example demonstrating how to instantiate the Image interface with a Docker image name and enable flag. ```typescript const image: Image = { name: 'ghcr.io/myorg/myapp', enable: true }; ``` -------------------------------- ### Full Docker Bake Schema Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/11-bake-files.md An example demonstrating the full Docker Bake schema, including metadata action outputs and other bake options like context, dockerfile, platforms, and output types. ```hcl target "build" { context = "." dockerfile = "Dockerfile" platforms = ["linux/amd64"] # From metadata action tags = ["ghcr.io/org/app:1.0"] labels = {"version": "1.0"} args = {"BUILD_VERSION": "1.0"} # Other bake options output = ["type=registry"] cache-from = ["type=registry,ref=..."] } ``` -------------------------------- ### Version Interface Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Illustrates the structure of the Version interface for a semver tag. ```json { main: '1.2.3', partial: ['1.2', '1'], latest: true } ``` -------------------------------- ### Multiple Annotation Levels Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/10-json-output.md Demonstrates how annotations can be applied to multiple levels, such as 'manifest' and 'index'. ```json { "annotations": [ "manifest:org.opencontainers.image.version=1.2.3", "index:org.opencontainers.image.version=1.2.3" ] } ``` -------------------------------- ### Annotations Array Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/10-json-output.md Lists annotations with an annotation level prefix. The default level is 'manifest', but can be configured. ```json { "annotations": [ "manifest:org.opencontainers.image.created=2024-01-15T10:30:00.000Z", "manifest:org.opencontainers.image.description=My app", "manifest:org.opencontainers.image.revision=abc123...", "manifest:org.opencontainers.image.version=1.2.3" ] } ``` -------------------------------- ### Version Interface Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/07-types.md Illustrates the structure of the Version interface for a semver tag like v1.2.3. Shows how 'main', 'partial', and 'latest' properties are populated. ```plaintext For v1.2.3 with semver pattern {{major}}.{{minor}}.{{patch}}: { main: '1.2.3', partial: ['1.2', '1'], latest: true } ``` -------------------------------- ### Tag Class Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/02-tag.md Demonstrates how to instantiate and use the Tag class to set its type and attributes, and then convert it to a string representation. ```typescript const tag = new Tag(); tag.type = Type.Semver; tag.attrs = {pattern: '{{version}}', priority: '900'}; console.log(tag.toString()); // 'type=semver,pattern={{version}},priority=900' ``` -------------------------------- ### Tags Array Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/10-json-output.md Displays fully qualified Docker image tags. The format varies based on the number of images configured. ```json { "tags": [ "ghcr.io/myorg/myapp:1.2.3", "ghcr.io/myorg/myapp:1.2", "ghcr.io/myorg/myapp:latest", "docker.io/myorg/myapp:1.2.3", "docker.io/myorg/myapp:1.2", "docker.io/myorg/myapp:latest" ] } ``` -------------------------------- ### Transform Function Example: Basic Flavor Settings Source: https://github.com/docker/metadata-action/blob/master/_autodocs/04-flavor.md Demonstrates parsing basic flavor settings like 'latest', 'prefix', and 'suffix' into a Flavor object. ```typescript const flavor = Transform([ 'latest=auto', 'prefix=v', 'suffix=-prod' ]); // Returns: // { // latest: 'auto', // prefix: 'v', // prefixLatest: false, // suffix: '-prod', // suffixLatest: false // } ``` -------------------------------- ### PEP 440 Pattern Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md Shows how to use the 'version' expression for PEP 440 compliant tags, preserving pre-release, post-release, and dev versions. ```yaml tags: | type=pep440,pattern={{version}} # 1.2.3rc2 # 1.2.3 ``` -------------------------------- ### Tag Names Array Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/10-json-output.md Provides version tags without image base names, useful for referencing versions independently. ```json { "tag-names": [ "1.2.3", "1.2", "latest" ] } ``` -------------------------------- ### Example of Schedule Processor Pattern Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Demonstrates the use of the 'schedule' processor with date formatting using handlebars expressions. The pattern can include date formatting and timezone specification. ```plaintext Pattern `{{date 'YYYYMMDD' tz='UTC'}}` produces `20240115` ``` -------------------------------- ### Minimal Docker Bake Action Setup Source: https://github.com/docker/metadata-action/blob/master/_autodocs/11-bake-files.md This snippet shows a basic GitHub Actions workflow using the Docker Bake Action with minimal configuration. It generates tags using docker/metadata-action and then uses the bake action to build and push. ```yaml jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: docker/metadata-action@v6 id: meta with: images: ghcr.io/${{ github.repository }} tags: type=semver,pattern={{version}} - uses: docker/bake-action@v3 with: files: | docker-bake.hcl ${{ steps.meta.outputs.bake-file }} targets: build push: true ``` -------------------------------- ### Docker Bake HCL for Minimal Setup Source: https://github.com/docker/metadata-action/blob/master/_autodocs/11-bake-files.md This HCL file defines targets for the Docker Bake Action. The 'build' target inherits from 'docker-metadata-action' and specifies platforms. ```hcl target "docker-metadata-action" {} target "build" { inherits = ["docker-metadata-action"] context = "." dockerfile = "Dockerfile" platforms = ["linux/amd64", "linux/arm64"] } ``` -------------------------------- ### Workflow Example: Newline-Separated Legacy Format Source: https://github.com/docker/metadata-action/blob/master/_autodocs/03-image.md Illustrates how to define multiple images using the legacy, newline-separated format within a GitHub Actions workflow file. ```yaml # In GitHub Actions workflow images: | ghcr.io/org/app1 ghcr.io/org/app2 docker.io/org/app3 ``` -------------------------------- ### Semver Pattern Examples Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md Demonstrates various Semver pattern expressions for extracting major, minor, patch, and full version strings. Handles pre-release versions by preserving them in the 'version' field. ```yaml tags: | type=semver,pattern={{major}}.{{minor}}.{{patch}} # v1.2.3 type=semver,pattern=v{{major}} # v1.2.3 type=semver,pattern={{version}} # v1.2.3-beta.1 ``` -------------------------------- ### Match Pattern Examples with Regex Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md Illustrates using regex capture groups with 'type=match' patterns to extract specific parts of a tag string. Allows specifying which capture group to use. ```yaml tags: | type=match,pattern=v(\d.\d.\d) # v1.2.3 type=match,pattern=(\w+)/v([\d.]+),group=2 # path/v1.2.3 ``` -------------------------------- ### Multiple Images with Mixed Enable Status Source: https://github.com/docker/metadata-action/blob/master/_autodocs/03-image.md Example showing how to configure multiple images, with specific images explicitly disabled for tag generation using the 'enable=false' attribute. ```typescript const images = Transform([ 'name=ghcr.io/myorg/frontend', 'name=ghcr.io/myorg/backend,enable=false', 'name=docker.io/myorg/legacy' ]); // Three images, middle one disabled ``` -------------------------------- ### Labels Object Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/10-json-output.md Represents OCI image labels as key-value pairs, including standard labels and custom overrides. Keys are sorted alphabetically. ```json { "labels": { "org.opencontainers.image.created": "2024-01-15T10:30:00.000Z", "org.opencontainers.image.description": "My application", "org.opencontainers.image.licenses": "MIT", "org.opencontainers.image.revision": "abc1234def5678...", "org.opencontainers.image.source": "https://github.com/myorg/myapp", "org.opencontainers.image.title": "myapp", "org.opencontainers.image.url": "https://github.com/myorg/myapp", "org.opencontainers.image.version": "1.2.3" } } ``` -------------------------------- ### Parse Modern Image Format Source: https://github.com/docker/metadata-action/blob/master/_autodocs/03-image.md Example demonstrating the parsing of modern, attribute-based image specifications, including enabling and disabling tag generation for specific images. ```typescript const inputs = [ 'ghcr.io/docker/metadata-action', 'name=docker.io/library/alpine,enable=false', 'name=quay.io/opencontainers/image' ]; const images = Transform(inputs); // Returns: // [ // { name: 'ghcr.io/docker/metadata-action', enable: true }, // { name: 'docker.io/library/alpine', enable: false }, // { name: 'quay.io/opencontainers/image', enable: true } // ] ``` -------------------------------- ### Annotations with Multiple Levels using Docker Bake Action Source: https://github.com/docker/metadata-action/blob/master/_autodocs/11-bake-files.md This example shows how to use the Docker Bake Action with annotations generated by docker/metadata-action. It specifically configures annotation levels to 'manifest' and 'index'. ```yaml - uses: docker/metadata-action@v6 id: meta with: images: myapp env: DOCKER_METADATA_ANNOTATIONS_LEVELS: 'manifest,index' - uses: docker/bake-action@v3 with: files: | docker-bake.hcl ${{ steps.meta.outputs.bake-file-annotations }} targets: build ``` -------------------------------- ### Get Base Branch Name with {{base_ref}} Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md Use `base_ref` to get the base branch of a pull request or the base branch for a tag. Note that `base_ref` on tag pushes is unreliable. ```yaml labels: | org.example.target-branch={{base_ref}} ``` -------------------------------- ### Get Docker Image Tags Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Retrieves generated Docker image tags. Use `namesOnly: true` to get only tag names without the image base name. Includes 'latest' tag if applicable. ```typescript // For images: ['ghcr.io/org/app', 'docker.io/org/app'] // version: {main: '1.2.3', partial: ['1.2'], latest: true} getTags(); // [ // 'ghcr.io/org/app:1.2.3', // 'ghcr.io/org/app:1.2', // 'ghcr.io/org/app:latest', // 'docker.io/org/app:1.2.3', // 'docker.io/org/app:1.2', // 'docker.io/org/app:latest' // ] ``` ```typescript getTags(true); // ['1.2.3', '1.2', 'latest'] ``` -------------------------------- ### Basic Single Image Configuration Source: https://github.com/docker/metadata-action/blob/master/_autodocs/09-configuration.md Configures the action to build and tag a single image (`myapp`) with tags based on branches, tags, and semantic versioning. ```yaml with: images: myapp tags: | type=ref,event=branch type=ref,event=tag type=semver,pattern={{version}} ``` -------------------------------- ### Get Enabled Image Names Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Returns a list of enabled Docker image names, all sanitized to lowercase. ```typescript getImageNames() ``` -------------------------------- ### Get Annotations Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Retrieves annotations in `key=value` format. Custom annotations from inputs are processed through a global expression template. ```typescript // With inputs.annotations = ['org.example.build.date={{date "YYYY-MM-DD"}}'] const annotations = meta.getAnnotations(); ``` -------------------------------- ### Building Docker Images with Bake Files Source: https://github.com/docker/metadata-action/blob/master/_autodocs/06-main.md This snippet shows how to set up Docker Buildx and then use the docker/bake-action to build images based on bake files, incorporating metadata from the docker/metadata-action. ```yaml - name: Setup Docker Buildx uses: docker/setup-buildx-action@v2 - name: Build with bake uses: docker/bake-action@v3 with: files: | docker-bake.hcl ${{ steps.meta.outputs.bake-file }} targets: build ``` -------------------------------- ### Sanitize Consecutive Hyphens Source: https://github.com/docker/metadata-action/blob/master/_autodocs/12-sanitization.md Consecutive hyphens are preserved during sanitization. This example shows input with special characters being converted to hyphens. ```text Input: my@@tag Output: my--tag ``` -------------------------------- ### Transform Function Example: Using 'onlatest' Source: https://github.com/docker/metadata-action/blob/master/_autodocs/04-flavor.md Illustrates how the 'onlatest' attribute applies the preceding prefix or suffix specifically to the 'latest' tag. ```typescript const flavor = Transform([ 'prefix=release-', 'onlatest=true', 'suffix=-stable' ]); // Returns: // { // latest: 'auto', // prefix: 'release-', // prefixLatest: true, // from 'onlatest=true' after prefix // suffix: '-stable', // suffixLatest: false // } ``` -------------------------------- ### Tag Name Sanitization Examples Source: https://github.com/docker/metadata-action/blob/master/_autodocs/12-sanitization.md Tag names are sanitized when used via the `{{tag}}` expression. Invalid characters are replaced with hyphens. ```text Ref: refs/tags/v1.2.3 Tag Expression: v1.2.3 After Sanitization: v1.2.3 ``` ```text Ref: refs/tags/release@1.0 Tag Expression: release@1.0 After Sanitization: release-1.0 ``` ```text Ref: refs/tags/my-tag:test Tag Expression: my-tag:test After Sanitization: my-tag-test ``` -------------------------------- ### Parse Inputs and Initialize Toolkit Source: https://github.com/docker/metadata-action/blob/master/_autodocs/06-main.md Parses GitHub Actions inputs, initializes the Docker Actions Toolkit with the GitHub token, and retrieves workflow/git context. ```typescript const inputs: Inputs = getInputs(); const toolkit = new Toolkit({githubToken: inputs.githubToken}); const context = await getContext(inputs.context, toolkit); const repo = await toolkit.github.repoData(); ``` -------------------------------- ### Basic Docker Metadata Action Usage Source: https://github.com/docker/metadata-action/blob/master/README.md This is a basic GitHub Actions workflow demonstrating how to use the docker/metadata-action to generate tags and labels for Docker images. It includes steps for logging into Docker Hub and building/pushing the image using the generated metadata. ```yaml name: ci on: workflow_dispatch: push: branches: - 'master' tags: - 'v*' pull_request: branches: - 'master' jobs: docker: runs-on: ubuntu-latest steps: - name: Docker meta id: meta uses: docker/metadata-action@v6 with: images: name/app - name: Login to DockerHub if: github.event_name != 'pull_request' uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push uses: docker/build-push-action@v7 with: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} ``` -------------------------------- ### SHA Sanitization Example Source: https://github.com/docker/metadata-action/blob/master/_autodocs/12-sanitization.md Commit SHAs are not sanitized as they only contain valid lowercase hex characters. The `{{sha}}` expression produces a hex string. ```text SHA abc1234def5678... Output: abc1234 ``` -------------------------------- ### Get JSON Output Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Combines tags and labels into a structured JSON object. Specify annotation levels like `['manifest']` or `['manifest', 'index']`. ```typescript const json = meta.getJSON(['manifest']); // { // tags: ['ghcr.io/org/app:1.2.3', 'ghcr.io/org/app:latest'], // 'tag-names': ['1.2.3', 'latest'], // labels: { // 'org.opencontainers.image.version': '1.2.3', // ... // }, // annotations: ['manifest:org.opencontainers.image.version=1.2.3', ...] // } ``` -------------------------------- ### Initialize Meta Object Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Instantiates the Meta object with inputs, context, and repository data. Computes the version and transforms inputs during initialization. ```typescript const meta = new Meta(inputs, context, repo); console.log(meta.version.main); // '1.2.3' ``` -------------------------------- ### Get Current Git Tag Name with {{tag}} Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md The `tag` expression retrieves the current Git tag name. It is empty if the reference is not a tag. ```yaml tags: | type=raw,prefix=release-,value={{tag}} # On tag 'v1.2.3': 'release-v1.2.3' ``` -------------------------------- ### Multi-Platform Build with Docker Bake Action Source: https://github.com/docker/metadata-action/blob/master/_autodocs/11-bake-files.md This workflow demonstrates building Docker images for multiple platforms using the Docker Bake Action. It utilizes docker/metadata-action to generate various tag types. ```yaml - uses: docker/metadata-action@v6 id: meta with: images: | ghcr.io/myorg/myapp docker.io/myorg/myapp tags: | type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=ref,event=branch - uses: docker/bake-action@v3 with: files: | docker-bake.hcl ${{ steps.meta.outputs.bake-file }} targets: | build-amd64 build-arm64 push: true ``` -------------------------------- ### Use JSON Output for Build Args Source: https://github.com/docker/metadata-action/blob/master/README.md Utilize the `json` output from `docker/metadata-action` to access generated tags and labels using the `fromJSON` function. This allows passing metadata like build time, version, and revision as build arguments to other actions. ```yaml - name: Docker meta uses: docker/metadata-action@v6 id: meta with: images: name/app - name: Build and push uses: docker/build-push-action@v7 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'] }} ``` -------------------------------- ### Set Annotations with Build-Push Action Source: https://github.com/docker/metadata-action/blob/master/README.md Use the 'annotations' output from the metadata-action as input for the docker/build-push-action. ```yaml - name: Docker meta uses: docker/metadata-action@v6 with: images: name/app - name: Build and push uses: docker/build-push-action@v7 with: tags: ${{ steps.meta.outputs.tags }} annotations: ${{ steps.meta.outputs.annotations }} ``` -------------------------------- ### Context Module Functions Source: https://github.com/docker/metadata-action/blob/master/_autodocs/13-reference-index.md Functions for retrieving and managing build context and inputs. ```APIDOC ## Context Module ### `getInputs(): Inputs` Retrieves the inputs provided to the action. ### `getContext(source: ContextSource, toolkit: Toolkit): Promise` Retrieves the build context from a specified source using the provided toolkit. ``` -------------------------------- ### CI Workflow with Bake File Tags and Labels Outputs Source: https://github.com/docker/metadata-action/blob/master/README.md This YAML snippet demonstrates an alternative way to integrate docker/metadata-action with docker/bake-action, specifically using the 'bake-file-tags' and 'bake-file-labels' outputs for more granular control. ```yaml - name: Build uses: docker/bake-action@v7 with: files: | ./docker-bake.hcl cwd://${{ steps.meta.outputs.bake-file-tags }} cwd://${{ steps.meta.outputs.bake-file-labels }} targets: build ``` -------------------------------- ### Generate Combined Docker Bake File (Tags, Labels, Args) Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Generates a Docker Bake definition file that combines tags, labels, and arguments. The output is a JSON file path. ```json { "target": { "docker-metadata-action": { "tags": ["name/app:1.2.3", "name/app:1.2", "name/app:latest"], "labels": { "org.opencontainers.image.title": "Hello-World", "org.opencontainers.image.version": "1.2.3" }, "args": { "DOCKER_META_IMAGES": "name/app", "DOCKER_META_VERSION": "1.2.3" } } } } ``` -------------------------------- ### Get Short Commit SHA with {{sha}} Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md The `sha` expression provides the short commit SHA, defaulting to 7 characters. This length can be configured using the `DOCKER_METADATA_SHORT_SHA_LENGTH` environment variable. ```yaml tags: | type=raw,value={{sha}}-build # Returns: 'abc1234-build' ``` -------------------------------- ### Get Current Branch Name with {{branch}} Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md Use the `branch` expression to dynamically include the current Git branch name in tags. It returns an empty string if the reference is not a branch. ```yaml tags: | type=raw,prefix={{branch}}-,value=build # On branch 'main': 'main-build' # On tag push: 'build' ``` -------------------------------- ### Use JSON Output with build-push-action Source: https://github.com/docker/metadata-action/blob/master/_autodocs/10-json-output.md Pass extracted tags and labels, and parse JSON for build arguments when using the `docker/build-push-action`. ```yaml - name: Build and push uses: docker/build-push-action@v7 with: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} ``` -------------------------------- ### Sanitize Leading/Trailing Hyphens Source: https://github.com/docker/metadata-action/blob/master/_autodocs/12-sanitization.md Docker specifications prohibit tags starting or ending with periods or dashes. This action does not strip them, and registry validation will fail at push time for invalid tags. ```text Pattern: {{major}} Version: 0.1.2 Result: 0 (valid) Pattern: -{{major}} Version: 1.2.3 Result: -1 (invalid per Docker spec, caught by registry) ``` -------------------------------- ### Version with Commit Date and Repository URL Source: https://github.com/docker/metadata-action/blob/master/_autodocs/08-expressions.md Set image labels for creation date and repository URL using commit date and GitHub repository context. ```yaml labels: | org.opencontainers.image.created={{commit_date 'YYYY-MM-DDTHH:mm:ss.SSS[Z]'}} org.opencontainers.image.url=${{ github.repository }} ``` -------------------------------- ### Get Git Repository Context Source: https://github.com/docker/metadata-action/blob/master/_autodocs/01-context.md Retrieves context from the local Git repository state using Docker Actions Toolkit's Git utilities to extract branch, ref, and SHA. ```typescript async function getContextFromGit(): Promise ``` -------------------------------- ### Custom Versioning and Labels Source: https://github.com/docker/metadata-action/blob/master/_autodocs/09-configuration.md Applies custom versioning using PEP 440 and raw values, along with custom labels for vendor and build date. ```yaml with: images: myapp tags: | type=pep440,pattern={{version}},value=${{ github.ref }} type=raw,value=latest,enable={{is_default_branch}} labels: | org.opencontainers.image.vendor=ACME org.example.build-date={{date 'YYYY-MM-DD'}} ``` -------------------------------- ### Image Interface Source: https://github.com/docker/metadata-action/blob/master/_autodocs/07-types.md Defines the structure for configuring a single Docker image, including its name and whether to enable tag generation. ```APIDOC ## Image (Interface) ### Description Configuration for a single Docker image. ### Properties - **name** (string) - Required - Docker image name (may include registry) - **enable** (boolean) - Required - Generate tags for this image ### Example ```typescript const image: Image = { name: 'ghcr.io/myorg/myapp', enable: true }; ``` ``` -------------------------------- ### Parse Legacy Image Format with Newlines Source: https://github.com/docker/metadata-action/blob/master/_autodocs/03-image.md Example showing how the Transform function handles legacy image formats when a single input string contains multiple image names separated by newlines. ```typescript const inputs = [ 'ghcr.io/docker/metadata-action\ndocker.io/library/alpine' ]; const images = Transform(inputs); // Returns: // [ // { name: 'ghcr.io/docker/metadata-action', enable: true }, // { name: 'docker.io/library/alpine', enable: true } // ] ``` -------------------------------- ### getBakeFileTagsLabels(): string Source: https://github.com/docker/metadata-action/blob/master/_autodocs/05-meta.md Generates a combined Docker bake definition file that includes tags, labels, and arguments. ```APIDOC ## getBakeFileTagsLabels(): string ### Description Generates combined bake definition with tags, labels, and args. ### Returns `string` — File path to bake definition combining all metadata. ### Example output: ```json { "target": { "docker-metadata-action": { "tags": ["name/app:1.2.3", "name/app:1.2", "name/app:latest"], "labels": { "org.opencontainers.image.title": "Hello-World", "org.opencontainers.image.version": "1.2.3" }, "args": { "DOCKER_META_IMAGES": "name/app", "DOCKER_META_VERSION": "1.2.3" } } } } ``` ``` -------------------------------- ### Get Commit Date from Workflow Source: https://github.com/docker/metadata-action/blob/master/_autodocs/01-context.md Determines the commit date from the GitHub workflow payload or API. Falls back to checking event payloads, then GitHub API, and finally returns the current date if all else fails. ```typescript async function getCommitDateFromWorkflow( sha: string, toolkit: Toolkit ): Promise ``` -------------------------------- ### Basic GitHub Actions Workflow with Docker Metadata Source: https://github.com/docker/metadata-action/blob/master/_autodocs/06-main.md This snippet shows a typical GitHub Actions workflow that uses the docker/metadata-action to extract image metadata, followed by the docker/build-push-action to build and push Docker images. ```yaml name: Build and Push on: push: branches: [main] tags: ['v*'] jobs: build: runs-on: ubuntu-latest steps: - name: Extract metadata id: meta uses: docker/metadata-action@v6 with: images: | ghcr.io/myorg/myapp docker.io/library/myapp tags: | type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=ref,event=branch - name: Build and push uses: docker/build-push-action@v7 with: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} annotations: ${{ steps.meta.outputs.annotations }} ``` -------------------------------- ### Get GitHub Workflow Context Source: https://github.com/docker/metadata-action/blob/master/_autodocs/01-context.md Retrieves context from GitHub Actions workflow runtime. Overrides ref for `pull_request_target` events and supports overriding commit SHA with PR head SHA via environment variable. ```typescript async function getContextFromWorkflow(toolkit: Toolkit): Promise ``` -------------------------------- ### Configure SemVer for Major Version Zero Source: https://github.com/docker/metadata-action/blob/master/README.md Manage Docker tag generation for major version zero (0.y.z) using `type=semver`. The `enable` flag can disable tag generation based on conditions, such as not starting with `refs/tags/v0.`. ```yaml type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} ``` -------------------------------- ### Nightly Builds with Timezone and Annotations Source: https://github.com/docker/metadata-action/blob/master/_autodocs/09-configuration.md Configures nightly builds with a specific timezone for date formatting and sets Docker metadata annotations for manifest and index levels. ```yaml with: images: myapp tags: | type=schedule,pattern=nightly-{{date 'YYYYMMDD' tz='US/Eastern'}} annotations: | org.example.scheduled=true env: DOCKER_METADATA_ANNOTATIONS_LEVELS: 'manifest,index' ``` -------------------------------- ### Get GitHub Context with Git Metadata Source: https://github.com/docker/metadata-action/blob/master/_autodocs/01-context.md Retrieves GitHub context, optionally enriched with Git metadata. Routes to workflow or Git context retrieval based on the source parameter. Requires a Toolkit instance for GitHub API access. ```typescript import {Toolkit} from '@docker/actions-toolkit/lib/toolkit.js'; import {getContext, ContextSource} from './context.js'; const toolkit = new Toolkit({githubToken: process.env.GITHUB_TOKEN}); const context = await getContext(ContextSource.workflow, toolkit); console.log(context.ref); console.log(context.sha); console.log(context.commitDate); ``` -------------------------------- ### Configure Schedule Tagging Source: https://github.com/docker/metadata-action/blob/master/README.md Set up tags for schedule events. Supports basic patterns, date formatting, and timezone specification. ```yaml tags: | # minimal type=schedule # default type=schedule,pattern=nightly # handlebars type=schedule,pattern={{date 'YYYYMMDD'}} # handlebars with timezone type=schedule,pattern={{date 'YYYYMMDD-HHmmss' tz='Asia/Tokyo'}} ```