-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
- Loading branch information
There are no files selected for viewing
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
|
||
} | ||
} | ||
} |