Commit Graph

394 Commits

Author SHA1 Message Date
Scott Frederick
09b627d232 Add support for publishing docker images to a registry
This commit adds options to the Maven and Gradle plugins to publish
to a Docker registry the image generated by the image-building goal
and task.

The Docker registry auth configuration added in an earlier commit
was modified to accept separate auth configs for the builder/run
image and the generated image, since it is likely these images will
be stored in separate registries or repositories with distinct
auth required for each.

Fixes gh-21001
2020-10-07 16:51:33 -05:00
Scott Frederick
54288678d1 Configure Docker host in build plugins
This commit adds the ability to configure the Maven and Gradle
plugins to use a remote Docker daemon using build file
configuration, as an alternative to setting environment variables
to specify remote host connection details.

Fixes gh-23400
2020-09-18 13:51:20 -05:00
Phillip Webb
27095d9043 Polish 2020-09-17 00:31:00 -07:00
Scott Frederick
86fa8144f5 Polish "Support authentication to private Docker registry"
See gh-22972
2020-09-16 16:04:21 -05:00
姜为
e8f555e13d Support authentication to private docker registry
This commit adds the ability to configure Docker image registry
authentication credentials in the Maven and Gradle plugins. The
authentication credentials are passed to the Docker daemon with
all daemon API calls, and the daemon forwards the credentials to the
image registry when necessary. This makes it possible to use
builder and run images stored in a private Docker registry.

See gh-22972
2020-09-16 16:03:40 -05:00
Scott Frederick
b70d0dd5ac Merge branch '2.3.x'
Closes gh-23134
2020-08-28 17:04:57 -05:00
Scott Frederick
bc1834bfdf Ensure layer digest hashes contain 64 characters
This commit ensures that encoded digest hashes for Docker image
layers are zero-padded to the required 64 characters length.

Fixes gh-23132
2020-08-28 17:04:34 -05:00
Scott Frederick
ccabc1a4c9 Merge branch '2.3.x'
Closes gh-23133
2020-08-28 15:18:30 -05:00
Scott Frederick
4f1b4c98ae Fail on Docker image load with empty response
In some cases, a call to the Docker image load API will fail but
return a 200 OK response status code and an empty response. This
commit detects that the response from this call is empty and
treats this condition as an error instead of a silent failure.

Fixes gh-23130
2020-08-28 15:18:02 -05:00
dreis2211
33cd875cb8 Simplify InputStream assertions
See gh-23052
2020-08-24 11:35:17 +02:00
Scott Frederick
ee41d71ea8 Merge branch '2.3.x'
Closes gh-23016
2020-08-19 16:12:44 -05:00
Scott Frederick
56bc0eb9e0 Use canonical path for CNB builder lifecycle binaries
This commit changes the path used to invoke lifecycle binaries in
CNB builders from `/lifecycle` to `/cnb/lifecycle` to conform to
the CNB spec. This will ensure the build plugin image-building
goals and tasks are compatible with future versions of builders
that may not support both paths.

See gh-23009
2020-08-19 16:11:59 -05:00
Scott Frederick
6b15822cb1 Polish "Add pullPolicy option for image building"
See gh-22736
2020-08-12 15:16:38 -05:00
anshlykov
c7449b57ce Add pullPolicy option for image building
This commit adds a pullPolicy option to the configuration of the Maven
plugin spring-boot:build-image goal and the Gradle plugin bootBuildImage
task. The new option gives users control over pulling the builder image
and run image from a remote image registry to the local Docker daemon.

See gh-22736
2020-08-12 15:16:38 -05:00
Andy Wilkinson
969dd35e45 Upgrade to Mockito 3.4.6
Closes gh-22838
2020-08-10 15:22:03 +01:00
Scott Frederick
f247fec310 Merge branch '2.3.x'
Closes gh-22735
2020-08-04 15:30:17 -05:00
Scott Frederick
21b2dd2740 Allow empty env entries when building an image
Prior to this commit, an entry in the environment map provided to the
build plugin image building goal or task that had a null value would
result in a failure with a message that was difficult to diagnose.

This commit treats env map entries with a null value as an empty
entry to prevent the failure and also make it easier to provide an
explicit empty entry in the Maven XML.

