https://github.com/chonton/buildx-maven-plugin
Use buildx to create container images
https://github.com/chonton/buildx-maven-plugin
Last synced: 3 months ago
JSON representation
Use buildx to create container images
- Host: GitHub
- URL: https://github.com/chonton/buildx-maven-plugin
- Owner: chonton
- License: apache-2.0
- Created: 2025-01-12T05:03:55.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-20T00:07:26.000Z (4 months ago)
- Last Synced: 2025-01-20T01:20:28.614Z (4 months ago)
- Language: Java
- Size: 683 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# buildx-maven-plugin
Build and push images using docker or podman buildx. This plugin has four goals:
1. [Login to registry](#login-goal)
2. [Create Containerfile from base image and copy directives](#containerfile-goal)
3. [Build image from Containerfile and context](#build-goal)
4. [Push image to registry](#push-goal)# Rationale
Build images using [docker buildx](https://docs.docker.com/reference/cli/docker/buildx/) or
[podman build](https://docs.podman.io/en/stable/markdown/podman-build.1.html) with this
plugin's [containerfile](#containerfile-goal) and [build](#build-goal) goals.# Plugin Reports
Plugin reports available at
[plugin info](https://chonton.github.io/buildx-maven-plugin/plugin-info.html).## Login Goal
The [login](https://chonton.github.io/buildx-maven-plugin/login-mojo.html) goal binds by default to
the **prepare-package** phase. This goal executes `docker login` or `podman login` with credentials
from **settings.xml** or specified in the configuration.### Login Configuration from settings.xml
Maven's [settings.xml](https://maven.apache.org/settings.html) contains items that are not specific
to a project or that should not be distributed to artifact consumers. This plugin will read the
[servers](https://maven.apache.org/settings.html#servers) element of settings.xml to find a server
element with an `` element that matches the registry. If found, the `` and
`` from that server element will be used. (The password is
[decrypted](https://maven.apache.org/guides/mini/guide-encryption.html) if needed.)### Login Configuration from pom.xml
| Parameter | Required | Description |
|-----------:|:--------:|:-------------------------------------------------------|
| registry | ✓ | Registry to authenticate with |
| password | | If registry not found in settings.xml, use as password |
| skip | | Skip login |
| username | | If registry not found in settings.xml, use as username |## Containerfile Goal
The [containerfile](https://chonton.github.io/buildx-maven-plugin/containerfile-mojo.html) goal
binds by default to the **prepare-package** phase.
This goal creates *${project.build.directory}/context/Containerfile* from the configuration.
See [Containerfile](https://github.com/containers/common/blob/main/docs/Containerfile.5.md) for more
information about Containerfile syntax.### Containerfile Configuration
| Parameter | Description |
|--------------:|:---------------------------------------------------------------------------------------|
| cli | Container command, default is **docker**. (**podman** is supported) |
| containerFile | Instruction file relative to context, default is **Dockerfile** (or **Containerfile**) |
| context | Directory with build content, default is `${project.build.directory}/context` |
| contexts | Map of additional context names to locations | |
| cmd | Default [ShellOrExec Config](#shellorexec-config) command |
| entrypoint | Default [ShellOrExec Config](#shellorexec-config) entrypoint |
| from | Base image for subsequent instructions |
| layers | List of [Layer Config](#layer-config) to apply |
| labels | Map of labels to apply to image |
| env | Map of environment variables that are set when container runs |
| user | User\[:Group] that runs inside the container. May be uid or name |
| expose | List of ports that the container will expose |
| volumes | List of locations in the image filesystem for external mounts |
| workDir | Working directory for the container's process |### Layer Config
| Parameter | Required | Description |
|----------:|:--------:|:--------------------------------------------------------------------------|
| chown | | Owner\[:Group] of the files in the image |
| chmod | | Permissions of the files in the image |
| srcs | ✓ | Files relative to the context to be copied. (golang wildcards supported) |
| dest | ✓ | Absolute destination in the image where files are copied |### ShellOrExec Config
| Parameter | Required | Description |
|----------:|:----------:|:-----------------------------------------------------------------|
| exec | ✓ or shell | List of Executable and parameters, no shell involved |
| shell | ✓ or cmd | Single line command executed by shell (unused if exec specified) |## Build Goal
The [build](https://chonton.github.io/buildx-maven-plugin/build-mojo.html) goal binds by
default to the **package** phase. This goal executes `docker build buildx`.### Build Configuration
| Parameter | Description |
|---------------:|:---------------------------------------------------------------------------------------|
| buildArguments | Map of build arguments |
| builder | Name of an already defined docker buildx builder |
| cli | Container command, default is **docker**. (**podman** is supported) |
| containerFile | Instruction file relative to context, default is **Dockerfile** (or **Containerfile**) |
| context | Directory with build content, default is `${project.build.directory}/context` |
| contexts | Map of additional context names to locations |
| image | Fully qualified image name; must include *registry/repository:version* |
| load | If set to true, load the local docker image cache with resulting image |
| platforms | List of platforms. Each element may contain comma separated *os/arch* |
| provenance | Level of provenance attestation to add. May be false, min, or max |
| sbom | Add software bill of materials attestation to add |
| skip | Skip build |## Push Goal
The [push](https://chonton.github.io/buildx-maven-plugin/push-mojo.html) goal binds by
default to the **deploy** phase. This goal uses `docker buildx` to push an image to its registry.### Push Configuration
| Parameter | Description |
|----------:|:-----------------------------------------------------------------|
| image | The fully qualified image name, with registry/repository:version |
| skip | Skip push |# Examples
## Typical Use
```xml
org.honton.chas
buildx-maven-plugin
0.0.5
org.honton.chas
buildx-maven-plugin
build-java-based-containerfile
containerfile
registry.access.redhat.com/ubi8/openjdk-11:1.15
nobody
target/quarkus-app/lib/
/deployments/lib/
nobody
target/quarkus-app/*.jar
/deployments/
nobody
target/quarkus-app/app/
/deployments/app/
nobody
target/quarkus-app/quarkus/
/deployments/quarkus/
8080
/work/
nobody
build-java-based-container
build
login
push
target/quarkus-app
artifactory.example.com/dev/${project.artifactId}:${project.version}
${build.platforms}
```