Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting registryCredentials for DockerPushImage does not work #1216

Open
k3mist opened this issue Apr 15, 2024 · 2 comments
Open

Setting registryCredentials for DockerPushImage does not work #1216

k3mist opened this issue Apr 15, 2024 · 2 comments

Comments

@k3mist
Copy link

k3mist commented Apr 15, 2024

When running dockerPushImage or a custom task such as

task myDockerPush(type: DockerPushImage) {
	images = ["test/${project.name}:${project.version}"]

	registryCredentials {
		url = "https://123.dkr.ecr.us-east-1.amazonaws.com/repository"
	}
}

the plugin will not use the provided url and fails with

> Task :myDockerPush FAILED
Pushing image 'test/test:0.1.0 to https://index.docker.io/v1/.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':myDockerPush'.
> Could not push image: denied: requested access to the resource is denied

Expected Behavior

it should use the provided url

Current Behavior

its using the default url

Context

gradle 8.2.1

def username = System.properties['user.name']
def uid = ["id", "-u", username].execute().text.trim()

docker {
	url = "unix:///run/user/${uid}/docker.sock"

	javaApplication {
		user = uid
		baseImage = "amazon/aws-lambda-java:17"
		maintainer = "test"
		mainClassName = "test"
	}

	registryCredentials {
		url = "https://123.dkr.ecr.us-east-1.amazonaws.com/repository"
	}

	println(docker.registryCredentials.url.get())
}

task myDockerPush(type: DockerPushImage) {
	images = ["test/${project.name}:${project.version}"]

	registryCredentials {
		url = "https://123.dkr.ecr.us-east-1.amazonaws.com/repository"
	}
}
println(tasks.dockerPushImage.registryCredentials.url.get())
println(tasks.myDockerPush.registryCredentials.url.get())

all 3 print statements print;
https://123.dkr.ecr.us-east-1.amazonaws.com/repository

however, it still uses the default configuration

Dockerfile and DockerBuildImage tasks work fine in the same build

ive also tried

afterEvaluate {
	project.tasks.withType(RegistryCredentialsAware).configureEach {
		println(it.name)
		println(it.getRegistryCredentials().getUrl().get())
		registryCredentials {
			url = "https://123.dkr.ecr.us-east-1.amazonaws.com/repository"
		}
		println(it.getRegistryCredentials().getUrl().get())
	}
}

and

afterEvaluate {
	project.tasks.withType(RegistryCredentialsAware) {
		println(it.name)
		println(it.getRegistryCredentials().getUrl().get())
		registryCredentials {
			url = "https://123.dkr.ecr.us-east-1.amazonaws.com/repository"
		}
		println(it.getRegistryCredentials().getUrl().get())
	}
}
@bmuschko
Copy link
Owner

If you are dealing with just a single registry then you do not need to use registryCredentials for tasks. Simply define it centrally in the docker extension. It will be applied to all Docker tasks. Something seems to be off as you are still pushing to Docker Hub. Make sure to provide the credentials.

Pushing image 'test/test:0.1.0 to https://index.docker.io/v1/.

My guess is that your container image name doesn't contain the registry domain, e.g. aws_account_id.dkr.ecr.region.amazonaws.com/test:1.0.0.

@phil-capa
Copy link

I am having a similar problem on Gradle 8,6 when trying to push an image, in that I am unable to set the the registry to anything other than dockerhub.

I have configured the docker closure as follows;

docker {
registryCredentials {
url.set("https://ghcr.io")
username.set(System.getenv("MY_GPR_USERNAME") as String)
password.set(System.getenv("MY_GPR_TOKEN") as String)
}
}

when I try to use the dockerPushImage task it returns the following;

Pushing image 'myrepo/alertengine:0.1' to https://index.docker.io/v1/

I have also tried to add the closure to an extension task as follows;

tasks.create("pushAlertDocker") {
registryCredentials {
url.set("https://ghcr.io")
username.set(System.getenv("MY_GPR_USERNAME") as String)
password.set(System.getenv("MY_GPR_TOKEN") as String)
}
dependsOn("buildAlertDocker")
images.add("myrepo/alertengine:${project.version}")
}

Same result, it still attempts to point to the docker.io repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants