GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.67k stars 1.44k forks source link

The resource directory is not copied to the image. #3865

Closed zgqq closed 1 year ago

zgqq commented 1 year ago

Environment:


Gradle 7.5.1

Build time: 2022-08-05 21:17:56 UTC Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918

Kotlin: 1.6.21 Groovy: 3.0.10 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 17.0.4.1 (Eclipse Adoptium 17.0.4.1+1) OS: Mac OS X 12.6 aarch64

- *OS:*  macOS 12.6 (21G115)

**Description of the issue**:
The resource directory is not copied to the image.

root@f206f84cf4b2:/app# ls classes jib-classpath-file jib-main-class-file libs


**Expected behavior**:
Resource directory will in  /app directory.

**Steps to reproduce**:
<!-- Please provide a minimal and precise series of steps -->

  1. 
  2. 
  3. 

**`jib-gradle-plugin` Configuration**: <!-- Delete this section if not used -->
```groovy
buildscript {
//    ext.configDir = "../../config"
    ext.configDir = "../../lib-flycat/config"
    ext.gradleConfigDir = "${configDir}/gradle"
    apply from: "${gradleConfigDir}/versionManagement.gradle"
    ext {
        springBootVersion = FlycatLibVersion.spring_boot_version
        springManagementVersion = FlycatLibVersion.spring_management_version
    }
    repositories {
        mavenCentral()
        gradlePluginPortal()
        maven { url 'https://repo.spring.io/plugins-release-local' }
        maven { url 'https://repo.spring.io/milestone' }
        maven { url 'https://repo.spring.io/snapshot' }
    }

    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" //
        classpath "io.spring.gradle:dependency-management-plugin:${springManagementVersion}"
    }
}

plugins {
//    id 'org.springframework.boot' version "2.7.4" apply false
//    id 'io.spring.dependency-management' version '1.0.8.RELEASE' apply false
//    id 'org.springframework.boot' version "2.7.4" apply true
//    id 'io.spring.dependency-management' version '1.0.8.RELEASE' apply true
    id 'java'
    id 'idea'
    // id "io.freefair.lombok" version "4.1.0"
    id "net.ltgt.errorprone" version "1.1.1" apply false

    id 'org.hidetake.ssh' version '2.10.1'
//    id "net.rdrei.android.buildtimetracker" version "0.11.0"

//    id 'com.google.cloud.tools.jib' version '3.3.1' apply false
    id 'com.google.cloud.tools.jib' version '3.3.1' apply false
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'

//ext.configDir = "../../config"
//ext.gradleConfigDir = "${configDir}/gradle"
//ext.env = env
ext.vJavaLang = '17'

ext.config = "../../config.json"
apply from: "${gradleConfigDir}/env.gradle"
//apply from: "${gradleConfigDir}/autoConfigure.gradle"
apply from: "${gradleConfigDir}/readJsonConfig.gradle"

//spring.security.user.name: zgqq
//spring.security.user.password: zgqq
//server.port: 8081
//spring.boot.admin.context-path: /sba-admin

if (getSubConfigValue('infra_sba', 'enable', env)) {
    def router_path = getSubConfigConnectValue('infra_sba', 'router_path', env)
    def port = getSubConfigConnectValue('infra_sba', 'app_port', env)
    def user = getSubConfigConnectValue('infra_sba', 'sba_user', env)
    def password = getSubConfigConnectValue('infra_sba', 'sba_password', env)
    addCustomJvmArgs(["-Dspring.security.user.name=${user}".toString(),
                      "-Dspring.security.user.password=${password}".toString(),
                      "-Dserver.port=${port}".toString(),
                      "-Dspring.boot.admin.context-path=${router_path}".toString(),
    ])
    def public_url = getSubConfigValue('infra_sba','public_url',env, '')
//    server.use-forward-headers=true
//    spring.boot.admin.ui.public-url=https://xxx.com
    if (public_url !== '') {
        addCustomJvmArgs(["-Dserver.use-forward-headers=true".toString(),
                "-Dspring.boot.admin.ui.public-url=${public_url}".toString()
        ])
    }
}

def dockerRegistryUser = getSubOrMainConfigValue('infra_sba','docker_registry_user',env, '')
def dockerRegistryPassword = getSubOrMainConfigValue('infra_sba','docker_registry_password',env, '')
if (dockerRegistryUser !== '') {
    ext.dockerUsername = dockerRegistryUser
    ext.dockerPassword = dockerRegistryPassword
}

def webServer = getSubConfigValue('infra_sba', 'web_server', env, 'tomcat')

ext.configObj = configObj['infra_sba']
apply from: "${gradleConfigDir}/javaProject.gradle"
apply from: "${gradleConfigDir}/configureSbaApp.gradle"
ext.appClassName = 'com.github.flycat.sba.SpringBootAdminApplication'
//ext.jmxPort = getSubConfigValue('infra_sba', 'jmx_port', env, 0)
//ext.dockerImage = getSubConfigValue('infra_sba', 'docker_repo', env, 'zgqq/flycat-sba')
//ext.containerPort = getSubConfigValue('infra_sba', 'app_port', env, 8081)

apply from: "${gradleConfigDir}/bootappProject.gradle"
apply from: "${gradleConfigDir}/dockerProject.gradle"

dependencies {
//    implementation project(':flycat-context')
//    implementation project(':flycat-spi')

//    implementation group: 'de.codecentric', name: 'spring-boot-admin-starter-server', version: '2.7.5'
    implementation(FlycatLibVersion.spring_boot_admin_server)
    // api"org.springframework.boot:spring-boot-starter-web:$springBootVersion"
    // implementation("org.springframework.boot:spring-boot-starter-security:$springBootVersion")

    println("Using web server ${webServer}")
    if (webServer == "underflow") {
        implementation("org.springframework.boot:spring-boot-starter-web") {
            exclude group: "org.springframework.boot", module: "spring-boot-starter-tomcat"
        }
        implementation "org.springframework.boot:spring-boot-starter-undertow"
    } else {
        implementation("org.springframework.boot:spring-boot-starter-web")
    }

    implementation("org.springframework.boot:spring-boot-starter-security")

}

Log output:

Additional Information:

zgqq commented 1 year ago

jib config

apply plugin: "com.google.cloud.tools.jib"

ext.jvmArgs = applicationDefaultJvmArgs

System.setProperty("jib.httpTimeout", '0')

def executeDockerBuild = false
def executeDockerBuildLocal = false
def executingTasks = project.gradle.startParameter.taskNames
if (executingTasks != null && !executingTasks.isEmpty()) {
    executeDockerBuild = 'jib' in executingTasks
            || 'jibDockerBuild' in executingTasks
    executeDockerBuildLocal = 'jibDockerBuild' in executingTasks
}

//if (executeDockerBuild) {
//    if (!isDocker(env)) {
//        throw new RuntimeException("Executing jib task need to docker env, current:" + env)
//    }
//}

ext.jibPlatform = "linux/arm64"
if (hasProperty("platform")) {
    println("Using specific docker platform, $platform")
    ext.jibPlatform = "$platform"
}

def dockerBaseImage = 'ibm-semeru-runtimes:open-17-jre-jammy'
def tag = "default"
if (hasProperty("dockerBaseImage")) {
    dockerBaseImage = ext.dockerBaseImage
    tag = "config"
}
println("Using ${dockerBaseImage} image by ${tag}")

jib {
    from {
//        image = 'amazoncorretto:8u232'
//        image = 'https://reg.qiniu.com/open-flycat/flycat:latest'
//        image = 'https://reg.qiniu.com/open-flycat/flycat-openj9:latest'
//        image = 'zgqq/flycat-jdk17:latest'
        image = dockerBaseImage
        platforms {
            if (jibPlatform == "linux/amd64") {
                println("Using docker platform, linux/amd64, specific platform: $jibPlatform")
                platform {
                    architecture = 'amd64'
                    os = 'linux'
                }
            } else {
                println("Using docker platform, linux/arm64, specific platform: $jibPlatform")
                platform {
                    architecture = 'arm64'
                    os = 'linux'
                }
            }
        }
    }

    extraDirectories {
        paths = [file('build/jib')]
    }

    to {
        image = dockerImage
        // https://github.com/GoogleContainerTools/jib/issues/2182
        credHelper = 'docker-credential-osxkeychain'
        tags = [env.toString() + '-' + (new Date().format("yyyyMMdd_HHmmss")).toString(), env.toString()]
        if (!executeDockerBuildLocal) {
            if (project.hasProperty('dockerUsername')) {
                auth {
                    println "image  $dockerImage username $dockerUsername"
                    username = dockerUsername
                    password = dockerPassword
                }
            }
        }
    }

    container {
        jvmFlags = jvmArgs
        mainClass = mainClassName
//        ports = [containerPort.toString(), debugServerPort.toString()]
        ports = [containerPort.toString()]
        volumes = ['/app', '/userapp/data', '/userapp/logs']

        creationTime = 'USE_CURRENT_TIMESTAMP'
    }
//    allowInsecureRegistries = true
}
elefeint commented 1 year ago

Jib uses Gradle's main source set. You should investigate whether the source set is what you want it to be.

alicejli commented 1 year ago

Closing due to lack of response.