github.com/goreleaser/goreleaser@v1.25.1/www/docs/customization/ko.md (about)

     1  # Docker Images with Ko
     2  
     3  > Since v1.15
     4  
     5  You can also use [ko][] to build and publish Docker container images.
     6  
     7  Please notice that ko will build your binary again.
     8  That shouldn't increase the release times too much, as it'll use the same build
     9  options as the [build][] pipe when possible, so the results will probably be
    10  cached.
    11  
    12  !!! warning
    13      Ko only runs on the publishing phase, so it might be a bit hard to test —
    14      you might need to push to a fake repository (or a fake tag) when playing
    15      around with its configuration.
    16  
    17  ```yaml
    18  # .goreleaser.yaml
    19  kos:
    20  -
    21    # ID of this image.
    22    id: foo
    23  
    24    # Build ID that should be used to import the build settings.
    25    build: build-id
    26  
    27    # Main path to build.
    28    # It must be a relative path
    29    #
    30    # Default: build.main
    31    main: ./cmd/...
    32  
    33    # Working directory used to build.
    34    #
    35    # Default: build.dir
    36    working_dir: .
    37  
    38    # Base image to publish to use.
    39    #
    40    # Default: 'cgr.dev/chainguard/static'
    41    base_image: alpine
    42  
    43    # Labels for the image.
    44    #
    45    # Since: v1.17
    46    labels:
    47      foo: bar
    48  
    49    # Repository to push to.
    50    #
    51    # Default: $KO_DOCKER_REPO
    52    repository: ghcr.io/foo/bar
    53  
    54    # Platforms to build and publish.
    55    #
    56    # Default: 'linux/amd64'
    57    platforms:
    58    - linux/amd64
    59    - linux/arm64
    60  
    61    # Tag to build and push.
    62    # Empty tags are ignored.
    63    #
    64    # Default: 'latest'
    65    # Templates: allowed
    66    tags:
    67    - latest
    68    - '{{.Tag}}'
    69    - '{{if not .Prerelease}}stable{{end}}'
    70  
    71    # Creation time given to the image
    72    # in seconds since the Unix epoch as a string.
    73    #
    74    # Since: v1.17
    75    # Templates: allowed
    76    creation_time: '{{.CommitTimestamp}}'
    77  
    78    # Creation time given to the files in the kodata directory
    79    # in seconds since the Unix epoch as a string.
    80    #
    81    # Since: v1.17
    82    # Templates: allowed
    83    ko_data_creation_time: '{{.CommitTimestamp}}'
    84  
    85    # SBOM format to use.
    86    #
    87    # Default: 'spdx'
    88    # Valid options are: spdx, cyclonedx, go.version-m and none.
    89    sbom: none
    90  
    91    # Ldflags to use on build.
    92    #
    93    # Default: build.ldflags
    94    ldflags:
    95    - foo
    96    - bar
    97  
    98    # Flags to use on build.
    99    #
   100    # Default: build.flags
   101    flags:
   102    - foo
   103    - bar
   104  
   105    # Env to use on build.
   106    #
   107    # Default: build.env
   108    env:
   109    - FOO=bar
   110    - SOMETHING=value
   111  
   112  
   113    # Bare uses a tag on the $KO_DOCKER_REPO without anything additional.
   114    bare: true
   115  
   116    # Whether to preserve the full import path after the repository name.
   117    preserve_import_paths: true
   118  
   119    # Whether to use the base path without the MD5 hash after the repository name.
   120    base_import_paths: true
   121  ```
   122  
   123  Refer to [ko's project page][ko] for more information.
   124  
   125  
   126  ## Example
   127  
   128  Here's a minimal example:
   129  
   130  ```yaml
   131  # .goreleaser.yml
   132  before:
   133    hooks:
   134      - go mod tidy
   135  
   136  builds:
   137    - env: [ "CGO_ENABLED=1" ]
   138      binary: test
   139      goos:
   140      - darwin
   141      - linux
   142      goarch:
   143      - amd64
   144      - arch64
   145  
   146  kos:
   147    - repository: ghcr.io/caarlos0/test-ko
   148      tags:
   149      - '{{.Version}}'
   150      - latest
   151      bare: true
   152      preserve_import_paths: false
   153      platforms:
   154      - linux/amd64
   155      - linux/arm64
   156  ```
   157  
   158  This will build the binaries for `linux/arm64`, `linux/amd64`, `darwin/amd64`
   159  and `darwin/arm64`, as well as the Docker images and manifest for Linux.
   160  
   161  # Signing KO manifests
   162  
   163  KO will add the built manifest to the artifact list, so you can sign them with
   164  `docker_signs`:
   165  
   166  ```yaml
   167  # .goreleaser.yml
   168  docker_signs:
   169    -
   170      artifacts: manifests
   171  ```
   172  
   173  [ko]: https://ko.build
   174  [build]: /customization/build/