Skip to content

Commit

Permalink
Merge branch 'master' into contextdir
Browse files Browse the repository at this point in the history
  • Loading branch information
lexemmens committed Apr 16, 2024
2 parents 09b0ba5 + 849a470 commit 49011bc
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 161 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/mavenpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 17
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: SonarCloud analysis
run: mvn -B verify sonar:sonar --file pom.xml
env:
Expand Down
30 changes: 15 additions & 15 deletions docs/modules/ROOT/pages/goals/build.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,15 @@ Note: You can also override the default value of layers by setting the BUILDAH_L

**Default value is**: `false`
|pull
|When the option is specified or set to “true”, pull the image. Raise an error if the image could not be pulled, even if the image is present locally.
|When the option is specified or set, pull the image. Raise an error if the image could not be pulled, even if the image is present locally.

If the option is disabled (with `<pull>false</pull>`) or not specified, pull the image from the registry only if the image is not present locally. Raise an error if the image is not found in the registries and is not present locally.

When this option is specified _and_ `pullAlways` is also specified, builds will fail as Podman does not support both options to be enabled at the same time.
If the option is disabled (with `<pull>never</pull>`) or not specified, pull the image from the registry only if the image is not present locally. Raise an error if the image is not found in the registries and is not present locally.

**Default value is**: `null` (not specified).

**See**: https://docs.podman.io/en/latest/markdown/podman-build.1.html

|pullAlways
|Pull the image from the first registry it is found in as listed in registries.conf. Raise an error if not found in the registries, even if the image is present locally.
**Supported values are:** ALWAYS, TRUE, MISSING, NEVER, FALSE, NEWER

When this option is specified _and_ `pullAlways` is also specified, builds will fail as Podman does not support both options to be enabled at the same time.

**Default value is**: `null` (not specified).

**See**: https://docs.podman.io/en/latest/markdown/podman-build.1.html
**See**: https://docs.podman.io/en/latest/markdown/podman-build.1.html#pull-policy

|squash
|Squash all of the image’s new layers into a single new layer; any preexisting layers are not squashed.
Expand Down Expand Up @@ -141,6 +132,16 @@ Supported values are:

**See**: https://docs.podman.io/en/latest/markdown/podman-build.1.html

|ulimits
|Specifies one or more user limits, such as `nofile` (number of open files), permitted in the build container.
Necessary, because `podman build` does not pass the current user session's user limits into the build container, breaking, e.g., large Java builds.

**Syntax**: `<type>soft-limit[:hard-limit]</type>`

Type is one of (core cpu data fsize locks memlock msgqueue nice nofile nproc rss rtprio rttime sigpending stack).

**See**: https://docs.podman.io/en/latest/markdown/podman-build.1.html#ulimit-type-soft-limit-hard-limit

|===

.Example configuration
Expand All @@ -152,8 +153,7 @@ Supported values are:
<image>
<name>your-image-name</name>
<build>
<pull>true</pull>
<pullAlways>false</pullAlways>
<pull>always</pull>
<tags>
<sampleTag>sampleTagValue</sampleTag>
</tags>
Expand Down
51 changes: 28 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.version>3.8.5</maven.version>
<jupiter.version>5.10.2</jupiter.version>
<mockito.version>5.11.0</mockito.version>
<sonar.projectKey>lexemmens_podman-maven-plugin</sonar.projectKey>
<sonar.organization>lexemmens</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand All @@ -61,19 +63,19 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>3.14.0</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version>
<version>20240303</version>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>3.3.1</version>
<version>3.3.2</version>
</dependency>