Fixes gh-22703
2020-08-04 15:29:29 -05:00
dreis2211
e49e2dfff1 Use Supplier variants of Assert methods
See gh-22699
2020-08-03 15:06:13 +02:00
Phillip Webb
da69286838 Merge branch '2.3.x' 2020-07-22 17:39:27 -07:00
Phillip Webb
d2a7808098 Polish 2020-07-22 17:25:04 -07:00
Scott Frederick
e6318f83b2 Merge branch '2.3.x'
Closes gh-22349
2020-07-15 15:17:16 -05:00
Scott Frederick
bc88af8e53 Restore accidentally deleted line 2020-07-15 15:14:23 -05:00
Scott Frederick
210282260e Fail on bootBuildImage with launch script
This commit adds a check to the support code for the Gradle plugin
bootBuildImage task to ensure that the jar file that will be passed
to a builder is readable and has a valid directory. This prevents a
situation where the jar file cannot be read because it is prepended
with a launch script, and the builder does not receive any files to
process.

Notes have also been added to the Gradle plugin documentation to warn
against using a bootJar launchScript configuration and bootBuildImage
together, as well as caveats about launchScript that match the Maven
plugin documentation.

Fixes gh-22223
2020-07-15 14:58:11 -05:00
Andy Wilkinson
3d2f67f0be Merge branch '2.3.x'
Closes gh-22304
2020-07-10 15:36:49 +01:00
Andy Wilkinson
f18b657ff9 Fix handling of DOCKER_HOST that begins with unix://
Fixes gh-22300
2020-07-10 15:31:55 +01:00
Andy Wilkinson
160d8e49e3 Merge branch '2.3.x'
Closes gh-22180
2020-07-01 11:44:00 +01:00
Andy Wilkinson
9317135690 Improve error handling when builder image isn't a builder
Fixes gh-22179
2020-07-01 11:42:36 +01:00
Phillip Webb
301ec12a0c Merge branch '2.3.x' 2020-06-22 22:37:25 -07:00
Phillip Webb
f296f57401 Rename ImageReferenceParser to Regex
Rename `ImageReferenceParser` to `Regex` and remove state. The regular
expressions are now used directly by the `ImageName` and
`ImageReference` classes with the values accessed directly from the
`Matcher`.

See gh-21495
2020-06-22 22:36:46 -07:00
Scott Frederick
39b2d01541 Merge branch '2.3.x'
Closes gh-22037
2020-06-19 15:43:59 -05:00
dreis2211
a6e8561391 Catch more generic FileSystemException in NamedPipeSocket
See gh-22035
2020-06-19 15:41:20 -05:00
Scott Frederick
73b737c7d8 Merge branch '2.3.x'
Closes gh-22017
2020-06-18 15:11:07 -05:00
Scott Frederick
28643e4d2d Validate image references before passing to CNB builder
Prior to this commit, an image name or run image name derived from
the project name or provided by the user would be passed to the CNB
builder without validation by the Maven plugin build-image goal or
Gradle plugin bootBuildImage task. This could lead to error messages
from the plugins that are difficult to understand and diagnose.

This commit makes parsing of the image names more strict, based on
the grammar implemented by the Docker go library. This provides
validation of the image names before passing them to the builder,
with a more descriptive error message when parsing and validation
fails.

Fixes gh-21495
2020-06-18 15:09:57 -05:00
Andy Wilkinson
07fb4b065d Merge branch '2.3.x'
Closes gh-21940
2020-06-16 10:10:38 +01:00
Andy Wilkinson
0de466e06e Require dependency on s-b-dependencies to use its constraints
Previously, Spring Boot's modules published Gradle Module Metadata
(GMM) the declared a platform dependency on spring-boot-dependencies.
This provided versions for each module's own dependencies but also had
they unwanted side-effect of pulling in spring-boot-dependencies
constraints which would influence the version of other dependencies
declared in the same configuration. This was undesirable as users
should be able to opt in to this level of dependency management, either
by using the dependency management plugin or by using Gradle's built-in
support via a platform dependency on spring-boot-dependencies.

This commit reworks how Spring Boot's build uses
spring-boot-dependencies and spring-boot-parent to provide its own
dependency management. Configurations that aren't seen by consumers are
configured to extend a dependencyManagement configuration that has an
enforced platform dependency on spring-boot-parent. This enforces
spring-boot-parent's version constraints on Spring Boot's build without
making them visible to consumers. To ensure that the versions that
Spring Boot has been built against are visible to consumers, the
Maven publication that produces pom files and GMM for the published
modules is configured to use the resolved versions from the module's
runtime classpath.

