Skip to content
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ docker {
// name and value of a buildarg. Optional, default = no build arguments
buildArgs = ['http_proxy="http://some.proxy.url"']

// platforms to be built, Optional, default = no. E.g. platforms = ['linux/arm64', 'linux/amd64']
platforms = ['linux/arm64', 'linux/amd64']

// Always remove intermediate containers, even after unsuccessful builds. Optional, default = false
removeIntermediateContainers = true

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ java {
}

group = 'org.sglahn'
version = "0.8"
version = "0.8.1"

pluginBundle {
website = 'https://github.com/sglahn/gradle-dockerfile-plugin'
Expand Down
2 changes: 2 additions & 0 deletions example-project-groovy-dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ docker {
labels = ['branch=master', 'mylabel=test']
// name and value of a buildarg. Optional, default = no build arguments
buildArgs = ['http_proxy="http://some.proxy.url"']
// platforms to be built, Optional, default = no. E.g. platforms = ['linux/arm64', 'linux/amd64']
platforms = ['linux/amd64']
// Always remove intermediate containers, even after unsuccessful builds. Optional, default = false
removeIntermediateContainers = true
// Isolation specifies the type of isolation technology used by containers. Optional, default = default
Expand Down
2 changes: 2 additions & 0 deletions example-project-kotlin-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ docker {
labels = listOf("branch=master", "mylabel=test")
// name and value of a buildarg. Optional, default = no build arguments
buildArgs = listOf("http_proxy=\"http://some.proxy.url\"")
// platforms to be built, Optional, default = no. E.g. platforms = ['linux/arm64', 'linux/amd64']
platforms = listOf('linux/amd64')
// Always remove intermediate containers, even after unsuccessful builds. Optional, default = false
removeIntermediateContainers = true
// Isolation specifies the type of isolation technology used by containers. Optional, default = default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DockerFilePluginExtension {
List<String> tags = []
List<String> labels = []
List<String> buildArgs = []
List<String> platforms = []

String dockerFile
String buildContext
Expand Down
25 changes: 23 additions & 2 deletions src/main/groovy/org/sglahn/gradle/docker/util/DockerHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ class DockerHelper {
def dockerRepository = project.docker.dockerRepository ?: ''
if (!dockerRepository.empty && !dockerRepository.endsWith('/')) dockerRepository = dockerRepository + '/'
def imageName = project.docker.imageName ?: project.getName()
def cmd = "docker push ${dockerRepository}${imageName}:${tag}"
def cmd = ""
if (useBuildX(project)) {
cmd = "docker " + dockerBuildParameter(project, true).join(" ")
} else {
cmd = "docker push ${dockerRepository}${imageName}:${tag}"
}

executeCmd(project, cmd)
}
Expand All @@ -84,16 +89,24 @@ class DockerHelper {
executeCmd(project, cmd)
}

static List<String> dockerBuildParameter(project) {
static List<String> dockerBuildParameter(project, push=false) {
List<String> arguments = new ArrayList<>()

def dockerRepository = project.docker.dockerRepository ?: ''
if (!dockerRepository.empty && !dockerRepository.endsWith('/')) dockerRepository = dockerRepository + '/'
def imageName = project.docker.imageName ?: project.getName()
def imageVersion = project.docker.imageVersion ?: "latest"

if (useBuildX(project)) {
arguments.add('buildx')
}
arguments.add('build')

println("push: $push")
if (push) {
arguments.add("--push")
}

if (project.docker.tags.isEmpty()) {
arguments.add('-t')
arguments.add("${dockerRepository}${imageName}:${imageVersion}")
Expand All @@ -112,6 +125,10 @@ class DockerHelper {
arguments.add("--build-arg=${it}")
}

if (useBuildX(project)) {
arguments.add("--platform=${project.docker.platforms.join(",")}")
}

if (project.docker.isolation == null) {
arguments.add("--isolation=default")
}
Expand All @@ -130,4 +147,8 @@ class DockerHelper {

arguments
}

static boolean useBuildX(project) {
return !project.docker.platforms.isEmpty()
}
}