Skip to content

Commit ec36059

Browse files
authored
Enables Kokoro integration testing for jib-core. (GoogleContainerTools#88)
1 parent 3ce7512 commit ec36059

7 files changed

Lines changed: 41 additions & 10 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ again.
2525
use your corporate email address here, not your personal address.
2626
2. Fork the repository into your own Github account.
2727
3. Please include unit tests (and integration tests if applicable) for all new code.
28-
4. Make sure all existing tests pass. (./gradlew goJF build integrationTest)
28+
4. Make sure all existing tests pass.
29+
a. In `jib-core`, run `./gradlew clean goJF build integrationTest`
30+
b. In `jib-maven-plugin`, run `./mvnw clean verify`
2931
5. Associate the change with an existing issue or file a [new issue](../../issues)
3032
6. Create a pull request!

‎jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/DockerCredentialRetrieverIntegrationTest.java‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
package com.google.cloud.tools.jib.registry;
1818

1919
import com.google.cloud.tools.jib.http.Authorization;
20+
import com.google.common.io.Resources;
2021
import java.io.IOException;
22+
import java.io.OutputStream;
23+
import java.net.URISyntaxException;
24+
import java.nio.file.Files;
25+
import java.nio.file.Paths;
2126
import org.hamcrest.CoreMatchers;
2227
import org.junit.Assert;
2328
import org.junit.Test;
@@ -29,14 +34,22 @@ public class DockerCredentialRetrieverIntegrationTest {
2934
@Test
3035
public void testRetrieveGCR()
3136
throws IOException, NonexistentServerUrlDockerCredentialHelperException,
32-
NonexistentDockerCredentialHelperException {
37+
NonexistentDockerCredentialHelperException, URISyntaxException, InterruptedException {
38+
// TODO: Refactor
39+
Process process = Runtime.getRuntime().exec("docker-credential-gcr store");
40+
try (OutputStream outputStream = process.getOutputStream()) {
41+
outputStream.write(
42+
Files.readAllBytes(Paths.get(Resources.getResource("credentials.json").toURI())));
43+
}
44+
process.waitFor();
45+
3346
DockerCredentialRetriever dockerCredentialRetriever =
34-
new DockerCredentialRetriever("gcr.io", "gcr");
47+
new DockerCredentialRetriever("myregistry", "gcr");
3548

3649
Authorization authorization = dockerCredentialRetriever.retrieve();
3750

38-
// Checks that some token was received.
39-
Assert.assertTrue(0 < authorization.getToken().length());
51+
// Checks that token received was base64 encoding of "myusername:mysecret".
52+
Assert.assertEquals("bXl1c2VybmFtZTpteXNlY3JldA==", authorization.getToken());
4053
}
4154

4255
@Test
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ServerURL": "myregistry",
3+
"Username": "myusername",
4+
"Secret": "mysecret"
5+
}

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/RetrieveRegistryCredentialsStep.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public Authorization call() throws IOException, NonexistentDockerCredentialHelpe
100100
* docker-credential-[credentialHelperSuffix]}.
101101
*/
102102
private Authorization retrieveFromCredentialHelper(String credentialHelperSuffix)
103-
throws IOException, NonexistentDockerCredentialHelperException {
103+
throws NonexistentDockerCredentialHelperException, IOException {
104104
try {
105105
Authorization authorization =
106106
new DockerCredentialRetriever(registry, credentialHelperSuffix).retrieve();

‎jib-core/src/main/java/com/google/cloud/tools/jib/registry/DockerCredentialRetriever.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.cloud.tools.jib.registry;
1818

1919
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
20-
import com.fasterxml.jackson.databind.JsonMappingException;
20+
import com.fasterxml.jackson.core.JsonProcessingException;
2121
import com.google.cloud.tools.jib.http.Authorization;
2222
import com.google.cloud.tools.jib.http.Authorizations;
2323
import com.google.cloud.tools.jib.json.JsonTemplate;
@@ -101,15 +101,16 @@ public Authorization retrieve()
101101
return Authorizations.withBasicCredentials(
102102
dockerCredentials.Username, dockerCredentials.Secret);
103103

104-
} catch (JsonMappingException ex) {
104+
} catch (JsonProcessingException ex) {
105105
throw new NonexistentServerUrlDockerCredentialHelperException(
106106
credentialHelper, serverUrl, output);
107107
}
108108
}
109109

110110
} catch (IOException ex) {
111111
// Checks if the failure is due to a nonexistent credential helper CLI.
112-
if (ex.getMessage().contains("No such file or directory")) {
112+
if (ex.getMessage().contains("No such file or directory")
113+
|| ex.getMessage().contains("cannot find the file")) {
113114
throw new NonexistentDockerCredentialHelperException(credentialHelperSuffix, ex);
114115
}
115116
throw ex;

‎kokoro/continuous.bat‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ set PATH=%JAVA_HOME%\bin;%PATH%
66

77
cd github/jib
88

9+
REM Stops any left-over containers.
10+
REM FOR /f "tokens=*" %%i IN ('docker ps -q') DO docker rm -vf %%i
11+
12+
REM TODO: Enable integration tests once docker works (b/73345382).
913
cd jib-core && call gradlew.bat clean build publishToMavenLocal --info && ^
1014
cd ../jib-maven-plugin && call mvnw.cmd clean install cobertura:cobertura -B -U -X
1115

‎kokoro/continuous.sh‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
set -e
44
set -x
55

6+
gcloud components install docker-credential-gcr
7+
export PATH=$PATH:/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/
8+
9+
# Stops any left-over containers.
10+
docker stop $(docker container ls --quiet) || true
11+
612
cd github/jib
713

8-
(cd jib-core; ./gradlew clean build publishToMavenLocal --info)
14+
(cd jib-core; ./gradlew clean build integrationTest publishToMavenLocal --info)
915
(cd jib-maven-plugin; ./mvnw clean install cobertura:cobertura -B -U -X)

0 commit comments

Comments
 (0)