Fixes gh-21911
2020-06-16 08:50:21 +01:00
Scott Frederick
838cfc529f Merge branch '2.3.x'
Closes gh-21933
2020-06-15 16:17:39 -05:00
Scott Frederick
6119d69679 Add runImage option for image building
This commit adds a runImage property to the Maven plugin build-image
goal and the Gradle bootBuildImage task. The property allows the user
to override the run image reference provided in the builder metadata
with an alternate run image. The runImage property can be specified
in the build file or on the command line.

Fixes gh-21534
2020-06-15 16:08:56 -05:00
Phillip Webb
3892f4402a Merge branch '2.3.x'
Closes gh-21895
2020-06-11 12:32:41 -07:00
Phillip Webb
1e7da4d3ca Allow digest builder references
Update `BuildRequest` to also allow digest based references.

Closes gh-21879
2020-06-11 12:31:29 -07:00
Scott Frederick
9d9a501b17 Merge branch '2.3.x'
Closes gh-21892
2020-06-11 11:55:20 -05:00
Scott Frederick
7a2939f129 Use non-blocking I/O for Docker API
This commit changes the NamedPipeSocket used for communication with
a local Docker daemon to use a non-blocking AsynchronousByteChannel
instead of a blocking RandomAccessFile, modeled after a similar
change to the docker-java project. This eliminates the potential for
a blocking call to hang indefinitely.

Fixes gh-21672
2020-06-11 11:53:52 -05:00
Phillip Webb
5f79bd2a09 Merge branch '2.3.x'
Closes gh-21734
2020-06-06 11:08:30 -07:00
dreis2211
2b5569f054 Polish
See gh-21732
2020-06-06 11:07:21 -07:00
Scott Frederick
87f5894a9a Merge branch '2.3.x'
Closes gh-21685
2020-06-03 16:54:37 -05:00
Scott Frederick
29253264b4 Improve Docker API 5xx error messages
This commit improves the error messages returned by the Spring Boot
build plugins when a 5xx status code is returned from the Docker
API while attempting to build an image. If the error response has
contents containing a JSON structure with a "message" key, the value
associated with that key will be included in the exception message
and in the build plugin output error.

