Skip to content

Document how to get socket location for image building configuration with podman #34435

@andrej-urvantsev

Description

@andrej-urvantsev

At the moment current documentation recommends this approach to configure PodMan:

tasks.named<BootBuildImage>("bootBuildImage") {
	docker {
		host.set("unix:///run/user/1000/podman/podman.sock")
		bindHostToBuilder.set(true)
	}
}

Where 1000 is an uid of a user, which is usually a 1000, but might be different in some cases.

So, more generic approach to configure PodMan(in theory it's also compatible with Docker) would be:

tasks.named<BootBuildImage>("bootBuildImage") {
    docker {
        fun String.runCommand(
            workingDir: File = File("."),
            timeoutAmount: Long = 60,
            timeoutUnit: TimeUnit = TimeUnit.SECONDS
        ): String? = runCatching {
            ProcessBuilder("\\s".toRegex().split(this))
                .directory(workingDir)
                .redirectOutput(ProcessBuilder.Redirect.PIPE)
                .redirectError(ProcessBuilder.Redirect.PIPE)
                .start().also { it.waitFor(timeoutAmount, timeoutUnit) }
                .inputStream.bufferedReader().readText().trim()
        }.onFailure { it.printStackTrace() }.getOrNull()

        val uid = "id -u".runCommand() ?: 0;
        val socketPath = "/run/user/$uid/podman/podman.sock";
        if (file(socketPath).exists()) {
            host.set("unix://$socketPath")
            bindHostToBuilder.set(true)
        }
    }
}

Which is ugly. It would be nice to move this logic inside of Spring Boot Gradle(and probably maven) plugins to eliminate that boilerplate from configs.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions