iriusrisk / GoCD-EC2-Elastic-Agent-Plugin

Plugin for GoCD server that will spin up and shut down EC2 instances as its agent workers on demand
Apache License 2.0
12 stars 12 forks source link

[FEATURE REQUEST] Add option to configure environment that agents will be assigned to #6

Closed joelsdc closed 4 years ago

joelsdc commented 4 years ago

Hi,

I'm testing out this plugin, I'm having a hard time finding how to assign the elastic agents to an environment, otherwise my pipelines won't run on the elastic agents.

Having for example:

2 envs (stg/prd)
3 pipelines (pl1, pl2, pl3)

pl1 is assigned to stg
pl2 is assigned to prd
pl3 is not assigned to any env

Only pl3 will run on the ec2 elastic agents, because I have no way to tell them they are assigned to an environment.

According to the docs here: https://docs.gocd.org/current/advanced_usage/agent_auto_register.html you can set the agent.auto.register.environments so the agent get assigned, the problem is there is no way to do this using the EC2 Elasting plugin because whatever you set in the userData will be executed after the agent has started and registered.

As a workaround, I have patched your source so the starting of the agent is run after everything else, but this is ugly, is there any change you can implement another setting in the elasticAgentProfile so we can configure the environments to be assigned?

Thanks!

joelsdc commented 4 years ago

With the above patch and then setting in the profile config userData something like:

echo "agent.auto.register.environments=env1,env2,env3..." >> /var/lib/go-agent/config/autoregister.properties

I can get the agents to register with GoCD using environments.

The ideal way would be to have a separate configuration param that can be empty (nothing changes) or can be set (the agent.auto.register.environments param gets added).

ShubhamAgarwal1616 commented 4 years ago

I am also trying to do the same thing, I provided ami and other config details on elastic agent configuration and I have created a file /var/lib/go-agent/config/autoregister.properties and provided auto registration key in it as mentioned in https://docs.gocd.org/current/advanced_usage/agent_auto_register.html.

but I am getting such errors: Error occurred when agent tried to ping server: org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [https://my-server-url/go/remoting/remoteBuildRepository]; nested exception is org.apache.http.client.ClientProtocolException: The server returned status code 403.

can you please help me with this

do I have to mention something in user data

joelsdc commented 4 years ago

Hi @ShubhamAgarwal1616, I'm not sure it's the same problem. Sounds to me you are configuring the autoregister.properties manually anbd you don't need to, the EC2 plugin uses the ec2 userdata to automatically configure the agents for auto-registration.

v-sky commented 4 years ago

Hi @joelsdc! As you figured out yourself we didn't implement environments feature in this plugin and this is not something we have on our roadmap right now, but maybe in a feature we will. If you're interested I encourage you to implement it yourself and make a pull request. The workaround you suggested makes sense to me, so I will merge it. Thanks!

joelsdc commented 4 years ago

I've been using the workaround for a couple weeks now with no problems. I don't think it's worth either as this does in fact solve the problem. Thanks for merging!

joelsdc commented 4 years ago

Will you create a new release or not until you have more significant changes?

v-sky commented 4 years ago

I think it would be great to test the plugin with the newest version of GoCD server first. What version you have been running?

joelsdc commented 4 years ago

I didn’t now there could be a version limitation, I started with v20.2.0, and updated recently to v20.3.0. So far no issues...