Nx Tools
API/Executors/build

build

Build an OCI image from a Dockerfile.

Options can be configured in project.json when defining the executor, or when invoking it. Read more about how to configure targets and executors here: https://nx.dev/reference/project-configuration#targets.

Note

This executor not handle registry login steps, so if you wanna push your container images to a remote registry, please setup the credentials using the docker login or podman login.

Examples

You may want your build result to be available in the Docker client through docker images to be able to use it in another step of your workflow:

apps/your-app/project.json
"container": {
  "executor": "@nx-tools/nx-container:build",
  "options": {
    "load": true,
    "tags": ["image-name:latest"],
  }
}

The following config will connect you to DockerHub and GitHub Container Registry and push the image to these registries.

apps/your-app/project.json
"container": {
  "executor": "@nx-tools/nx-container:build",
  "options": {
    "push": true,
    "tags": [
      "user/app:latest",
      "user/app:1.0.0",
      "ghcr.io/user/app:latest",
      "ghcr.io/user/app:1.0.0"
    ],
  }
}

If you want an "automatic" tag management and OCI Image Format Specification for labels, you can do it with a dedicated configuration option. The following config will use the Docker metadata package to handle tags and labels based on CI events and Git metadata.

apps/your-app/project.json
"container": {
  "executor": "@nx-tools/nx-container:build",
  "options": {
    "push": true,
    "metadata": {
      "images": ["name/app", "ghcr.io/username/app"],
      "tags": [
        "type=schedule",
        "type=ref,event=branch",
        "type=ref,event=tag",
        "type=ref,event=pr",
        "type=semver,pattern={{version}}",
        "type=semver,pattern={{major}}.{{minor}}",
        "type=semver,pattern={{major}}",
        "type=sha"
      ]
    }
  }
}

Options:

All options described here, can be customized using environment variables or values in your project.json. Environment variables takes precedence over harcoded values.

Tip!

All environment values needs to be prefixed with INPUT_ so INPUT_PUSH=true will replace the options.push value of your project.json file

Note: For list values use a comma-delimited string, like INPUT_PLATFORMS=linux/amd64,linux/arm64. For INPUT_BUILD_ARGS and INPUT_TAGS use a newline-delimited string. See FAQ page for more information.

Note: Replace a dash (-) with an underscore in environment variables, like INPUT_CACHE_FROM='type=gha'

PropTypeDefault
metadata?
Metadata
-
ulimit?
string[]
-
target?
string
-
tags?
string[]
-
ssh?
string[]
-
shm-size?
string
-
secret-files?
string[]
-
secrets?
string[]
-
sbom?
boolean
false
push?
boolean
false
pull?
boolean
false
provenance?
string
-
platforms?
string[]
-
outputs?
string[]
-
no-cache-filters?
string[]
-
no-cache?
boolean
false
network?
string
-
load?
boolean
false
labels?
string[]
-
file?
string
Dockerfile
context?
string
.
cgroup-parent?
string
-
cache-to?
string | string[]
-
cache-from?
string | string[]
-
builder?
string
-
build-contexts?
string[]
-
build-args?
string[]
-
allow?
string[]
-
add-hosts?
string[]
-
quiet?
boolean
false
engine?
"docker" | "podman"
docker

Metadata

PropTypeDefault
bake-target?
string
container-metadata-action
sep-labels?
string
\n
sep-tags?
string
\n
labels?
string[]
-
flavor?
string[]
-
tags?
string[]
-
images?
string[]
-

Last updated on