2
votes

I have a Jenkins server with Amazon EC2 Container Service Plugin installed. I am able to run a slave in ECS using example images like jenkins/jnlp-slave, but i want to use my own custom image that is present in AWS ECR repository as slave.

I have given the Image name as {ID}.dkr.ecr.us-east-1.amazonaws.com/python-slave:latest in ECS template in Configure system section, enter image description here

But it is not able to bring up the slave. I went to the ECS cluster to see the cause of error, I can see in the task details that for ECR images it is trying to use the following command to bring up the containers,

-url http://xyz:8084/ b0a06a93aa32251b22ae3a1a198e2d8a2057f2808b7947ed612b9e1eebb109c5 'ecs java slave-4b15n' 

It is failing with the error as,

Status reason   CannotStartContainerError: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"-url\": executable file not found in $PATH": unknown
Command ["-url","http://xyz:8084/","b0a06a93aa32251b22ae3a1a198e2d8a2057f2808b7947ed612b9e1eebb109c5","ecs java slave-4b15n"]
Privileged  false

But if i use example image like jenkins/jnlp-slave, it is using the following command and running fine

jenkins-agent -url http://xyz:8084/ bf8b42ab34d2691732026d8f454027c46d4ddaf9e9a7abc5af9c1ce417facf7a 'ecs java slave-x6p3z'

I have tried to find out the exact reason for this behaviour but no luck. Is there anyway we can use ECR image as jenkins Slave using ECS plugin.

3

3 Answers

1
votes

I ran into this issue as well. You MUST use the jnlp-slave image, or the extended image with build tools or cloudbees slave image ( if you are using cloudbees ).

You then extend the docker image by adding the libraries you want to it. You can add images to it with 'apt-get'

An example of extended the slave image with python

FROM jenkins/jnlp-slave:latest
RUN apt-get install -y -f python3 python3-pip

treat it like a generic debian image. you can install whatever you need to.

0
votes

for pulling the ECR image we should authenticate the docker client with the registry, then only you should be able to pull the image

eg. $(aws ecr get-login --no-include-email --region us-east-1)

0
votes

I faced the same issue. I pushed a custom image to the docker hub and gave the path of it in the ECS Container Service Plugin as "username/repo". Remember that there would be a version of the image with a tag "latest". I'm still figuring out how to do the same with a custom image on ECR. I Will update here once I resolve it.