-
Notifications
You must be signed in to change notification settings - Fork 32
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
Inline Containerfile generation #2119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,10 +46,13 @@ spec: | |
type: string | ||
- name: RECIPE_IMAGE | ||
description: The image from the build recipe to use | ||
- name: BUILD_TOOL | ||
description: The build tool to use. | ||
- name: BUILD_PLUGINS | ||
description: Comma separated list of build plugins that should be disabled. | ||
default: "" | ||
- name: BUILD_SCRIPT | ||
description: The build script to embed with the Containerfile | ||
- name: PREPROCESSOR_ARGS | ||
description: The arguments for the build preprocessor | ||
- name: ORAS_OPTIONS | ||
type: string | ||
description: Optional environment variable string for build-trusted-artifacts | ||
|
@@ -103,7 +106,7 @@ spec: | |
memory: 512Mi | ||
script: | | ||
$(params.BUILD_SCRIPT) | ||
/opt/jboss/container/java/run/run-java.sh $(params.PREPROCESSOR_ARGS) | ||
/opt/jboss/container/java/run/run-java.sh $(params.BUILD_TOOL)-prepare $(workspaces.source.path)/source --recipe-image=$(params.RECIPE_IMAGE) --request-processor-image=$(params.JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE) --disabled-plugins=$(params.BUILD_PLUGINS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This completely inlines the request processor arguments (which makes it easier for PNC to use) |
||
- name: create-pre-build-source | ||
image: $(params.JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE) | ||
securityContext: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,86 @@ | ||
package com.redhat.hacbs.container.build.preprocessor; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import io.quarkus.logging.Log; | ||
import picocli.CommandLine; | ||
|
||
/** | ||
* We keep all the options the same between maven and gradle for now, | ||
* to keep the pipeline setup simpler. | ||
* | ||
* We keep all the options the same between maven, gradle, sbt and ant for now to keep the pipeline setup simpler. | ||
* Some of these may be ignored by different processors | ||
*/ | ||
public abstract class AbstractPreprocessor implements Runnable { | ||
|
||
@CommandLine.Parameters(description = "The directory to process") | ||
protected Path buildRoot; | ||
|
||
@CommandLine.Option(names = { "-dp", "--disable-plugin" }, paramLabel = "<plugin>", description = "The plugin to disable") | ||
@CommandLine.Option(names = { "-dp", "--disabled-plugins" }, paramLabel = "<plugin>", description = "The plugin to disable", split=",") | ||
protected List<String> disabledPlugins; | ||
|
||
@CommandLine.Option(names = "--recipe-image", required = true) | ||
String recipeImage; | ||
|
||
@CommandLine.Option(names = "--request-processor-image", required = true) | ||
String buildRequestProcessorImage; | ||
|
||
protected enum ToolType { | ||
ANT, | ||
GRADLE, | ||
MAVEN, | ||
SBT | ||
} | ||
|
||
protected ToolType type; | ||
|
||
@Override | ||
public void run() { | ||
Path jbsDirectory = Path.of(buildRoot.toString(), ".jbs"); | ||
//noinspection ResultOfMethodCallIgnored | ||
jbsDirectory.toFile().mkdirs(); | ||
|
||
String containerFile = """ | ||
FROM %s | ||
USER 0 | ||
WORKDIR /var/workdir | ||
RUN mkdir -p /var/workdir/software/settings /original-content/marker | ||
ARG CACHE_URL="" | ||
ENV CACHE_URL=$CACHE_URL | ||
COPY .jbs/run-build.sh /var/workdir | ||
COPY . /var/workdir/workspace/source/ | ||
RUN /var/workdir/run-build.sh | ||
""".formatted(recipeImage); | ||
|
||
// TODO: This is a bit of a hack but as Ant doesn't deploy and the previous implementation relied upon using the | ||
// BuildRequestProcessorImage we need to modify the Containerfile. In future the ant-build.sh should probably | ||
// encapsulate this. | ||
if (type == ToolType.ANT) { | ||
// Don't think we need to mess with keystore as copy-artifacts is simply calling copy commands. | ||
containerFile += | ||
Check warning on line 62 in java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java Codecov / codecov/patchjava-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java#L62
|
||
""" | ||
FROM %s AS build-request-processor | ||
USER 0 | ||
WORKDIR /var/workdir | ||
COPY --from=0 /var/workdir/ /var/workdir/ | ||
RUN /opt/jboss/container/java/run/run-java.sh copy-artifacts --source-path=/var/workdir/workspace/source --deploy-path=/var/workdir/workspace/artifacts | ||
FROM scratch | ||
COPY --from=1 /var/workdir/workspace/artifacts / | ||
""".formatted(buildRequestProcessorImage); | ||
Check warning on line 71 in java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java Codecov / codecov/patchjava-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java#L71
|
||
} else { | ||
containerFile += | ||
""" | ||
FROM scratch | ||
COPY --from=0 /var/workdir/workspace/artifacts / | ||
"""; | ||
} | ||
try { | ||
Files.writeString(Paths.get(jbsDirectory.toString(), "Containerfile"), containerFile); | ||
} catch (IOException e) { | ||
Log.errorf("Unable to write Containerfile", e); | ||
throw new RuntimeException(e); | ||
Check warning on line 83 in java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java Codecov / codecov/patchjava-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java#L81-L83
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This inlines the Containerfile generation into the source directory for the next steps (the git archiving and image generation) in the task to use. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless the JBS_QUAY_IMAGE_TAG is specified we default to
dev
. With Tekton pipelines, if tag islatest
the it will use PullAlways. Hence for pipelines settingJBS_QUAY_IMAGE_TAG=latest
is advised. We should consider whether to change the default tolatest
(perhaps in another iteration).