Fixes gh-21515
2020-06-03 16:53:44 -05:00
Phillip Webb
502e2a4c64 Polish 2020-06-01 14:27:39 -07:00
Scott Frederick
7722394e19 Provide better error message if Docker is not running
Previously, if the Spring Boot build plugins got a connection error
when attempting to communicate with a Docker daemon (for example,
when the daemon isn't running), the error message made it appear that
the daemon returned an HTTP error code. This commit makes a connection
error distinct from an HTTP error response code to make it easier for
the user to diagnose the root cause of the problem.

Fixes gh-21554
2020-05-29 12:37:06 -05:00
Scott Frederick
ed4a7d4ba0 Use default tag when pulling run image
Prior to this commit, a default tag of 'latest' was used when no tag
was included in the builder image name used when building an image in
the Maven and Gradle plugins, but the tag for the run image was left
empty if it was not provided. This resulted in errors when pulling
the run image from an image repository. This commit applies the
same tag defaulting logic to the run image name.

Fixes gh-21532
2020-05-21 17:28:59 -05:00
Phillip Webb
12381467da Polish 2020-05-13 16:48:51 -07:00
Scott Frederick
90ce472252 Support local socket path in DOCKER_HOST
Prior to this commit, if a DOCKER_HOST environment variable was present
when attempting to communicate with a Docker daemon, it was assumed
that the value of that variable was an address that could be used to
create an HTTP connection to a remote daemon. In some cases, the value
of the variable is the path to a local socket file, which would cause
the HTTP connection to fail.

This commit adds additional validation of the value of the DOCKER_HOST
environment variable to determine whether it is a remote address or
a local socket file and create the appropriate connection type.

Fixes gh-21173
2020-05-12 16:11:27 -05:00
Scott Frederick
35bc82a693 Use CNB creator all-in-one lifecycle
This commit modifies the buildpack platform invocation logic used by
the build plugins to invoke the single creator lifecycle introduced in
the CNB API 0.3, instead of invoking discrete lifecycle phases
separately. It also removes support for CNB API 0.2.

Fixes gh-21273
2020-05-08 17:03:47 -05:00
Scott Frederick
0cb090766f Fix typos in mock tests data 2020-04-29 18:08:34 -05:00
Scott Frederick
f3d717e97a Use paketo-buildpacks/builder as default builder
This commit changes the default builder image from
`cloudfoundry/cnb:bionic-platform-api-0.2` to
`gcr.io/paketo-buildpacks/builder:base-platform-api-0.3`. It also
uses a `paketo-buildpacks/builder` image instead of a
`cloudfoundry/cnb` image to test compatibility with lifecycle v2
and uses paketo naming instead of cloudfoundry when mocking builder
interactions.

Some adjustments to lifecycle phases were also made to align more
closely with the pack CLI.

Fixes gh-21066
2020-04-29 14:28:25 -05:00
Phillip Webb
ad1248e4ec Replace "folder" with "directory"
Consistently use the term "directory" instead of "folder"

Closes gh-21218
2020-04-28 19:20:24 -07:00
dreis2211
4b0a31acf8 Delete Toml class
See gh-21129
2020-04-28 11:01:00 +01:00
dreis2211
5eb5bf0a2d Polish
See gh-21009
2020-04-25 08:54:47 +02:00
Johnny Lim
29717423a3 Remove this keyword on member method invocations
See gh-21007
2020-04-25 08:49:44 +02:00
dreis2211
4b9986d790 Remove unused fields in tests
See gh-20926
2020-04-13 13:46:43 +02:00
Cicio Flaviu
7f1655e5cb Add package-info to buildpack.platform.docker.ssl
See gh-20913
2020-04-10 08:57:23 -05:00
Phillip Webb
ffd499fdc7 Attempt to fix failing Windows test 2020-04-06 23:02:12 -07:00
Phillip Webb
5b374e833b Cleanup paths to fix tests running on Windows 2020-04-06 20:33:33 -07:00
Scott Frederick
cc2852ce79 Polish 2020-04-01 18:43:11 -05:00
Scott Frederick
a01c8452cb Support CNB builder platform API 0.3
This commit adds support for Cloud Native Buildpacks builder platform
API 0.3, which is the latest platform API available currently. Support
for platform API 0.1 has been removed, adopting the policy of the pack
CLI to support the current platform API version and one version prior.

Fixes gh-20757
2020-04-01 17:18:46 -05:00
Scott Frederick
bb9e37e119 Use platform API builder image tags
CNB builder images are now being tagged in a manner that indicates
the version of the platform API implemented. This allows Spring Boot
to default to a builder tag that guarantees API compatibility while
allowing for updates to bundled buildpacks.

Fixes gh-20171
2020-04-01 16:18:05 -05:00
Phillip Webb
4dad56a491 Restructure and polish docker code
Restructure and polish docker code to fix a package tangle and
provide better separation of concerns.
2020-04-01 11:51:33 -07:00
Scott Frederick
ed6e54218d Support remote Docker daemon for building images
Prior to this commit, the build plugin goal/task for building images
required a locally running Docker daemon that was accessed via a
non-networked socket or pipe.

This commit adds support for remote Docker daemons at a location
specified by the environment variable `DOCKER_HOST`. Additional
environment variables `DOCKER_TLS_VERIFY` and `DOCKER_CERT_PATH`
are recognized for configuring a secure TLS connection to the daemon.

Fixes gh-20538
2020-03-30 17:06:02 -05:00
Phillip Webb
0717de723f Polish 2020-03-23 20:03:44 -07:00
dreis2211
9588188800 Use isEmpty() where possible
See gh-20370
2020-03-03 18:33:26 -05:00
Scott Frederick
296a13a479 Fix unit test case formatting 2020-02-27 16:43:56 -06:00
Scott Frederick
b00ed5b143 Remove unused imports 2020-02-27 16:17:19 -06:00
Scott Frederick
ada0741e10 Polish Docker client exception handling 2020-02-27 16:09:30 -06:00
Mike Smithson
6f095d6fec Improve error message from image building
Translate IOException to DockerException for a more meaningful error
message when the Docker daemon is not available.

Fixes gh-20151
2020-02-27 15:51:58 -06:00
dreis2211
4f824bf9ad Fix duplicate words
See gh-20210
2020-02-18 13:34:56 +01:00
Scott Frederick
e294d26458 Set ephemeral builder container creation to a fixed date
This commit fixes the `Created` date and time of the ephemeral builder
container image at the Windows epoch plus one second
(1980-01-01T00:00:01Z). This date matches the created date of the builder
image and influences the created date of the resulting image. Using
a fixed date for images ensures that the digest is consistent for all
images with the same version.

Fixes gh-20126
2020-02-12 13:55:54 -06:00
Scott Frederick
191dce3f5e Set Spring Boot version in ephemeral builder
This commit adds a `createdBy` structure to the metadata of the ephemeral
builder container image that identifies Spring Boot as the creator of the
image, along with the Spring Boot version.

See gh-20126
2020-02-12 13:31:21 -06:00
Scott Frederick
12c640e133 Upgrade default image builder version
This commit upgrades the default CNB builder image from
cloudfoundry/cnb:0.0.43-bionic to cloudfoundry/cnb:0.0.53-bionic.
It also adds integration tests for the Maven and Gradle plugins
to verify both versions are supported.
2020-02-06 17:24:29 -06:00
Scott Frederick
d07062652e Add support for CNB platform API v0.2
Cloud Native Buildpacks platform API version 0.2 introduced
two breaking changes: the order of invoking the restore and analyze
phases was reversed, and the cache phase was removed in favor of
distributing caching across other phases.

This commit adds support for Cloud Native Buildpacks builders that
implement platform API version 0.2, while maintaining compatibility
with builders that implement Lifecycle version platform API
version 0.1.

Closes gh-19829
2020-02-06 17:24:29 -06:00
Phillip Webb
cbacab5e26 Polish 2020-01-30 17:14:36 -08:00
Phillip Webb
234c5033d4 Polish whitespace 2020-01-30 17:09:49 -08:00
Scott Frederick
b281af0b9b Remove adding of existing layers to EphemeralBuilder
Layers were being added to the EphemeralBuilder each time one was
created, but those layers already existed in the base builder image.

Closes gh-19832
2020-01-30 16:34:02 -06:00
Andy Wilkinson
2725264be1 Polishing formatting of DockerApi 2020-01-30 14:08:45 +00:00
Andy Wilkinson
28442b5ca5 Lower the minimum required Docker API version to 1.24
Closes gh-19945
2020-01-30 13:57:18 +00:00
Andy Wilkinson
54b3f480b4 Use posix long names when creating tar archive for image building
Fixes gh-19964
2020-01-30 13:31:27 +00:00
Scott Frederick
c6a6024062 Stop image building on error from builder
Previously, the image builder used by the build tool plugins ignored
errors from lifecycle phases and continued with subsequent phases.

This commit inspects the status of the builder container after each
lifecycle phase and aborts the image building process if the exit
status of the container after any phase is non-zero.

Fixes #19949
2020-01-29 17:51:32 -06:00
dreis2211
d8e2349e47 Use Supplier variants of Assert
See gh-19864
2020-01-28 15:04:11 +01:00
Andy Wilkinson
63b736d1f0 Fix NPE when waiting for named socket path to become available
Fixes gh-19941
2020-01-27 11:38:19 +00:00
Stephane Nicoll
3290313eb7 Fix Docker socket creation on Windows
Closes gh-19908
2020-01-27 07:29:16 +01:00
Andy Wilkinson
0a9fe65443 Use line endings on all OSs when writing image config JSON
Previously \r\n was used on Windows and \n was used on other
platforms. This resulted in different JSON content being written to
the archive. As the config's entry name is the SHA-256 hash of its
content, it also resulted in the entry name being different.

This commit updates the JSON that's written into the archive to use
\n line endings, irrespective of the OS on which the image is being
built.

See gh-19828
2020-01-23 14:37:06 +00:00
Andy Wilkinson
a0b4cdee44 Make line ending expectations in TotalProgressBarTests OS-independent
See gh-19828
2020-01-23 14:14:14 +00:00
Stephane Nicoll
105db66553 Polish 2020-01-23 14:04:19 +01:00
Andy Wilkinson
0bd0b2a6c0 Add support for building OCI images using the Gradle plugin
Closes gh-19831
2020-01-23 10:52:57 +00:00
Phillip Webb
e0013454b5 Use parentheses when declaring dependencies
Update all dependencies declarations to use the form `scope(reference)`
rather than `scope reference`.

Prior to this commit we declared dependencies without parentheses unless
we were forced to add them due to an `exclude`.
2020-01-22 16:02:38 -08:00
Phillip Webb
0209cd3e4c Polish quote form used in Gradle scripts
Replace Gradle single quote strings with the double quote form
whenever possible. The change helps to being consistency to the
dependencies section where mostly single quotes were used, but
occasionally double quotes were required due to `${}` references.
2020-01-22 15:49:52 -08:00
Phillip Webb
e28338d6cd Rename spring-boot-cloudnativebuildpack
Rename the `spring-boot-cloudnativebuildpack` module to
`spring-boot-buildpack-platform` and update the the package
name to `org.springframework.boot.buildpack.platform`.

Closes gh-19851
2020-01-22 11:01:32 -08:00