<!-- Required dependencies for plugin development -->
Expand Down Expand Up @@ -104,7 +106,7 @@
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.8.1</version>
<version>3.12.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -130,25 +132,25 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -160,15 +162,15 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.2.0</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<!-- Required for running tests from Intellij -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.9.2</version>
<version>${jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -186,35 +188,35 @@
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.2</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.5</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.5</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0</version>
<version>3.0.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
Expand All @@ -226,25 +228,25 @@
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.5.1</version>
<version>3.6.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<version>3.6.3</version>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>2.1.1</version>
<version>2.2.0</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.9</version>
<version>0.8.12</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
Expand Down Expand Up @@ -311,6 +313,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -341,12 +346,12 @@
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-api</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
</dependency>
</dependencies>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public class PodmanBuildCommand extends AbstractPodmanCommand {
private static final String LAYERS_CMD = "--layers";
private static final String BUILD_FORMAT_CMD = "--format";
private static final String CONTAINERFILE_CMD = "--file";
private static final String PULL_CMD = "--pull";
private static final String PULL_ALWAYS_CMD = "--pull-always";
private static final String PULL_POLICY_CMD = "--pull";
private static final String NO_CACHE_CMD = "--no-cache";
private static final String BUILD_ARG_CMD = "--build-arg";
private static final String PLATFORM_CMD = "--platform";
private static final String TARGET_STAGE_CMD = "--target";
private static final String SUBCOMMAND = "build";
private static final String PODMAN_ULIMITS_PREFIX = "podman.buildUlimits.";
private static final String ULIMITS_ARG_CMD = "--ulimit";

private PodmanBuildCommand(Log log, PodmanConfiguration podmanConfig, CommandExecutorDelegate delegate) {
super(log, podmanConfig, delegate, SUBCOMMAND, false);
Expand Down Expand Up @@ -120,11 +121,11 @@ public Builder setContainerFile(Path containerFile) {
/**
* Sets whether the base image should be pulled
*
* @param pull Sets whether to pull the image
* @param pullPolicy Sets whether to pull the image
* @return This builder instance
*/
public Builder setPull(Boolean pull) {
command.withOption(PULL_CMD, pull.toString());
public Builder setPullPolicy(String pullPolicy) {
command.withOption(PULL_POLICY_CMD, pullPolicy);
return this;
}

Expand All @@ -139,17 +140,6 @@ public Builder setNoCache(boolean noCache) {
return this;
}

/**
* Sets whether base images should always be pushed
*
* @param pullAlways Sets the value of the pullAlways property
* @return This builder instance
*/
public Builder setPullAllways(Boolean pullAlways) {
command.withOption(PULL_ALWAYS_CMD, pullAlways.toString());
return this;
}

/**
* Sets the platform for the resulting image rather using the default of the build system
*
Expand All @@ -160,7 +150,7 @@ public Builder setPlatform(String platform){
command.withOption(PLATFORM_CMD, platform);
return this;
}

/**
* Sets the platform for the resulting image rather using the default of the build system
*
Expand Down Expand Up @@ -201,6 +191,35 @@ private Map<String, String> getBuildArgsFromSystem() {
return buildArgsFromSystem;
}

public Builder addUlimitsArgs(Map<String, String> ulimits) {
Map<String, String> allUlimitsArgs = new HashMap<>(ulimits);
allUlimitsArgs.putAll(getUlimitsFromSystem());

for (Map.Entry<String, String> ulimit : allUlimitsArgs.entrySet()) {
command.withOption(ULIMITS_ARG_CMD, String.format("%s=%s", ulimit.getKey(), ulimit.getValue()));
}
return this;
}

private Map<String, String> getUlimitsFromSystem() {
Map<String, String> buildUlimitsFromSystem = new HashMap<>();
Properties properties = System.getProperties();

for (Object keyObj : properties.keySet()) {
String key = (String) keyObj;
if (key.startsWith(PODMAN_ULIMITS_PREFIX)) {
String ulimitKey = key.replaceFirst(PODMAN_ULIMITS_PREFIX, "");
String ulimitValue = properties.getProperty(key);

if (!isEmpty(ulimitValue)) {
buildUlimitsFromSystem.put(ulimitKey, ulimitValue);
}
}
}

return buildUlimitsFromSystem;
}

/**
* Returns the constructed command
*
Expand Down
Loading

0 comments on commit 49011bc

Please sign in to comment.