Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFMP-262]: Allow to add labels to the images. #543

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public interface PropertyNames {

String WILDFLY_IMAGE_BINARY = "wildfly.image.binary";

String WILDFLY_IMAGE_LABELS = "wildfly.image.labels";

Comment on lines +111 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but this doesn't need to be here if you'd rather it not be. I had originally created this file for shared properties to ensure the values stay the same, but this is likely not to be shared.

String WILDFLY_LAYERS_CONFIGURATION_FILE_NAME = "wildfly.provisioning.layers.configuration.file.name";

String WILDFLY_ORIGINAL_ARTIFACT_VERSION_RESOLUTION = "wildfly.provisioning.original-artifact-version-resolution";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import static java.lang.String.format;
import static java.lang.String.join;
import static org.wildfly.plugin.common.PropertyNames.WILDFLY_IMAGE_LABELS;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -15,6 +16,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -95,6 +97,9 @@ public class ApplicationImageMojo extends PackageServerMojo {
@Parameter(alias = "image")
private ApplicationImageInfo image;

@Parameter(property = WILDFLY_IMAGE_LABELS, alias = "labels", required = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some Java doc for the plugin documentation. In that it needs a @since 5.0.2.

private List<String> labels = Collections.emptyList();
Comment on lines +100 to +101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a Map<String, String> instead so it can be defined like:

<labels>
    <version>1.0</version>
    <description>&quot;Test description &quot;</description>
</labels>

Also the alias and required aren't really needed.


@Override
protected String getGoal() {
return "image";
Expand Down Expand Up @@ -223,8 +228,13 @@ private void generateDockerfile(String runtimeImage, Path targetDir, String wild

// Create the Dockerfile content
final StringBuilder dockerfileContent = new StringBuilder();
dockerfileContent.append("FROM ").append(runtimeImage).append('\n')
.append("COPY --chown=jboss:root ").append(jbossHome).append(" $JBOSS_HOME\n")
dockerfileContent.append("FROM ").append(runtimeImage).append('\n');
if (labels != null) {
for (String label : labels) {
dockerfileContent.append("LABEL ").append(label).append("\n");
}
}
dockerfileContent.append("COPY --chown=jboss:root ").append(jbossHome).append(" $JBOSS_HOME\n")
.append("RUN chmod -R ug+rwX $JBOSS_HOME\n")
.append("COPY --chown=jboss:root ").append(getDeploymentContent().getFileName())
.append(" $JBOSS_HOME/standalone/deployments/").append(targetName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import static org.wildfly.plugin.tests.AbstractWildFlyMojoTest.getPomFile;

import java.io.ByteArrayOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;

import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -36,7 +38,12 @@ public void testBuildImage() throws Exception {
imageMojo.execute();
Path jbossHome = AbstractWildFlyMojoTest.getBaseDir().resolve("target").resolve("image-server");
assertTrue(jbossHome.toFile().exists());

Path dockerFile = AbstractWildFlyMojoTest.getBaseDir().resolve("target").resolve("Dockerfile");
assertTrue(dockerFile.toFile().exists());
List<String> dockerfileLines = Files.readAllLines(dockerFile);
assertEquals("LABEL version=\"1.0\"", dockerfileLines.get(1));
assertEquals("LABEL description=\"This text illustrates \\", dockerfileLines.get(2));
assertEquals("that label-values can span multiple lines.\"", dockerfileLines.get(3));
final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
assertTrue(ExecUtil.exec(stdout, binary, "inspect", "wildfly-maven-plugin/testing"));
assertEnvironmentUnset(stdout, "SERVER_ARGS=-c=");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<image>
<group>wildfly-maven-plugin</group>
</image>
<labels>
<label>version="1.0"</label>
<label>description="This text illustrates \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but the quotes should be &quot; to be valid XML :)

that label-values can span multiple lines."</label>
</labels>
</configuration>
</plugin>
</plugins>
Expand Down