Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
160d8e49
Commit
160d8e49
authored
Jul 01, 2020
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x'
Closes gh-22180
parents
9981f01a
93171356
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
80 additions
and
23 deletions
+80
-23
BuildOwner.java
...ngframework/boot/buildpack/platform/build/BuildOwner.java
+5
-3
BuilderMetadata.java
...mework/boot/buildpack/platform/build/BuilderMetadata.java
+5
-4
StackId.java
...pringframework/boot/buildpack/platform/build/StackId.java
+2
-4
ImageConfig.java
...work/boot/buildpack/platform/docker/type/ImageConfig.java
+21
-7
BuildOwnerTests.java
...mework/boot/buildpack/platform/build/BuildOwnerTests.java
+5
-4
BuilderMetadataTests.java
...k/boot/buildpack/platform/build/BuilderMetadataTests.java
+4
-1
ImageConfigTests.java
...boot/buildpack/platform/docker/type/ImageConfigTests.java
+19
-0
minimal-image-config.json
.../buildpack/platform/docker/type/minimal-image-config.json
+19
-0
No files found.
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildOwner.java
View file @
160d8e49
...
...
@@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
* The {@link Owner} that should perform the build.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class
BuildOwner
implements
Owner
{
...
...
@@ -49,13 +50,14 @@ class BuildOwner implements Owner {
private
long
getValue
(
Map
<
String
,
String
>
env
,
String
name
)
{
String
value
=
env
.
get
(
name
);
Assert
.
state
(
StringUtils
.
hasText
(
value
),
()
->
"Missing '"
+
name
+
"' value from the builder environment"
);
Assert
.
state
(
StringUtils
.
hasText
(
value
),
()
->
"Missing '"
+
name
+
"' value from the builder environment '"
+
env
+
"'"
);
try
{
return
Long
.
parseLong
(
value
);
}
catch
(
NumberFormatException
ex
)
{
throw
new
IllegalStateException
(
"Malformed '"
+
name
+
"' value '"
+
value
+
"' in the builder environment"
,
ex
);
throw
new
IllegalStateException
(
"Malformed '"
+
name
+
"' value '"
+
value
+
"' in the builder environment '"
+
env
+
"'"
,
ex
);
}
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuilderMetadata.java
View file @
160d8e49
...
...
@@ -18,7 +18,6 @@ package org.springframework.boot.buildpack.platform.build;
import
java.io.IOException
;
import
java.lang.invoke.MethodHandles
;
import
java.util.Map
;
import
java.util.function.Consumer
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
...
...
@@ -30,11 +29,13 @@ import org.springframework.boot.buildpack.platform.docker.type.ImageConfig;
import
org.springframework.boot.buildpack.platform.json.MappedObject
;
import
org.springframework.boot.buildpack.platform.json.SharedObjectMapper
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
/**
* Builder metadata information.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class
BuilderMetadata
extends
MappedObject
{
...
...
@@ -121,9 +122,9 @@ class BuilderMetadata extends MappedObject {
*/
static
BuilderMetadata
fromImageConfig
(
ImageConfig
imageConfig
)
throws
IOException
{
Assert
.
notNull
(
imageConfig
,
"ImageConfig must not be null"
);
Map
<
String
,
String
>
labels
=
imageConfig
.
getLabels
(
);
String
json
=
(
labels
!=
null
)
?
labels
.
get
(
LABEL_NAME
)
:
null
;
Assert
.
notNull
(
json
,
()
->
"No '"
+
LABEL_NAME
+
"' label found in image config
"
);
String
json
=
imageConfig
.
getLabels
().
get
(
LABEL_NAME
);
Assert
.
notNull
(
json
,
()
->
"No '"
+
LABEL_NAME
+
"' label found in image config labels '"
+
StringUtils
.
collectionToCommaDelimitedString
(
imageConfig
.
getLabels
().
keySet
())
+
"'
"
);
return
fromJson
(
json
);
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/StackId.java
View file @
160d8e49
...
...
@@ -16,8 +16,6 @@
package
org
.
springframework
.
boot
.
buildpack
.
platform
.
build
;
import
java.util.Map
;
import
org.springframework.boot.buildpack.platform.docker.type.Image
;
import
org.springframework.boot.buildpack.platform.docker.type.ImageConfig
;
import
org.springframework.util.Assert
;
...
...
@@ -27,6 +25,7 @@ import org.springframework.util.StringUtils;
* A Stack ID.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class
StackId
{
...
...
@@ -75,8 +74,7 @@ class StackId {
* @return the extracted stack ID
*/
private
static
StackId
fromImageConfig
(
ImageConfig
imageConfig
)
{
Map
<
String
,
String
>
labels
=
imageConfig
.
getLabels
();
String
value
=
(
labels
!=
null
)
?
labels
.
get
(
LABEL_NAME
)
:
null
;
String
value
=
imageConfig
.
getLabels
().
get
(
LABEL_NAME
);
Assert
.
state
(
StringUtils
.
hasText
(
value
),
()
->
"Missing '"
+
LABEL_NAME
+
"' stack label"
);
return
new
StackId
(
value
);
}
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/type/ImageConfig.java
View file @
160d8e49
...
...
@@ -31,6 +31,7 @@ import org.springframework.boot.buildpack.platform.json.MappedObject;
* Image configuration information.
*
* @author Phillip Webb
* @author Andy Wilkinson
* @since 2.3.0
*/
public
class
ImageConfig
extends
MappedObject
{
...
...
@@ -39,16 +40,27 @@ public class ImageConfig extends MappedObject {
private
final
Map
<
String
,
String
>
configEnv
;
@SuppressWarnings
(
"unchecked"
)
ImageConfig
(
JsonNode
node
)
{
super
(
node
,
MethodHandles
.
lookup
());
this
.
labels
=
valueAt
(
"/Labels"
,
Map
.
class
);
this
.
labels
=
extractLabels
(
);
this
.
configEnv
=
parseConfigEnv
();
}
@SuppressWarnings
(
"unchecked"
)
private
Map
<
String
,
String
>
extractLabels
()
{
Map
<
String
,
String
>
labels
=
valueAt
(
"/Labels"
,
Map
.
class
);
if
(
labels
==
null
)
{
return
Collections
.
emptyMap
();
}
return
labels
;
}
private
Map
<
String
,
String
>
parseConfigEnv
()
{
Map
<
String
,
String
>
env
=
new
LinkedHashMap
<>();
String
[]
entries
=
valueAt
(
"/Env"
,
String
[].
class
);
if
(
entries
==
null
)
{
return
Collections
.
emptyMap
();
}
Map
<
String
,
String
>
env
=
new
LinkedHashMap
<>();
for
(
String
entry
:
entries
)
{
int
i
=
entry
.
indexOf
(
'='
);
String
name
=
(
i
!=
-
1
)
?
entry
.
substring
(
0
,
i
)
:
entry
;
...
...
@@ -63,16 +75,18 @@ public class ImageConfig extends MappedObject {
}
/**
* Return the image labels.
* @return the image labels
* Return the image labels. If the image has no labels, an empty {@code Map} is
* returned.
* @return the image labels, never {@code null}
*/
public
Map
<
String
,
String
>
getLabels
()
{
return
this
.
labels
;
}
/**
* Return the image environment variables.
* @return the env
* Return the image environment variables. If the image has no environment variables,
* an empty {@code Map} is returned.
* @return the env, never {@code null}
*/
public
Map
<
String
,
String
>
getEnv
()
{
return
this
.
configEnv
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildOwnerTests.java
View file @
160d8e49
...
...
@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* Tests for {@link BuildOwner}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class
BuildOwnerTests
{
...
...
@@ -54,7 +55,7 @@ class BuildOwnerTests {
Map
<
String
,
String
>
env
=
new
LinkedHashMap
<>();
env
.
put
(
"CNB_GROUP_ID"
,
"456"
);
assertThatIllegalStateException
().
isThrownBy
(()
->
BuildOwner
.
fromEnv
(
env
))
.
withMessage
(
"Missing 'CNB_USER_ID' value from the builder environment"
);
.
withMessage
(
"Missing 'CNB_USER_ID' value from the builder environment
'"
+
env
+
"'
"
);
}
@Test
...
...
@@ -62,7 +63,7 @@ class BuildOwnerTests {
Map
<
String
,
String
>
env
=
new
LinkedHashMap
<>();
env
.
put
(
"CNB_USER_ID"
,
"123"
);
assertThatIllegalStateException
().
isThrownBy
(()
->
BuildOwner
.
fromEnv
(
env
))
.
withMessage
(
"Missing 'CNB_GROUP_ID' value from the builder environment"
);
.
withMessage
(
"Missing 'CNB_GROUP_ID' value from the builder environment
'"
+
env
+
"'
"
);
}
@Test
...
...
@@ -71,7 +72,7 @@ class BuildOwnerTests {
env
.
put
(
"CNB_USER_ID"
,
"nope"
);
env
.
put
(
"CNB_GROUP_ID"
,
"456"
);
assertThatIllegalStateException
().
isThrownBy
(()
->
BuildOwner
.
fromEnv
(
env
))
.
withMessage
(
"Malformed 'CNB_USER_ID' value 'nope' in the builder environment"
);
.
withMessage
(
"Malformed 'CNB_USER_ID' value 'nope' in the builder environment
'"
+
env
+
"'
"
);
}
@Test
...
...
@@ -80,7 +81,7 @@ class BuildOwnerTests {
env
.
put
(
"CNB_USER_ID"
,
"123"
);
env
.
put
(
"CNB_GROUP_ID"
,
"nope"
);
assertThatIllegalStateException
().
isThrownBy
(()
->
BuildOwner
.
fromEnv
(
env
))
.
withMessage
(
"Malformed 'CNB_GROUP_ID' value 'nope' in the builder environment"
);
.
withMessage
(
"Malformed 'CNB_GROUP_ID' value 'nope' in the builder environment
'"
+
env
+
"'
"
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java
View file @
160d8e49
...
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
buildpack
.
platform
.
build
;
import
java.io.IOException
;
import
java.util.Collections
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -34,6 +35,7 @@ import static org.mockito.Mockito.mock;
*
* @author Phillip Webb
* @author Scott Frederick
* @author Andy Wilkinson
*/
class
BuilderMetadataTests
extends
AbstractJsonTests
{
...
...
@@ -69,8 +71,9 @@ class BuilderMetadataTests extends AbstractJsonTests {
Image
image
=
mock
(
Image
.
class
);
ImageConfig
imageConfig
=
mock
(
ImageConfig
.
class
);
given
(
image
.
getConfig
()).
willReturn
(
imageConfig
);
given
(
imageConfig
.
getLabels
()).
willReturn
(
Collections
.
singletonMap
(
"alpha"
,
"a"
));
assertThatIllegalArgumentException
().
isThrownBy
(()
->
BuilderMetadata
.
fromImage
(
image
))
.
withMessage
(
"No 'io.buildpacks.builder.metadata' label found in image config"
);
.
withMessage
(
"No 'io.buildpacks.builder.metadata' label found in image config
labels 'alpha'
"
);
}
@Test
...
...
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageConfigTests.java
View file @
160d8e49
...
...
@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.entry;
* Tests for {@link ImageConfig}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class
ImageConfigTests
extends
AbstractJsonTests
{
...
...
@@ -42,6 +43,20 @@ class ImageConfigTests extends AbstractJsonTests {
entry
(
"CNB_STACK_ID"
,
"org.cloudfoundry.stacks.cflinuxfs3"
));
}
@Test
void
whenConfigHasNoEnvThenImageConfigEnvIsEmpty
()
throws
Exception
{
ImageConfig
imageConfig
=
getMinimalImageConfig
();
Map
<
String
,
String
>
env
=
imageConfig
.
getEnv
();
assertThat
(
env
).
isEmpty
();
}
@Test
void
whenConfigHasNoLabelsThenImageConfigLabelsIsEmpty
()
throws
Exception
{
ImageConfig
imageConfig
=
getMinimalImageConfig
();
Map
<
String
,
String
>
env
=
imageConfig
.
getLabels
();
assertThat
(
env
).
isEmpty
();
}
@Test
void
getLabelsReturnsLabels
()
throws
Exception
{
ImageConfig
imageConfig
=
getImageConfig
();
...
...
@@ -63,4 +78,8 @@ class ImageConfigTests extends AbstractJsonTests {
return
new
ImageConfig
(
getObjectMapper
().
readTree
(
getContent
(
"image-config.json"
)));
}
private
ImageConfig
getMinimalImageConfig
()
throws
IOException
{
return
new
ImageConfig
(
getObjectMapper
().
readTree
(
getContent
(
"minimal-image-config.json"
)));
}
}
spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/resources/org/springframework/boot/buildpack/platform/docker/type/minimal-image-config.json
0 → 100644
View file @
160d8e49
{
"Hostname"
:
""
,
"Domainname"
:
""
,
"User"
:
""
,
"AttachStdin"
:
false
,
"AttachStdout"
:
false
,
"AttachStderr"
:
false
,
"Tty"
:
false
,
"OpenStdin"
:
false
,
"StdinOnce"
:
false
,
"Env"
:
null
,
"Cmd"
:
null
,
"Image"
:
""
,
"Volumes"
:
null
,
"WorkingDir"
:
""
,
"Entrypoint"
:
null
,
"OnBuild"
:
null
,
"Labels"
:
null
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment