|
34 | 34 | * [`type=ref`](#typeref) |
35 | 35 | * [`type=raw`](#typeraw) |
36 | 36 | * [`type=sha`](#typesha) |
| 37 | +* [`annotations` and `labels` inputs](#annotations-and-labels-inputs) |
| 38 | + * [Default labels and annotations](#default-labels-and-annotations) |
| 39 | + * [Customize labels and annotations](#customize-labels-and-annotations) |
| 40 | + * [Annotation outputs](#annotation-outputs) |
| 41 | + * [Annotation levels](#annotation-levels) |
37 | 42 | * [Notes](#notes) |
38 | 43 | * [Image name and tag sanitization](#image-name-and-tag-sanitization) |
39 | 44 | * [Latest tag](#latest-tag) |
|
49 | 54 | * [`{{commit_date '<format>' tz='<timezone>'}}`](#commit_date-format-tztimezone) |
50 | 55 | * [Major version zero](#major-version-zero) |
51 | 56 | * [JSON output object](#json-output-object) |
52 | | - * [Overwrite labels and annotations](#overwrite-labels-and-annotations) |
53 | | - * [Annotations](#annotations) |
54 | 57 | * [Contributing](#contributing) |
55 | 58 |
|
56 | 59 | ## Usage |
@@ -745,6 +748,128 @@ tags: | |
745 | 748 | type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short |
746 | 749 | ``` |
747 | 750 |
|
| 751 | +## `annotations` and `labels` inputs |
| 752 | + |
| 753 | +### Default labels and annotations |
| 754 | + |
| 755 | +The action will set the following default labels and annotations based on repository metadata: |
| 756 | + |
| 757 | +- `org.opencontainers.image.title` |
| 758 | +- `org.opencontainers.image.description` |
| 759 | +- `org.opencontainers.image.url` |
| 760 | +- `org.opencontainers.image.source` |
| 761 | +- `org.opencontainers.image.version` |
| 762 | +- `org.opencontainers.image.created` |
| 763 | +- `org.opencontainers.image.revision` |
| 764 | +- `org.opencontainers.image.licenses` |
| 765 | + |
| 766 | +### Customize labels and annotations |
| 767 | + |
| 768 | +If some [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md) |
| 769 | +generated are not suitable as labels/annotations, you can overwrite them like |
| 770 | +this: |
| 771 | + |
| 772 | +```yaml |
| 773 | + - |
| 774 | + name: Docker meta |
| 775 | + id: meta |
| 776 | + uses: docker/metadata-action@v5 |
| 777 | + with: |
| 778 | + images: name/app |
| 779 | + labels: | |
| 780 | + maintainer=CrazyMax |
| 781 | + org.opencontainers.image.title=MyCustomTitle |
| 782 | + org.opencontainers.image.description=Another description |
| 783 | + org.opencontainers.image.vendor=MyCompany |
| 784 | +``` |
| 785 | + |
| 786 | +Alternatively, you may wish to omit certain labels and annotations from the action output. For example, you may have `LABEL` directives in a Dockerfile that you would prefer to use instead of the labels set by this action. You can omit labels and annotations with `enable=false`. |
| 787 | + |
| 788 | +```yaml |
| 789 | + - |
| 790 | + name: Docker meta |
| 791 | + id: meta |
| 792 | + uses: docker/metadata-action@v5 |
| 793 | + with: |
| 794 | + images: name/app |
| 795 | + labels: | |
| 796 | + name=org.opencontainers.image.url,enable=false |
| 797 | +``` |
| 798 | + |
| 799 | +### Annotation outputs |
| 800 | + |
| 801 | +Since Buildx 0.12, it is possible to set annotations to your image through the |
| 802 | +`--annotation` flag. |
| 803 | + |
| 804 | +With the [`build-push-action`](https://github.com/docker/build-push-action/), |
| 805 | +you can set the `annotations` input with the value of the `annotations` output |
| 806 | +of the `metadata-action`: |
| 807 | + |
| 808 | +```yaml |
| 809 | + - |
| 810 | + name: Docker meta |
| 811 | + uses: docker/metadata-action@v5 |
| 812 | + with: |
| 813 | + images: name/app |
| 814 | + - |
| 815 | + name: Build and push |
| 816 | + uses: docker/build-push-action@v6 |
| 817 | + with: |
| 818 | + tags: ${{ steps.meta.outputs.tags }} |
| 819 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 820 | +``` |
| 821 | + |
| 822 | +The same can be done with the [`bake-action`](https://github.com/docker/bake-action/): |
| 823 | + |
| 824 | +```yaml |
| 825 | + - |
| 826 | + name: Docker meta |
| 827 | + uses: docker/metadata-action@v5 |
| 828 | + with: |
| 829 | + images: name/app |
| 830 | + - |
| 831 | + name: Build |
| 832 | + uses: docker/bake-action@v6 |
| 833 | + with: |
| 834 | + files: | |
| 835 | + ./docker-bake.hcl |
| 836 | + cwd://${{ steps.meta.outputs.bake-file-tags }} |
| 837 | + cwd://${{ steps.meta.outputs.bake-file-annotations }} |
| 838 | + targets: build |
| 839 | +``` |
| 840 | + |
| 841 | +### Annotation levels |
| 842 | + |
| 843 | +Note that annotations can be attached at many different levels within a manifest. |
| 844 | +By default, the generated annotations will be attached to image manifests, |
| 845 | +but different registries may expect annotations at different places; |
| 846 | +a common practice is to read annotations at _image indexes_ if present, |
| 847 | +which are often used by multi-arch builds to index platform-specific images. |
| 848 | +If you want to specify level(s) for your annotations, you can use the |
| 849 | +[`DOCKER_METADATA_ANNOTATIONS_LEVELS` environment variable](#environment-variables) |
| 850 | +with a comma separated list of all levels the annotations should be attached to (defaults to `manifest`). |
| 851 | +The following configuration demonstrates the ability to attach annotations to both image manifests and image indexes, |
| 852 | +though your registry may only need annotations at the index level. (That is, `index` alone may be enough.) |
| 853 | +Please consult the documentation of your registry. |
| 854 | + |
| 855 | +```yaml |
| 856 | + - |
| 857 | + name: Docker meta |
| 858 | + uses: docker/metadata-action@v5 |
| 859 | + with: |
| 860 | + images: name/app |
| 861 | + env: |
| 862 | + DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
| 863 | + - |
| 864 | + name: Build and push |
| 865 | + uses: docker/build-push-action@v6 |
| 866 | + with: |
| 867 | + tags: ${{ steps.meta.outputs.tags }} |
| 868 | + annotations: ${{ steps.meta.outputs.annotations }} |
| 869 | +``` |
| 870 | + |
| 871 | +More information about annotations in the [BuildKit documentation](https://github.com/moby/buildkit/blob/master/docs/annotations.md). |
| 872 | + |
748 | 873 | ## Notes |
749 | 874 |
|
750 | 875 | ### Image name and tag sanitization |
@@ -955,98 +1080,6 @@ that you can reuse them further in your workflow using the [`fromJSON` function] |
955 | 1080 | REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} |
956 | 1081 | ``` |
957 | 1082 |
|
958 | | -### Overwrite labels and annotations |
959 | | - |
960 | | -If some [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md) |
961 | | -generated are not suitable as labels/annotations, you can overwrite them like |
962 | | -this: |
963 | | - |
964 | | -```yaml |
965 | | - - |
966 | | - name: Docker meta |
967 | | - id: meta |
968 | | - uses: docker/metadata-action@v5 |
969 | | - with: |
970 | | - images: name/app |
971 | | - labels: | |
972 | | - maintainer=CrazyMax |
973 | | - org.opencontainers.image.title=MyCustomTitle |
974 | | - org.opencontainers.image.description=Another description |
975 | | - org.opencontainers.image.vendor=MyCompany |
976 | | -``` |
977 | | - |
978 | | -### Annotations |
979 | | - |
980 | | -Since Buildx 0.12, it is possible to set annotations to your image through the |
981 | | -`--annotation` flag. |
982 | | - |
983 | | -With the [`build-push-action`](https://github.com/docker/build-push-action/), |
984 | | -you can set the `annotations` input with the value of the `annotations` output |
985 | | -of the `metadata-action`: |
986 | | - |
987 | | -```yaml |
988 | | - - |
989 | | - name: Docker meta |
990 | | - uses: docker/metadata-action@v5 |
991 | | - with: |
992 | | - images: name/app |
993 | | - - |
994 | | - name: Build and push |
995 | | - uses: docker/build-push-action@v6 |
996 | | - with: |
997 | | - tags: ${{ steps.meta.outputs.tags }} |
998 | | - annotations: ${{ steps.meta.outputs.annotations }} |
999 | | -``` |
1000 | | - |
1001 | | -The same can be done with the [`bake-action`](https://github.com/docker/bake-action/): |
1002 | | - |
1003 | | -```yaml |
1004 | | - - |
1005 | | - name: Docker meta |
1006 | | - uses: docker/metadata-action@v5 |
1007 | | - with: |
1008 | | - images: name/app |
1009 | | - - |
1010 | | - name: Build |
1011 | | - uses: docker/bake-action@v6 |
1012 | | - with: |
1013 | | - files: | |
1014 | | - ./docker-bake.hcl |
1015 | | - cwd://${{ steps.meta.outputs.bake-file-tags }} |
1016 | | - cwd://${{ steps.meta.outputs.bake-file-annotations }} |
1017 | | - targets: build |
1018 | | -``` |
1019 | | - |
1020 | | -Note that annotations can be attached at many different levels within a manifest. |
1021 | | -By default, the generated annotations will be attached to image manifests, |
1022 | | -but different registries may expect annotations at different places; |
1023 | | -a common practice is to read annotations at _image indexes_ if present, |
1024 | | -which are often used by multi-arch builds to index platform-specific images. |
1025 | | -If you want to specify level(s) for your annotations, you can use the |
1026 | | -[`DOCKER_METADATA_ANNOTATIONS_LEVELS` environment variable](#environment-variables) |
1027 | | -with a comma separated list of all levels the annotations should be attached to (defaults to `manifest`). |
1028 | | -The following configuration demonstrates the ability to attach annotations to both image manifests and image indexes, |
1029 | | -though your registry may only need annotations at the index level. (That is, `index` alone may be enough.) |
1030 | | -Please consult the documentation of your registry. |
1031 | | - |
1032 | | -```yaml |
1033 | | - - |
1034 | | - name: Docker meta |
1035 | | - uses: docker/metadata-action@v5 |
1036 | | - with: |
1037 | | - images: name/app |
1038 | | - env: |
1039 | | - DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index |
1040 | | - - |
1041 | | - name: Build and push |
1042 | | - uses: docker/build-push-action@v6 |
1043 | | - with: |
1044 | | - tags: ${{ steps.meta.outputs.tags }} |
1045 | | - annotations: ${{ steps.meta.outputs.annotations }} |
1046 | | -``` |
1047 | | - |
1048 | | -More information about annotations in the [BuildKit documentation](https://github.com/moby/buildkit/blob/master/docs/annotations.md). |
1049 | | - |
1050 | 1083 | ## Contributing |
1051 | 1084 |
|
1052 | 1085 | Want to contribute? Awesome! You can find information about contributing to |
|
0 commit comments