Skip to content
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

Fix Buildx build with Dockerfile outside of Docker build context #1721

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* **0.44-SNAPSHOT**:
- Add new option "useDefaultExclusion" for build configuration to handle exclusion of hidden files ([1708](https://github.com/fabric8io/docker-maven-plugin/issues/1708))
- The <noCache> option is now propagated down to the buildx command, if it is set in the <build> section. ([1717](https://github.com/fabric8io/docker-maven-plugin/pull/1717))
- Fix Buildx build with Dockerfile outside of the Docker build context directory ([1721](https://github.com/fabric8io/docker-maven-plugin/pull/1721))

* **0.43.4** (2023-08-18):
- Always pass `--config` option for latest versions of Docker CLI ([1701](https://github.com/fabric8io/docker-maven-plugin/issues/1701))
Expand Down
4 changes: 4 additions & 0 deletions it/buildx-dockerfile_and_contextdir/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM debian:bullseye-slim

COPY resource.properties /
CMD [ "echo", "Hello World" ]
51 changes: 51 additions & 0 deletions it/buildx-dockerfile_and_contextdir/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.fabric8.dmp.itests</groupId>
<artifactId>dmp-it-parent</artifactId>
<version>0.44-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dmp-it-buildx-dockerfile_and_contextdir</artifactId>

<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<outputDirectory>target/docker-build</outputDirectory>
<useColor>false</useColor>
<verbose>all</verbose>
<images>
<image>
<name>${project.artifactId}:${project.version}</name>
<build>
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
<contextDir>${project.basedir}/src/docker</contextDir>
<buildx>
<platforms>
<platform>linux/amd64</platform>
<platform>linux/arm64</platform>
</platforms>
</buildx>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name=value1
key=value2
1 change: 1 addition & 0 deletions it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<module>buildx-contextdir</module>
<module>buildx-dependencyset</module>
<module>buildx-dockerfile</module>
<module>buildx-dockerfile_and_contextdir</module>
<module>buildx-push</module>
<module>docker-compose</module>
<module>dockerfile</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ protected void buildX(List<String> buildX, String builderName, BuildDirs buildDi
File contextDir = buildConfiguration.getContextDir();
if (contextDir != null) {
Path destinationPath = getContextPath(buildArchive);
Path dockerFileRelativePath = contextDir.toPath().relativize(buildConfiguration.getDockerFile().toPath());
append(cmdLine, "--file=" + destinationPath.resolve(dockerFileRelativePath), destinationPath.toString());
String dockerFileName = buildConfiguration.getDockerFile().getName();
append(cmdLine, "--file=" + destinationPath.resolve(dockerFileName), destinationPath.toString());
} else {
cmdLine.add(buildDirs.getOutputDirectory().getAbsolutePath());
}
Expand Down
Loading