Skip to content

Commit

Permalink
Maven release v0.9.13 (#1153)
Browse files Browse the repository at this point in the history
* Fix missing env in maven docker context generator

* preparing release 0.9.13

* 0.9.14-SNAPSHOT

* Make exposed ports and labels nullable in JavaDockerContextGenerator
  • Loading branch information
TadCordle authored Oct 16, 2018
1 parent 055440c commit 695e815
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -133,10 +132,10 @@ private static String mapToDockerfileString(Map<String, String> map, String comm
@Nullable private String baseImage;
@Nullable private List<String> entrypoint;
@Nullable private List<String> programArguments;
@Nullable private Map<String, String> environment;
@Nullable private String user;
private Map<String, String> environment = Collections.emptyMap();
private List<String> exposedPorts = Collections.emptyList();
private Map<String, String> labels = Collections.emptyMap();
@Nullable private List<String> exposedPorts;
@Nullable private Map<String, String> labels;

/**
* Constructs a Docker context generator for a Java application.
Expand Down Expand Up @@ -219,7 +218,7 @@ public JavaDockerContextGenerator setProgramArguments(@Nullable List<String> pro
* @param environment map from the environment variable name to value
* @return this
*/
public JavaDockerContextGenerator setEnvironment(Map<String, String> environment) {
public JavaDockerContextGenerator setEnvironment(@Nullable Map<String, String> environment) {
this.environment = environment;
return this;
}
Expand All @@ -230,7 +229,7 @@ public JavaDockerContextGenerator setEnvironment(Map<String, String> environment
* @param exposedPorts the list of port numbers/port ranges to expose
* @return this
*/
public JavaDockerContextGenerator setExposedPorts(List<String> exposedPorts) {
public JavaDockerContextGenerator setExposedPorts(@Nullable List<String> exposedPorts) {
this.exposedPorts = exposedPorts;
return this;
}
Expand All @@ -241,7 +240,7 @@ public JavaDockerContextGenerator setExposedPorts(List<String> exposedPorts) {
* @param labels the map of labels
* @return this
*/
public JavaDockerContextGenerator setLabels(Map<String, String> labels) {
public JavaDockerContextGenerator setLabels(@Nullable Map<String, String> labels) {
this.labels = labels;
return this;
}
Expand Down Expand Up @@ -332,12 +331,18 @@ String makeDockerfile() throws JsonProcessingException {
}

dockerfile.append("\n");
for (String port : exposedPorts) {
dockerfile.append("\nEXPOSE ").append(port);
if (exposedPorts != null) {
for (String port : exposedPorts) {
dockerfile.append("\nEXPOSE ").append(port);
}
}

dockerfile.append(mapToDockerfileString(environment, "ENV"));
dockerfile.append(mapToDockerfileString(labels, "LABEL"));
if (environment != null) {
dockerfile.append(mapToDockerfileString(environment, "ENV"));
}
if (labels != null) {
dockerfile.append(mapToDockerfileString(labels, "LABEL"));
}
if (entrypoint != null) {
dockerfile.append("\nENTRYPOINT ").append(objectMapper.writeValueAsString(entrypoint));
}
Expand Down
6 changes: 6 additions & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ All notable changes to this project will be documented in this file.

### Fixed

## 0.9.13

### Fixed

- Adds environment variable configuration to Docker context generator ([#890 (comment)](https://github.com/GoogleContainerTools/jib/issues/890#issuecomment-430227555))

## 0.9.11

### Added
Expand Down
2 changes: 1 addition & 1 deletion jib-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>0.9.12-SNAPSHOT</version>
<version>0.9.14-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Jib</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void execute() throws MojoExecutionException {
.setEntrypoint(entrypoint)
.setProgramArguments(getArgs())
.setExposedPorts(getExposedPorts())
.setEnvironment(getEnvironment())
.setLabels(getLabels())
.setUser(getUser())
.generate(Paths.get(targetDir));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package com.google.cloud.tools.jib.maven;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.maven.model.Build;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -119,6 +121,11 @@ public void testGenerateDockerContext_errorOnWindowsAppRootWithDriveLetter() {
}

@Test
public void testGeneratedDockerContext_env() throws MojoExecutionException, IOException {
mojo.execute();
Assert.assertEquals("ENV envKey=\"envVal\"", getDockerfileLine("ENV"));
}

public void testBaseImage_nonWarPackaging() throws MojoExecutionException, IOException {
mojo.execute();

Expand Down Expand Up @@ -234,6 +241,11 @@ String getMainClass() {
String getAppRoot() {
return appRoot;
}

@Override
Map<String, String> getEnvironment() {
return ImmutableMap.of("envKey", "envVal");
}
}

@Nullable
Expand Down

0 comments on commit 695e815

Please sign in to comment.