Skip to content

Commit 7e895e6

Browse files
authored
Review and improve the existing Buildme sample. (#102)
Signed-off-by: cmoulliard <[email protected]>
1 parent 6e7bb36 commit 7e895e6

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ If you plan to push your image to a registry, then set your registry credential
312312
```bash
313313
export REGISTRY_USERNAME="<REGISTRY_USERNAME>"
314314
export REGISTRY_PASSWORD="<REGISTRY_PASSWORD>"
315-
export REGISTRY_SERVER="docker.io"
315+
export REGISTRY_ADDRESS="docker.io"
316316
```
317317
318318
Execute this command in a terminal:

samples/build-me/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ target/
1313
.vscode/
1414

1515
### Mac OS ###
16-
.DS_Store
16+
.DS_Store
17+
18+
.env

samples/build-me/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ If you plan to push your image to a registry, then set your registry credential
1515
```bash
1616
export REGISTRY_USERNAME="<REGISTRY_USERNAME>"
1717
export REGISTRY_PASSWORD="<REGISTRY_PASSWORD>"
18-
export REGISTRY_SERVER="docker.io"
18+
export REGISTRY_ADDRESS="docker.io"
19+
```
20+
21+
If you prefer that lifecycle don't access the mounted docker socket but talk directly with the container registry to build the image, then set to `false` the following variable:
22+
```shell
23+
export USE_DAEMON=false
1924
```
2025

2126
Execute this command in a terminal:

samples/build-me/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<dependency>
2020
<groupId>dev.snowdrop</groupId>
2121
<artifactId>buildpack-client</artifactId>
22-
<version>0.0.12</version>
22+
<version>0.0.14</version>
2323
</dependency>
2424
<dependency>
2525
<groupId>org.projectlombok</groupId>

samples/build-me/src/main/java/dev/snowdrop/BuildMe.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package dev.snowdrop;
22

33
import java.io.File;
4-
import java.util.HashMap;
5-
import java.util.Map;
4+
import java.util.*;
65
import java.util.stream.Collectors;
76

87
import dev.snowdrop.buildpack.*;
98
import dev.snowdrop.buildpack.config.*;
10-
import dev.snowdrop.buildpack.docker.*;
11-
import dev.snowdrop.buildpack.utils.OperatingSytem;
12-
13-
import static dev.snowdrop.buildpack.docker.DockerClientUtils.getDockerClient;
149

1510
public class BuildMe {
1611

@@ -21,11 +16,12 @@ public static void main(String... args) {
2116
System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack.lifecycle","debug");
2217
System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack.lifecycle.phases","debug");
2318

24-
String REGISTRY_USERNAME = System.getenv("REGISTRY_USERNAME");
25-
String REGISTRY_PASSWORD = System.getenv("REGISTRY_PASSWORD");
26-
String REGISTRY_SERVER = System.getenv("REGISTRY_SERVER");
27-
String IMAGE_REF = System.getenv("IMAGE_REF");
28-
String PROJECT_PATH = System.getenv("PROJECT_PATH");
19+
String IMAGE_REF = Optional.ofNullable(System.getenv("IMAGE_REF"))
20+
.orElseThrow(() -> new IllegalStateException("Missing env var: IMAGE_REF"));
21+
String PROJECT_PATH = Optional.ofNullable(System.getenv("PROJECT_PATH"))
22+
.orElseThrow(() -> new IllegalStateException("Missing env var: PROJECT_PATH"));
23+
String USE_DAEMON = Optional.ofNullable(System.getenv("USE_DAEMON"))
24+
.orElse("true");
2925

3026
Map<String, String> envMap = System.getenv().entrySet().stream()
3127
.filter(entry -> entry.getKey().startsWith("BP_") || entry.getKey().startsWith("CNB_"))
@@ -38,7 +34,7 @@ public static void main(String... args) {
3834

3935
List<RegistryAuthConfig> authInfo = new ArrayList<>();
4036
if(System.getenv("REGISTRY_ADDRESS")!=null){
41-
String registry = System.getenv("REGISTRY_SERVER");
37+
String registry = System.getenv("REGISTRY_ADDRESS");
4238
String username = System.getenv("REGISTRY_USER");
4339
String password = System.getenv("REGISTRY_PASS");
4440
RegistryAuthConfig authConfig = RegistryAuthConfig.builder()
@@ -57,7 +53,7 @@ public static void main(String... args) {
5753
.endPlatformConfig()
5854
.withNewDockerConfig()
5955
.withAuthConfigs(authInfo)
60-
.withUseDaemon(false)
56+
.withUseDaemon(Boolean.parseBoolean(USE_DAEMON))
6157
.endDockerConfig()
6258
.withNewLogConfig()
6359
.withLogger(new SystemLogger())

0 commit comments

Comments
 (0)