简体   繁体   中英

Jib create folder for temporary files and changing folder ownership

I want to create temporary files in my spring boot application. I build images using JIB and deploy them in kubernetes. When I tried to create temporary files I received an error because container was started by non root user.

Now I'm looking for workaround to allow my application saves files inside an image's file system. I've seen this extension for JIB which provides possibility to change ownership of directory. I've tried many times with different configs to implement it by myself but all my tries failed. And here it is my config which also doesn't work as well:

jib {
    from.image = "..."
    to.image = "..."
    container {
        user = '1000'
    }
    extraDirectories {
        paths {
            path {
                from = 'export'
                into = '/app/export'
            }
        }
    }

    pluginExtensions {
        pluginExtension {
            implementation = 'com.google.cloud.tools.jib.gradle.extension.ownership.JibOwnershipExtension'
            configuration {
                rules {
                    rule {
                        glob = 'app/export/**'
                        ownership = '1000'
                    }
                }
            }
        }
    }
}

Is there a more handy way to reach my goal or I missed something important in my config?

UPD : Jib version is 3.2.0

I was not able to make it work when using path.into for extraDirectories . I suspect this is a bug (or current technical limitation) of Jib.

That said, what worked for me is, instead of setting path.into , to structure the extra directory with the desired layout. For example, with the following directory structure,

<project root>/jib-extra/app/export

you would have

    extraDirectories.paths = ['jib-extra']

    pluginExtensions {
        pluginExtension {
            implementation = 'com.google.cloud.tools.jib.gradle.extension.ownership.JibOwnershipExtension'
            configuration {
                rules {
                    rule {
                        // must be absolute path starting with '/'
                        glob = '/app/export'
                        ownership = '1000'
                    }
                    // if you have files under /app/export
                    rule {
                        glob = '/app/export/**'
                        ownership = '1000'
                    }
                }
            }

Lastly, I think mounting a volume at runtime could be another option in your case?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM