加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

English Readme click here

docker-gradle-plugin

构建,推送docker镜像的Gradle插件

前置说明

  1. 低于1.2(含)的版本有bug,但是上传了之后没法删除,所以建议使用>=1.2.1的版本

代码库

GitHub: https://github.com/godfather1103/docker-gradle-plugin
Gitee/码云: https://gitee.com/godfather1103/docker-gradle-plugin

用法

  1. 在build.gradle中引入相关插件
// groovy DSL
// Using the plugins DSL:
plugins {
    id "io.github.godfather1103.docker-plugin" version "2.3"
}

// Using legacy plugin application:
buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "io.github.godfather1103:docker-plugin:2.3"
    }
}
apply plugin: "io.github.godfather1103.docker-plugin"

// kotlin DSL
// Using the plugins DSL:
plugins {
    id("io.github.godfather1103.docker-plugin") version "2.3"
}

// Using legacy plugin application:
buildscript {
    repositories {
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("io.github.godfather1103:docker-plugin:2.3")
    }
}
apply(plugin = "io.github.godfather1103.docker-plugin")
  1. 配置相关构建参数
// groovy DSL
docker {
    dockerBuildDependsOn.add("bootJar")
    dockerDirectory.value(project.projectDir.absolutePath)
    def user = (project.findProperty("docker.username") ?: "").toString()
    def password = (project.findProperty("docker.password") ?: "").toString()
    def email = (project.findProperty("docker.email") ?: "").toString()
    def name = (project.findProperty("docker.demo.imageName") ?: "demo").toString()
    if (!user.isEmpty() && !password.isEmpty()) {
        auth.value(new AuthConfig(user, password, email))
    }
    dockerBuildArgs.put("GitTag", "1.0")
    imageName.value(name + "-groovy")
    dockerImageTags.add("1.0")
    pushImageTag.value(true)
    pushImage.value(true)
    // since 2.0
    platform.value("linux/amd64")
}
// kotlin DSL
docker {
    dockerBuildDependsOn.add("bootJar")
    dockerDirectory.value(project.projectDir.absolutePath)
    val user = (project.findProperty("docker.username") ?: "") as String
    val password = (project.findProperty("docker.password") ?: "") as String
    val email = (project.findProperty("docker.email") ?: "") as String
    val name = (project.findProperty("docker.demo.imageName") ?: "demo") as String
    if (user.isNotEmpty() && password.isNotEmpty()) {
        auth.value(AuthConfig(user, password, email))
    }
    dockerBuildArgs.put("GitTag", "1.0")
    imageName.value("$name-kotlin")
    dockerImageTags.add("1.0")
    pushImageTag.value(true)
    pushImage.value(true)
    // since 2.0
    platform.value("linux/arm64/v8")
}

任务

插件包含以下任务。

任务 描述
dockerBuild 构建docker镜像。

配置DSL

以下属性是设置DSL docker{…}的一部分其中允许您设置环境和依赖项。

配置项 属性值
imageName - 构建的镜像名 允许的值:
字符串 - 'demoImage'

默认值: ''
dockerDirectory - docker对应的目录 允许的值:
路径 - '${project.projectDir}/'

默认值: ''
dockerBuildDependsOn - 构建镜像依赖的任务 允许的值:
任务名 - 'bootJar'

默认值: ''
dockerImageTags - 构建的tag列表 允许的值:
字符串 - '1.0'

默认值: ''
pushImage - 是否推送对应的镜像 允许的值:
布尔值 - true

默认值: false
pushImageTag - 是否推送tag 允许的值:
布尔值 - true

默认值: false
auth - 认证信息 允许的值:
AuthConfig对象 - new AuthConfig(用户名,密码,邮箱)

默认值: null
dockerBuildArgs - docker build参数 允许的值:
Map - map["arg1"]="arg"

默认值: null
resources - 构建过程中复制的资源 允许的值:
List[Resource] - [Resource1,...,ResourceN]

默认值: []
platform - 构建的目标平台 允许的值:
字符串 - linux/arm64/v8

默认值: ''

AuthConfig对象属性值

配置项 属性值
username - docker账户的用户名 允许的值:
字符串 - 'username'

默认值: ''
password - docker账户的密码 允许的值:
字符串 - 'password'

默认值: ''
email - docker账户的email 允许的值:
字符串 - 'example@example.com'

默认值: ''

Resource对象属性值

配置项 属性值
directory - 相关路径 允许的值:
字符串 - '/'

默认值: ''
targetPath - 目标路径 允许的值:
字符串 - 'build/docker'

默认值: ''
includes - 引入的资源(Ant-style) 允许的值:
字符串列表 - ['*.jar','*.class']

默认值: []
excludes - 排除的资源(Ant-style) 允许的值:
字符串列表 - ['*.log','log/**']

默认值: []

配置默认的docker账户信息

用户可以在gradle.properties中配置以下参数作为默认的账户信息,当项目中未配置对应的认证信息信息时,将使用默认的账户信息。

配置项 属性值
docker.username - docker账户的用户名 允许的值:
字符串 - 'username'
docker.password - docker账户的密码 允许的值:
字符串 - 'password'
docker.email - docker账户的email 允许的值:
字符串 - 'example@example.com'

捐赠

你的馈赠将助力我更好的去贡献,谢谢!

PayPal

支付宝
支付宝 支付宝

微信
微信支付

写在最后

  1. 该插件相关创意来源于docker-maven-plugin
  2. 从2.0版本开始api sdk改为使用docker-java
MIT License Copyright (c) 2022 Jack Chu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

构建、推送docker镜像(build or push docker Image.) 展开 收起
Java 等 3 种语言
MIT
取消

发行版 (11)

全部
2.4

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化