-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2119 from rnc/KJB11-2
Inline Containerfile generation
- Loading branch information
Showing
12 changed files
with
139 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 69 additions & 4 deletions
73
...sor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 += | ||
""" | ||
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); | ||
} 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.