Skip to content

The Unified and Autonomous Development Platform

feat: Multi-platform support for trivy image scanner

Robin Shenfcd34b311b56
diff --git a/pom.xml b/pom.xml
index b4f6b4db12..0a2de726de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -637,7 +637,7 @@
</repositories>
<properties>
<commons.version>3.0.2</commons.version>
- <agent.version>2.0.6</agent.version>
+ <agent.version>2.0.7</agent.version>
<slf4j.version>2.0.9</slf4j.version>
<logback.version>1.4.14</logback.version>
<antlr.version>4.7.2</antlr.version>
diff --git a/server-core/src/main/java/io/onedev/server/annotation/NoSpace.java b/server-core/src/main/java/io/onedev/server/annotation/NoSpace.java
new file mode 100644
index 0000000000..686f84ec8d
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/annotation/NoSpace.java
@@ -0,0 +1,22 @@
+package io.onedev.server.annotation;
+
+import io.onedev.server.validation.validator.NoSpaceValidator;
+
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+@Constraint(validatedBy= NoSpaceValidator.class)
+public @interface NoSpace {
+
+ String message() default "";
+
+ Class<?>[] groups() default {};
+
+ Class<? extends Payload>[] payload() default {};
+}
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/BuildSpec.java b/server-core/src/main/java/io/onedev/server/buildspec/BuildSpec.java
index cdf440d26b..b079ce46a9 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/BuildSpec.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/BuildSpec.java
@@ -2021,7 +2021,7 @@ public class BuildSpec implements Serializable, Validatable {
if (propName.equals("tags")) {
tags = ((ScalarNode)stepTuple.getValueNode()).getValue();
itStepTuple.remove();
- } else if (propName.equals("publish")) {
+ } else if (propName.equals("publish") || propName.equals("removeDanglingImages")) {
itStepTuple.remove();
}
}
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageStep.java b/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageStep.java
index bcb20ad4e4..05474aa815 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageStep.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageStep.java
@@ -37,7 +37,7 @@ public class BuildImageStep extends Step {
private String builtInRegistryAccessTokenSecret;
- private boolean removeDanglingImages = true;
+ private String platforms;
private String moreOptions;
@@ -96,20 +96,24 @@ public class BuildImageStep extends Step {
return "Optionally specify a secret to be used as access token for built-in registry server " +
"<code>" + server + "</code>";
}
-
- @Editable(order=1100, name="Remove Dangling Images After Build", group = "More Settings")
- public boolean isRemoveDanglingImages() {
- return removeDanglingImages;
+
+ @Editable(order=1300, group = "More Settings", placeholder = "Current platform", description = "Optionally specify " +
+ "<span class='text-info'>comma separated</span> platforms to build, for instance <tt>linux/amd64,linux/arm64</tt>. " +
+ "Leave empty to build for platform of the node running the job")
+ @Interpolative(variableSuggester="suggestVariables")
+ @NoSpace
+ public String getPlatforms() {
+ return platforms;
}
- public void setRemoveDanglingImages(boolean removeDanglingImages) {
- this.removeDanglingImages = removeDanglingImages;
+ public void setPlatforms(String platforms) {
+ this.platforms = platforms;
}
- @Editable(order=1200, group = "More Settings", description="Optionally specify additional options to build image, " +
- "separated by spaces. For instance <code>--platform</code> can be used to build multi-arch images")
+ @Editable(order=1400, group = "More Settings", description="Optionally specify additional options for " +
+ "buildx build command")
@Interpolative(variableSuggester="suggestVariables")
- @ReservedOptions({"--builder", "--push", "-f", "--file", "(-f|--file)=.*", "-t", "--tag", "(-t|--tag)=.*"})
+ @ReservedOptions({"--builder", "(--builder)=.*", "--platform", "(--platform)=.*", "--push", "-f", "--file", "(-f|--file)=.*", "-t", "--tag", "(-t|--tag)=.*", "-o", "--output", "(-o|--output)=.*"})
public String getMoreOptions() {
return moreOptions;
}
@@ -130,7 +134,7 @@ public class BuildImageStep extends Step {
else
accessToken = null;
return new BuildImageFacade(getBuildPath(), getDockerfile(), getOutput().getFacade(),
- isRemoveDanglingImages(), accessToken, getMoreOptions());
+ accessToken, getPlatforms(), getMoreOptions());
}
@Editable
@@ -177,8 +181,9 @@ public class BuildImageStep extends Step {
private String destPath;
- @Editable(name="OCI Layout Directory", description = "Specify path relative to <a href='https://docs.onedev.io/concepts#job-workspace' target='_blank'>job workspace</a> to store OCI layout")
+ @Editable(name="OCI Layout Directory", description = "Specify relative path under <a href='https://docs.onedev.io/concepts#job-workspace' target='_blank'>job workspace</a> to store OCI layout")
@SubPath
+ @NoSpace
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getDestPath() {
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageWithKanikoStep.java b/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageWithKanikoStep.java
index c7d81a6ae8..4afb8e05f2 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageWithKanikoStep.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/step/BuildImageWithKanikoStep.java
@@ -216,8 +216,10 @@ public class BuildImageWithKanikoStep extends CommandStep {
private String destPath;
- @Editable(name="OCI Layout Directory", description = "Specify path relative to <a href='https://docs.onedev.io/concepts#job-workspace' target='_blank'>job workspace</a> to store OCI layout")
+ @Editable(name="OCI Layout Directory", description = "Specify relative path under <a href='https://docs.onedev.io/concepts#job-workspace' target='_blank'>job workspace</a> to store OCI layout")
@Interpolative(variableSuggester="suggestVariables")
+ @SubPath
+ @NoSpace
@NotEmpty
public String getDestPath() {
return destPath;
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/step/CheckoutStep.java b/server-core/src/main/java/io/onedev/server/buildspec/step/CheckoutStep.java
index 5e1e815289..962dcf6603 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/step/CheckoutStep.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/step/CheckoutStep.java
@@ -72,7 +72,7 @@ public class CheckoutStep extends Step {
this.cloneDepth = cloneDepth;
}
- @Editable(order=300, placeholder="Job workspace", description="Optionally specify path relative to "
+ @Editable(order=300, placeholder="Job workspace", description="Optionally specify relative path under "
+ "<a href='https://docs.onedev.io/concepts#job-workspace'>job workspace</a> to clone code into. "
+ "Leave empty to use job workspace itself")
@Interpolative(variableSuggester="suggestVariables")
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/step/PullImageStep.java b/server-core/src/main/java/io/onedev/server/buildspec/step/PullImageStep.java
index 7ac59b52b6..41fc4ca1ad 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/step/PullImageStep.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/step/PullImageStep.java
@@ -1,9 +1,7 @@
package io.onedev.server.buildspec.step;
import io.onedev.commons.codeassist.InputSuggestion;
-import io.onedev.server.annotation.Editable;
-import io.onedev.server.annotation.Interpolative;
-import io.onedev.server.annotation.ReservedOptions;
+import io.onedev.server.annotation.*;
import io.onedev.server.buildspec.BuildSpec;
import javax.validation.constraints.NotEmpty;
@@ -21,9 +19,12 @@ public class PullImageStep extends CraneStep {
private String destPath;
+ private String platform;
+
private String moreOptions;
- @Editable(order=100, name="Source Docker Image", description="Specify source docker image to pull from")
+ @Editable(order=100, name="Source Docker Image", description="Specify full tag of source docker image to pull from, " +
+ "for instance <tt>registry-server/org/repo:tag</tt>")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getSrcImage() {
@@ -36,6 +37,8 @@ public class PullImageStep extends CraneStep {
@Editable(order=200, name="OCI Layout Directory", description = "Specify directory relative to <a href='https://docs.onedev.io/concepts#job-workspace' target='_blank'>job workspace</a> to store OCI layout")
@Interpolative(variableSuggester="suggestVariables")
+ @SubPath
+ @NoSpace
@NotEmpty
public String getDestPath() {
return destPath;
@@ -45,9 +48,22 @@ public class PullImageStep extends CraneStep {
this.destPath = destPath;
}
+ @Editable(order=1100, group = "More Settings", placeholder = "All platforms in image", description = "" +
+ "Optionally specify platform to pull, for instance <tt>linux/amd64</tt>. " +
+ "Leave empty to pull all platforms in image")
+ @Interpolative(variableSuggester="suggestVariables")
+ @NoSpace
+ public String getPlatform() {
+ return platform;
+ }
+
+ public void setPlatform(String platform) {
+ this.platform = platform;
+ }
+
@Editable(order=1200, group="More Settings", description="Optionally specify <a href='https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane_pull.md' target='_blank'>additional options</a> of crane")
@Interpolative(variableSuggester="suggestVariables")
- @ReservedOptions({"(--format)=.*"})
+ @ReservedOptions({"--format", "(--format)=.*", "--platform", "(--platform)=.*"})
public String getMoreOptions() {
return moreOptions;
}
@@ -62,7 +78,13 @@ public class PullImageStep extends CraneStep {
@Override
public String getCommand() {
- return "crane pull --format oci " + getSrcImage() + " /onedev-build/workspace/" + getDestPath();
+ var builder = new StringBuilder("crane pull --format oci ");
+ if (getPlatform() != null)
+ builder.append("--platform ").append(getPlatform()).append(" ");
+ if (getMoreOptions() != null)
+ builder.append(getMoreOptions()).append(" ");
+ builder.append(getSrcImage()).append(" /onedev-build/workspace/").append(getDestPath());
+ return builder.toString();
}
}
diff --git a/server-core/src/main/java/io/onedev/server/buildspec/step/PushImageStep.java b/server-core/src/main/java/io/onedev/server/buildspec/step/PushImageStep.java
index 97d80967f9..b3872c70ee 100644
--- a/server-core/src/main/java/io/onedev/server/buildspec/step/PushImageStep.java
+++ b/server-core/src/main/java/io/onedev/server/buildspec/step/PushImageStep.java
@@ -1,8 +1,7 @@
package io.onedev.server.buildspec.step;
import io.onedev.commons.codeassist.InputSuggestion;
-import io.onedev.server.annotation.Editable;
-import io.onedev.server.annotation.Interpolative;
+import io.onedev.server.annotation.*;
import io.onedev.server.buildspec.BuildSpec;
import javax.validation.constraints.NotEmpty;
@@ -24,6 +23,8 @@ public class PushImageStep extends CraneStep {
@Editable(order=100, name="OCI Layout Directory", description = "Specify OCI layout directory relative to <a href='https://docs.onedev.io/concepts#job-workspace' target='_blank'>job workspace</a> to push from")
@Interpolative(variableSuggester="suggestVariables")
+ @SubPath
+ @NoSpace
@NotEmpty
public String getSrcPath() {
return srcPath;
@@ -33,7 +34,8 @@ public class PushImageStep extends CraneStep {
this.srcPath = srcPath;
}
- @Editable(order=200, name="Target Docker Image", description="Specify target docker image to push to")
+ @Editable(order=200, name="Target Docker Image", description="Specify full tag of target docker image to push to, " +
+ "for instance <tt>registry-server/org/repo:tag</tt>")
@Interpolative(variableSuggester="suggestVariables")
@NotEmpty
public String getDestImage() {
@@ -43,8 +45,9 @@ public class PushImageStep extends CraneStep {
public void setDestImage(String destImage) {
this.destImage = destImage;
}
-
+
@Editable(order=1200, group="More Settings", description="Optionally specify <a href='https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane_push.md' target='_blank'>additional options</a> of crane")
+ @ReservedOptions({"--platform", "(--platform)=.*"})
@Interpolative(variableSuggester="suggestVariables")
public String getMoreOptions() {
return moreOptions;
@@ -60,7 +63,11 @@ public class PushImageStep extends CraneStep {
@Override
public String getCommand() {
- return "crane push /onedev-build/workspace/" + getSrcPath() + " " + getDestImage();
+ var builder = new StringBuilder("crane push");
+ if (getMoreOptions() != null)
+ builder.append(" ").append(getMoreOptions());
+ builder.append(" /onedev-build/workspace/").append(getSrcPath()).append(" ").append(getDestImage());
+ return builder.toString();
}
}
diff --git a/server-core/src/main/java/io/onedev/server/codequality/CodeProblem.java b/server-core/src/main/java/io/onedev/server/codequality/CodeProblem.java
index 1dc7abb5c3..23f27a3aef 100644
--- a/server-core/src/main/java/io/onedev/server/codequality/CodeProblem.java
+++ b/server-core/src/main/java/io/onedev/server/codequality/CodeProblem.java
@@ -15,7 +15,7 @@ public class CodeProblem implements Serializable {
private static final long serialVersionUID = 1L;
public static final String NON_REPO_FILE_PREFIX = ":";
-
+
public enum Severity {
CRITICAL,
HIGH,
diff --git a/server-core/src/main/java/io/onedev/server/validation/validator/NoSpaceValidator.java b/server-core/src/main/java/io/onedev/server/validation/validator/NoSpaceValidator.java
new file mode 100644
index 0000000000..7c2637495a
--- /dev/null
+++ b/server-core/src/main/java/io/onedev/server/validation/validator/NoSpaceValidator.java
@@ -0,0 +1,36 @@
+package io.onedev.server.validation.validator;
+
+import io.onedev.server.annotation.NoSpace;
+import io.onedev.server.annotation.SubPath;
+import org.apache.commons.io.FilenameUtils;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class NoSpaceValidator implements ConstraintValidator<NoSpace, String> {
+
+ private String message;
+
+ @Override
+ public void initialize(NoSpace constaintAnnotation) {
+ message = constaintAnnotation.message();
+ }
+
+ @Override
+ public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
+ if (value == null)
+ return true;
+
+ if (value.trim().contains(" ")) {
+ constraintContext.disableDefaultConstraintViolation();
+ String message = this.message;
+ if (message.length() == 0)
+ message = "Space not allowed";
+ constraintContext.buildConstraintViolationWithTemplate(message).addConstraintViolation();
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java
index 758f15ab87..830a7dcd66 100644
--- a/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java
+++ b/server-core/src/main/java/io/onedev/server/web/page/project/builds/detail/BuildDetailPage.java
@@ -333,7 +333,7 @@ public abstract class BuildDetailPage extends ProjectPage
@Override
protected Component newMessageContent(String componentId) {
- return new Label(componentId, "Web shell access to running job " +
+ return new Label(componentId, "Interactive web shell access to running jobs " +
"is an enterprise feature. <a href='https://onedev.io/pricing' target='_blank'>Try free</a> for 30 days").setEscapeModelStrings(false);
}
};
diff --git a/server-ee b/server-ee
index cba6e26a87..510daa7e95 160000
--- a/server-ee
+++ b/server-ee
@@ -1 +1 @@
-Subproject commit cba6e26a87a549e6d8c207af9d33bc230336562f
+Subproject commit 510daa7e952f9b9e1d02635c6222f37431e445f6
diff --git a/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemFile.java b/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemFile.java
index aa9eff755c..e18d18f740 100644
--- a/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemFile.java
+++ b/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemFile.java
@@ -1,10 +1,15 @@
package io.onedev.server.plugin.report.problem;
+import io.onedev.server.codequality.CodeProblem;
+
+import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
-import io.onedev.server.codequality.CodeProblem;
+import static io.onedev.server.codequality.CodeProblem.NON_REPO_FILE_PREFIX;
+import static org.apache.commons.lang3.StringUtils.substringAfterLast;
+import static org.apache.commons.lang3.StringUtils.substringBeforeLast;
public class ProblemFile implements Serializable {
@@ -12,24 +17,37 @@ public class ProblemFile implements Serializable {
private final String blobPath;
+ private final String moreInfo;
+
private final boolean inRepo;
private final Collection<CodeProblem> problems = new ArrayList<>();
public ProblemFile(String blobPath) {
- if (blobPath.startsWith(CodeProblem.NON_REPO_FILE_PREFIX)) {
- this.blobPath = blobPath.substring(CodeProblem.NON_REPO_FILE_PREFIX.length());
+ if (blobPath.startsWith(NON_REPO_FILE_PREFIX)) {
+ blobPath = blobPath.substring(NON_REPO_FILE_PREFIX.length());
inRepo = false;
} else {
- this.blobPath = blobPath;
inRepo = true;
}
+ if (blobPath.endsWith(")") && blobPath.contains("(")) {
+ moreInfo = substringBeforeLast(substringAfterLast(blobPath, "("), ")");
+ blobPath = substringBeforeLast(blobPath, "(").trim();
+ } else {
+ moreInfo = null;
+ }
+ this.blobPath = blobPath;
}
public String getBlobPath() {
return blobPath;
}
+ @Nullable
+ public String getMoreInfo() {
+ return moreInfo;
+ }
+
public boolean isInRepo() {
return inRepo;
}
@@ -38,4 +56,15 @@ public class ProblemFile implements Serializable {
return problems;
}
+ @Override
+ public String toString() {
+ var builder = new StringBuilder();
+ if (!inRepo)
+ builder.append(NON_REPO_FILE_PREFIX);
+ builder.append(blobPath);
+ if (moreInfo != null)
+ builder.append(" (").append(moreInfo).append(")");
+ return builder.toString();
+ }
+
}
\ No newline at end of file
diff --git a/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.html b/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.html
index 2bdd0678fb..9d6251ccad 100644
--- a/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.html
+++ b/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.html
@@ -17,7 +17,10 @@
<tr wicket:id="files">
<td>
<div class="file d-flex flex-wrap align-items-center">
- <a wicket:id="toggle" class="name mr-2"><wicket:svg href="arrow" class="icon"/> <span wicket:id="label" class="text-break"></span></a>
+ <a wicket:id="toggle" class="name mr-2"><wicket:svg href="arrow" class="icon"/>
+ <span wicket:id="label" class="text-break"></span>
+ <span wicket:id="moreInfo" class="ml-1 text-muted"></span>
+ </a>
<a wicket:id="view" title="Show problems in file view" class="mr-auto"><wicket:svg href="file" class="icon"/></a>
</div>
<wicket:enclosure child="problems">
diff --git a/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.java b/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.java
index 3f9389a682..5b1399a302 100644
--- a/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.java
+++ b/server-plugin/server-plugin-report-problem/src/main/java/io/onedev/server/plugin/report/problem/ProblemReportPage.java
@@ -212,28 +212,34 @@ public class ProblemReportPage extends BuildReportPage {
@Override
protected void populateItem(ListItem<ProblemFile> item) {
- ProblemFile file = item.getModelObject();
- String filePath = file.getBlobPath();
+ var file = item.getModelObject();
+ var fileString = file.toString();
+ var filePath = file.getBlobPath();
AjaxLink<Void> toggleLink = new AjaxLink<Void>("toggle") {
@Override
public void onClick(AjaxRequestTarget target) {
- if (expandedFiles.contains(filePath))
- expandedFiles.remove(filePath);
+ if (expandedFiles.contains(fileString))
+ expandedFiles.remove(fileString);
else
- expandedFiles.add(filePath);
+ expandedFiles.add(fileString);
target.add(item);
}
};
toggleLink.add(new Label("label", filePath));
+
+ if (file.getMoreInfo() != null)
+ toggleLink.add(new Label("moreInfo", "(" + file.getMoreInfo() + ")"));
+ else
+ toggleLink.add(new WebMarkupContainer("moreInfo").setVisible(false));
toggleLink.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
- return expandedFiles.contains(filePath) ? "expanded" : "collapsed";
+ return expandedFiles.contains(fileString) ? "expanded" : "collapsed";
}
}));
@@ -253,7 +259,7 @@ public class ProblemReportPage extends BuildReportPage {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(expandedFiles.contains(filePath)
+ setVisible(expandedFiles.contains(fileString)
&& item.getModelObject().getProblems().size() > MAX_PROBLEMS_TO_DISPLAY);
}
@@ -327,7 +333,7 @@ public class ProblemReportPage extends BuildReportPage {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(expandedFiles.contains(filePath));
+ setVisible(expandedFiles.contains(fileString));
}
});
@@ -338,7 +344,7 @@ public class ProblemReportPage extends BuildReportPage {
protected void onBeforeRender() {
expandedFiles.clear();
if (!getModelObject().isEmpty())
- expandedFiles.add(getModelObject().iterator().next().getBlobPath());
+ expandedFiles.add(getModelObject().iterator().next().toString());
super.onBeforeRender();
}
});