diff --git a/README.md b/README.md index 26c6f37..d731c8d 100644 --- a/README.md +++ b/README.md @@ -312,7 +312,7 @@ If you plan to push your image to a registry, then set your registry credential ```bash export REGISTRY_USERNAME="" export REGISTRY_PASSWORD="" -export REGISTRY_SERVER="docker.io" +export REGISTRY_ADDRESS="docker.io" ``` Execute this command in a terminal: diff --git a/samples/build-me/.gitignore b/samples/build-me/.gitignore index 7944f07..dd33a5a 100644 --- a/samples/build-me/.gitignore +++ b/samples/build-me/.gitignore @@ -13,4 +13,6 @@ target/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +.env \ No newline at end of file diff --git a/samples/build-me/README.md b/samples/build-me/README.md index 28609cd..9feadee 100644 --- a/samples/build-me/README.md +++ b/samples/build-me/README.md @@ -15,7 +15,12 @@ If you plan to push your image to a registry, then set your registry credential ```bash export REGISTRY_USERNAME="" export REGISTRY_PASSWORD="" -export REGISTRY_SERVER="docker.io" +export REGISTRY_ADDRESS="docker.io" +``` + +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: +```shell +export USE_DAEMON=false ``` Execute this command in a terminal: diff --git a/samples/build-me/pom.xml b/samples/build-me/pom.xml index 6f44a19..e0fa95b 100644 --- a/samples/build-me/pom.xml +++ b/samples/build-me/pom.xml @@ -19,7 +19,7 @@ dev.snowdrop buildpack-client - 0.0.12 + 0.0.14 org.projectlombok diff --git a/samples/build-me/src/main/java/dev/snowdrop/BuildMe.java b/samples/build-me/src/main/java/dev/snowdrop/BuildMe.java index d85fad9..bb894bd 100644 --- a/samples/build-me/src/main/java/dev/snowdrop/BuildMe.java +++ b/samples/build-me/src/main/java/dev/snowdrop/BuildMe.java @@ -1,16 +1,11 @@ package dev.snowdrop; import java.io.File; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import dev.snowdrop.buildpack.*; import dev.snowdrop.buildpack.config.*; -import dev.snowdrop.buildpack.docker.*; -import dev.snowdrop.buildpack.utils.OperatingSytem; - -import static dev.snowdrop.buildpack.docker.DockerClientUtils.getDockerClient; public class BuildMe { @@ -21,11 +16,12 @@ public static void main(String... args) { System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack.lifecycle","debug"); System.setProperty("org.slf4j.simpleLogger.log.dev.snowdrop.buildpack.lifecycle.phases","debug"); - String REGISTRY_USERNAME = System.getenv("REGISTRY_USERNAME"); - String REGISTRY_PASSWORD = System.getenv("REGISTRY_PASSWORD"); - String REGISTRY_SERVER = System.getenv("REGISTRY_SERVER"); - String IMAGE_REF = System.getenv("IMAGE_REF"); - String PROJECT_PATH = System.getenv("PROJECT_PATH"); + String IMAGE_REF = Optional.ofNullable(System.getenv("IMAGE_REF")) + .orElseThrow(() -> new IllegalStateException("Missing env var: IMAGE_REF")); + String PROJECT_PATH = Optional.ofNullable(System.getenv("PROJECT_PATH")) + .orElseThrow(() -> new IllegalStateException("Missing env var: PROJECT_PATH")); + String USE_DAEMON = Optional.ofNullable(System.getenv("USE_DAEMON")) + .orElse("true"); Map envMap = System.getenv().entrySet().stream() .filter(entry -> entry.getKey().startsWith("BP_") || entry.getKey().startsWith("CNB_")) @@ -38,7 +34,7 @@ public static void main(String... args) { List authInfo = new ArrayList<>(); if(System.getenv("REGISTRY_ADDRESS")!=null){ - String registry = System.getenv("REGISTRY_SERVER"); + String registry = System.getenv("REGISTRY_ADDRESS"); String username = System.getenv("REGISTRY_USER"); String password = System.getenv("REGISTRY_PASS"); RegistryAuthConfig authConfig = RegistryAuthConfig.builder() @@ -57,7 +53,7 @@ public static void main(String... args) { .endPlatformConfig() .withNewDockerConfig() .withAuthConfigs(authInfo) - .withUseDaemon(false) + .withUseDaemon(Boolean.parseBoolean(USE_DAEMON)) .endDockerConfig() .withNewLogConfig() .withLogger(new SystemLogger())