Skip to content

Commit

Permalink
Capture Docker Compose version information in a custom value
Browse files Browse the repository at this point in the history
Closes gh-80
  • Loading branch information
wilkinsona committed May 14, 2024
1 parent 54acfdb commit d6c72eb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void execute(BuildScanConfiguration buildScan) {
tagBuildScan(buildScan, ci);
buildScan.background(this::addGitMetadata);
buildScan.background(this::addDockerMetadata);
buildScan.background(this::addDockerComposeMetadata);
addCiMetadata(buildScan, ci);
buildScan.getUploadInBackground().set(ci == null);
buildScan.capture((settings) -> settings.getFileFingerprints().set(true));
Expand Down Expand Up @@ -127,6 +128,11 @@ private void addDockerMetadata(BuildScanConfiguration buildScan) {
run("docker", "--version").standardOut((dockerVersion) -> buildScan.value("Docker", dockerVersion));
}

private void addDockerComposeMetadata(BuildScanConfiguration buildScan) {
run("docker", "compose", "version")
.standardOut((dockerComposeVersion) -> buildScan.value("Docker Compose", dockerComposeVersion));
}

private void addCiMetadata(BuildScanConfiguration buildScan, ContinuousIntegration ci) {
if (ci == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 the original author or authors.
* Copyright 2020-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.util.function.Consumer;

import org.gradle.api.internal.ProcessOperations;
import org.gradle.process.ExecResult;
import org.gradle.process.ExecSpec;

/**
Expand All @@ -38,7 +39,7 @@ class ProcessOperationsProcessRunner implements ProcessRunner {
@Override
public void run(Consumer<ProcessSpec> configurer) {
try {
this.processOperations.exec((spec) -> configurer.accept(new ExecSpecProcessSpec(spec)));
ExecResult exec = this.processOperations.exec((spec) -> configurer.accept(new ExecSpecProcessSpec(spec)));
}
catch (Exception ex) {
throw new RunFailedException(ex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 the original author or authors.
* Copyright 2020-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,6 +55,10 @@ interface ProcessSpec {

class RunFailedException extends RuntimeException {

RunFailedException() {

}

RunFailedException(Exception cause) {
super(cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,24 @@ void whenDockerIsNotAvailableThenConventionsCanBeAppliedWithoutFailure() {
assertThat(this.buildScan.values).doesNotContainKey("Docker");
}

@Test
void buildScanHasDockerComposeCustomValue() {
this.processRunner.commandLineOutput.put(Arrays.asList("docker", "compose", "version"),
"Docker Compose version v2.17.2");
new BuildScanConventions(this.develocity, this.processRunner).execute(this.buildScan);
assertThat(this.buildScan.values).containsEntry("Docker Compose", "Docker Compose version v2.17.2");
}

@Test
void whenDockerComposeIsNotAvailableThenConventionsCanBeAppliedWithoutFailure() {
this.processRunner.failures.put(Arrays.asList("docker", "compose", "version"),
new RuntimeException("docker compose is not available"));
new BuildScanConventions(this.develocity, this.processRunner).execute(this.buildScan);
assertThatNoException()
.isThrownBy(() -> new BuildScanConventions(this.develocity, this.processRunner).execute(this.buildScan));
assertThat(this.buildScan.values).doesNotContainKey("Docker Compose");
}

@Test
void whenBuildingLocallyThenBackgroundUploadIsEnabled() {
new BuildScanConventions(this.develocity, this.processRunner, Collections.emptyMap()).execute(this.buildScan);
Expand Down

0 comments on commit d6c72eb

Please sign in to comment.