Skip to content

Commit

Permalink
Various updates =) (#80)
Browse files Browse the repository at this point in the history
* Clear entrypoint when setting command

If a builder image has an entrypoint (say via inheritance from it's base builder image) then in order for the snowdrop buildpack lib to function correctly, we must wipe the entrypoint when setting the command, else we'll invoke the wrong thing.

* Logging updates & DockerConfig fix.

Updates log messages to be less verbose by default, moving some info messages to debug, and adding a few info messages to give overall information on progress
Updates pullTimeout & pullRetryIncrease getters to have correct names of pullTimeoutSeconds and pullRetryIncreaseSeconds. The old names were breaking the generated builder leading to incorrect behavior.
  • Loading branch information
BarDweller authored Aug 15, 2024
1 parent 64a8d1a commit 1d8169b
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 43 deletions.
14 changes: 12 additions & 2 deletions client/src/main/java/dev/snowdrop/buildpack/BuildpackBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ private String selectPlatformLevel(DockerConfig dc, PlatformConfig pc, BuilderIm

public int build(){

log.info("Buildpack build requested with config: \n"+
" - builder "+config.getBuilderImage().getReference()+"\n"+
" - logLevel "+config.getLogConfig().getLogLevel());

log.info("Pulling Builder image");

//obtain & pull & inspect Builder image.
BuilderImage builder = new BuilderImage(config.getDockerConfig(),
config.getPlatformConfig(),
Expand All @@ -77,18 +83,22 @@ public int build(){
config.getPlatformConfig(),
builder);

log.info("Pulling Run Image(s)");

//precache the runimages in the orig builder before extending it.
builder.getRunImages(new Version(activePlatformLevel));

log.debug("Creating Ephemeral Builder Image...");

//create the extended builder image.
BuilderImage extendedBuilder = BuildContainerUtils.createBuildImage(config.getDockerConfig().getDockerClient(),
builder,
null,
null,
null);
try{
log.info("Initiating buildpack build with config \n"+
log.info("Initiating buildpack build with derived configuration: \n"+
" - ephemeralBuilder "+extendedBuilder.getImage().getReference()+"\n"+
" - baseBuilder "+builder.getImage().getReference()+"\n"+
" - activePlatformLevel "+activePlatformLevel+"\n"+
" - build uid:gid "+extendedBuilder.getUserId()+":"+extendedBuilder.getGroupId()+"\n"+
" - withExtensions "+extendedBuilder.hasExtensions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public DockerConfig(
}
}

public Integer getPullTimeout(){
public Integer getPullTimeoutSeconds(){
return this.pullTimeoutSeconds;
}

public Integer getPullRetryCount(){
return this.pullRetryCount;
}

public Integer getPullRetryIncrease(){
public Integer getPullRetryIncreaseSeconds(){
return this.pullRetryIncreaseSeconds;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static void addContentToContainer(DockerClient dc, String containerId, St

public static void addContentToContainer(DockerClient dc, String containerId, String pathInContainer, Integer userId, Integer groupId, ContainerEntry... entries) {

log.info("Adding to container "+containerId+" pathInContainer "+pathInContainer);
log.debug("Adding to container "+containerId+" pathInContainer "+pathInContainer);

Set<String> seenDirs = new HashSet<>();
// Don't add entry for "/", causes issues with tar format.
Expand Down Expand Up @@ -252,7 +252,7 @@ public void run() {
}
};

log.info("Copying archive to container at "+containerPath);
log.debug("Copying archive to container at "+containerPath);

Runnable reader = new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ public static void pullImages(DockerConfig config, String... imageNames) {
if(config.getPullPolicy() == DockerConfig.PullPolicy.IF_NOT_PRESENT) {
// list the current known images
List<Image> li = dc.listImagesCmd().exec();

log.debug("Requested Images "+imageNameSet);
for (Image i : li) {
if (i.getRepoTags() == null) {
continue;
}
for (String it : i.getRepoTags()) {
log.debug("Known Image : "+it);
if (imageNameSet.contains(it)) {
imageNameSet.remove(it);
}
Expand Down Expand Up @@ -82,7 +85,7 @@ public static void pullImages(DockerConfig config, String... imageNames) {
boolean allDone = false;
while(!allDone && retryCount<=config.getPullRetryCount()){
allDone = true;
long thisWait = config.getPullTimeout()+(retryCount*config.getPullRetryIncrease());
long thisWait = config.getPullTimeoutSeconds()+(retryCount*config.getPullRetryIncreaseSeconds());
for (Entry<String, PullImageResultCallback> e : pircMap.entrySet()) {
boolean done = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static boolean internalAddContentToVolume(DockerClient dc, String volume
List<String> command = Stream.of("").collect(Collectors.toList());
String dummyId = ContainerUtils.createContainer(dc, useImage, command, new VolumeBind(volumeName, mountPrefix));
try{
log.info("Adding content to volume "+volumeName+" under prefix "+prefix+" using image "+useImage+" with volume bound at "+mountPrefix+" temp container id "+dummyId);
log.debug("Adding content to volume "+volumeName+" under prefix "+prefix+" using image "+useImage+" with volume bound at "+mountPrefix+" temp container id "+dummyId);
ContainerUtils.addContentToContainer(dc, dummyId, prefix, uid, gid, entries);
return true;
}finally{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public int execute() {
if(rc!=0) break;
}while(false);
}
if(rc==0){
log.info("Buildpack build phases complete, application image is at "+config.getOutputImage().getReference());
}
return rc;
}finally{
//allow factory to clean up any volumes created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ public String getContainerForPhase(String args[], Integer runAsId){
dockerConfig.getDockerNetwork(),
binds);

log.info("- mounted " + buildCacheVolume + " at " + CACHE_VOL_PATH);
log.info("- mounted " + launchCacheVolume + " at " + LAUNCH_CACHE_VOL_PATH);
log.info("- mounted " + kanikoCacheVolume + " at " + KANIKO_VOL_PATH);
log.info("- mounted " + applicationVolume + " at " + WORKSPACE_VOL_PATH);
log.info("- mounted " + platformVolume + " at " + PLATFORM_VOL_PATH);
log.debug("- mounted " + buildCacheVolume + " at " + CACHE_VOL_PATH);
log.debug("- mounted " + launchCacheVolume + " at " + LAUNCH_CACHE_VOL_PATH);
log.debug("- mounted " + kanikoCacheVolume + " at " + KANIKO_VOL_PATH);
log.debug("- mounted " + applicationVolume + " at " + WORKSPACE_VOL_PATH);
log.debug("- mounted " + platformVolume + " at " + PLATFORM_VOL_PATH);
if(dockerConfig.getUseDaemon())
log.info("- mounted " + dockerConfig.getDockerSocket() + " at " + LifecyclePhaseFactory.DOCKER_SOCKET_PATH);
log.info("- mounted " + outputVolume + " at " + LAYERS_VOL_PATH);
log.info("- container id " + id);
log.info("- image reference "+builder.getImage().getReference());
log.debug("- mounted " + dockerConfig.getDockerSocket() + " at " + LifecyclePhaseFactory.DOCKER_SOCKET_PATH);
log.debug("- mounted " + outputVolume + " at " + LAYERS_VOL_PATH);
log.debug("- container id " + id);
log.debug("- image reference "+builder.getImage().getReference());
return id;
}

Expand Down Expand Up @@ -159,13 +159,13 @@ public void createVolumes(List<Content> content){
// add the application to the volume. Note we are placing it at /content,
// because the volume mountpoint is mounted such that the user has no perms to create
// new content there, but subdirs are ok.
log.info("There are "+content.size()+" entries to add for the app dir");
log.debug("There are "+content.size()+" entries to add for the app dir");
List<ContainerEntry> appEntries = content
.stream()
.flatMap(c -> c.getContainerEntries().stream())
.collect(Collectors.toList());

log.info("Adding aplication to volume "+applicationVolume);
log.info("Adding application to volume "+applicationVolume);
VolumeUtils.addContentToVolume(dockerConfig.getDockerClient(),
applicationVolume,
builder.getImage().getReference(),
Expand Down Expand Up @@ -204,7 +204,7 @@ public void createVolumes(List<Content> content){
}

public void tidyUp(){
log.info("- tidying up the build volumes");
log.info("Post Build cleanup activites:");
// remove volumes
// (note when/if we persist the cache between builds, we'll be more selective here over what we remove)
if (buildCacheConfig.getDeleteCacheAfterBuild()) {
Expand All @@ -222,7 +222,7 @@ public void tidyUp(){
VolumeUtils.removeVolume(dockerConfig.getDockerClient(), outputVolume);
VolumeUtils.removeVolume(dockerConfig.getDockerClient(), platformVolume);

log.info("- build volumes tidied up");
log.info("- temporary build volumes removed");
}

public BuilderImage getBuilderImage(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

String id = factory.getContainerForPhase(args.toArray(), runAsId);
try{
log.info("- analyze container id " + id+ " will be run with uid "+runAsId);
log.info("Analyze container id " + id+ " will be run with uid "+runAsId);
log.debug("- container args "+args);

// launch the container!
log.info("- launching analyze container");
Expand All @@ -82,7 +83,7 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

// wait for the container to complete, and retrieve the exit code.
int rc = factory.getDockerConfig().getDockerClient().waitContainerCmd(id).exec(new WaitContainerResultCallback()).awaitStatusCode();
log.info("Buildpack analyze container complete, with exit code " + rc);
log.info("Analyze container complete, with exit code " + rc);

return ContainerStatus.of(rc,id);
}catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us
int runAsId = factory.getBuilderImage().getUserId();
String id = factory.getContainerForPhase(args.toArray(), runAsId);
try{
log.info("- extender container id " + id+ " will be run with uid "+runAsId);
log.info("Builder container id " + id+ " will be run with uid "+runAsId);
log.debug("- container args "+args);

// launch the container!
log.info("- launching builder container");
Expand All @@ -55,7 +56,7 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

// wait for the container to complete, and retrieve the exit code.
int rc = factory.getDockerConfig().getDockerClient().waitContainerCmd(id).exec(new WaitContainerResultCallback()).awaitStatusCode();
log.info("Buildpack builder container complete, with exit code " + rc);
log.info("Builder container complete, with exit code " + rc);

return ContainerStatus.of(rc,id);
}catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us
int runAsId = 0;
String id = factory.getContainerForPhase(args.toArray(), runAsId);
try{
log.info("- creator container id " + id+ " will be run with uid "+runAsId+" and args "+args);
log.info("Creator container id " + id+ " will be run with uid "+runAsId);
log.debug("- container args "+args);

// launch the container!
log.info("- launching build container");
Expand All @@ -67,7 +68,7 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

// wait for the container to complete, and retrieve the exit code.
int rc = factory.getDockerConfig().getDockerClient().waitContainerCmd(id).exec(new WaitContainerResultCallback()).awaitStatusCode();
log.info("Buildpack container complete, with exit code " + rc);
log.info("Creator container complete, with exit code " + rc);

return ContainerStatus.of(rc,id);
}catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us
int runAsId = factory.getBuilderImage().getUserId();
String id = factory.getContainerForPhase(args.toArray(), runAsId);
try{
log.info("- detect container id " + id+ " will be run with uid "+runAsId);
log.info("Detect container id " + id+ " will be run with uid "+runAsId);
log.debug("- container args "+args);

// launch the container!
log.info("- launching detect container");
Expand All @@ -73,7 +74,7 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

// wait for the container to complete, and retrieve the exit code.
int rc = factory.getDockerConfig().getDockerClient().waitContainerCmd(id).exec(new WaitContainerResultCallback()).awaitStatusCode();
log.info("Buildpack detect container complete, with exit code " + rc);
log.info("Detect container complete, with exit code " + rc);

analyzedToml = ContainerUtils.getFileFromContainer(factory.getDockerConfig().getDockerClient(),
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

String id = factory.getContainerForPhase(args.toArray(), runAsId);
try{
log.info("- export container id " + id+ " will be run with uid "+runAsId);
log.info("Export container id " + id+ " will be run with uid "+runAsId);
log.debug("- container args "+args);

// launch the container!
log.info("- launching export container");
Expand All @@ -78,7 +79,7 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

// wait for the container to complete, and retrieve the exit code.
int rc = factory.getDockerConfig().getDockerClient().waitContainerCmd(id).exec(new WaitContainerResultCallback()).awaitStatusCode();
log.info("Buildpack export container complete, with exit code " + rc);
log.info("Export container complete, with exit code " + rc);

return ContainerStatus.of(rc,id);
}catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us
int runAsId = 0;
String id = factory.getContainerForPhase(args.toArray(), runAsId);
try{
log.info("- extender container id " + id+ " will be run with uid "+runAsId);
log.info("Extender container id " + id+ " will be run with uid "+runAsId);
log.debug("- container args "+args);

// launch the container!
log.info("- launching extender container");
Expand All @@ -66,7 +67,7 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

// wait for the container to complete, and retrieve the exit code.
int rc = factory.getDockerConfig().getDockerClient().waitContainerCmd(id).exec(new WaitContainerResultCallback()).awaitStatusCode();
log.info("Buildpack extender container complete, with exit code " + rc);
log.info("Extender container complete, with exit code " + rc);

return ContainerStatus.of(rc,id);
}catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

String id = factory.getContainerForPhase(args.toArray(), runAsId);
try{
log.info("- restorer container id " + id+ " will be run with uid "+runAsId+" and args "+args);
System.out.println("- restorer container id " + id+ " will be run with uid "+runAsId+" and args "+args);
log.info("Restorer container id " + id+ " will be run with uid "+runAsId);
log.debug("- container args "+args);

// launch the container!
log.info("- launching restorer container");
Expand All @@ -79,7 +79,7 @@ public ContainerStatus runPhase(dev.snowdrop.buildpack.Logger logger, boolean us

// wait for the container to complete, and retrieve the exit code.
int rc = factory.getDockerConfig().getDockerClient().waitContainerCmd(id).exec(new WaitContainerResultCallback()).awaitStatusCode();
log.info("Buildpack restorer container complete, with exit code " + rc);
log.info("Restorer container complete, with exit code " + rc);

return ContainerStatus.of(rc,id);
}catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class DockerConfigTest {
@Test
void checkTimeout() {
DockerConfig dc1 = new DockerConfig(null, null, null, null, null, null, null, null, null);
assertEquals(60, dc1.getPullTimeout());
assertEquals(60, dc1.getPullTimeoutSeconds());

DockerConfig dc2 = new DockerConfig(245017, null, null, null, null, null, null, null, null);
assertEquals(dc2.getPullTimeout(), 245017);
assertEquals(dc2.getPullTimeoutSeconds(), 245017);
}

@Test
Expand Down
Loading

0 comments on commit 1d8169b

Please sign in to comment.