gocd / gocd-docker

Deprecated. See: https://github.com/gocd/docker-gocd-server
https://hub.docker.com/r/gocd/gocd-server/
Apache License 2.0
94 stars 71 forks source link

gocd-agent Auto Register not working #22

Open holybit opened 8 years ago

holybit commented 8 years ago

Tried setting agent auto register properties a few ways with the 16.1.0 image but nothing is working. Running docker engine 1.9.1.

Here is an example of building an image from gocd/gocd-agent:16.1.0 with a properties files, but somehow the agent is removing the properties file.

# Basic Docker files for this experiment
$ ls -1
Dockerfile
autoregister.properties
docker-compose.yml

$ cat autoregister.properties
agent.auto.register.key=23456789abcdef

$ cat docker-compose.yml
gocd-agent-test:
  build: .
  restart: always
  container_name: gocd-agent-test
  environment:
     - GO_SERVER=gocd.efp.local
  ports:
     - 8153:8153
     - 8154:8154

$ cat Dockerfile
FROM gocd/gocd-agent:16.1.0

COPY autoregister.properties /var/lib/go-agent/config/autoregister.properties
RUN chown go:go /var/lib/go-agent/config/autoregister.properties

# I use docker-compose to run a build
$ docker-compose build
Building gocd-agent-test
Step 1 : FROM gocd/gocd-agent:16.1.0
 ---> 0aada6d4d4f9
Step 2 : COPY autoregister.properties /var/lib/go-agent/config/autoregister.properties
 ---> b46ba3316b82
Removing intermediate container 995c1663ea46
Step 3 : RUN chown go:go /var/lib/go-agent/config/autoregister.properties
 ---> Running in 31c4d255c23b
 ---> 6a4d26762ece
Removing intermediate container 31c4d255c23b
Successfully built 6a4d26762ece

# The resultant image from the build
$ docker images
REPOSITORY                                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
efpvoltrongocdagentdind_gocd-agent-test   latest              6a4d26762ece        2 minutes ago       455.5 MB
gocd/gocd-agent                           16.1.0              0aada6d4d4f9        3 weeks ago         455.5 MB
docker/compose                            1.5.2               a1614be747d3        10 weeks ago        58.6 MB

# If I run the container I just built the properties file exists
$ docker run -it --rm efpvoltrongocdagentdind_gocd-agent-test bash
root@14bdfe14c2df:/tmp# cat /var/lib/go-agent/config/autoregister.properties
agent.auto.register.key=23456789abcdef
root@14bdfe14c2df:/tmp# exit
exit

# Now I run the container in daemon mode
$ docker-compose up -d && docker logs -f gocd-agent-test
Creating gocd-agent-test
*** Running /etc/rc.local...
*** Booting runit daemon...
*** Runit started as PID 7
Starting Go Agent to connect to server gocd.efp.local ...
tail: unrecognized file system type 0x794c7630 for ‘/var/log/syslog’. please report this to bug-coreutils@gnu.org. reverting to polling
[Sat Feb 13 06:20:07 UTC 2016] using default settings from /etc/default/go-agent
logFile Environment Variable= null
Logging to go-agent-bootstrapper.log
0 [TouchLoopThread-2] INFO com.thoughtworks.go.agent.launcher.Lockfile  - Using lock file: /var/lib/go-agent/.agent-bootstrapper.running
194 [main] INFO com.thoughtworks.go.agent.launcher.ServerBinaryDownloader  - download started at Sat Feb 13 06:20:07 UTC 2016
201 [main] INFO com.thoughtworks.go.agent.launcher.ServerBinaryDownloader  - got server response at Sat Feb 13 06:20:07 UTC 2016
431 [main] INFO com.thoughtworks.go.agent.launcher.ServerBinaryDownloader  - pipe the stream to admin/agent at Sat Feb 13 06:20:08 UTC 2016
436 [main] INFO com.thoughtworks.go.util.PerfTimer  - Performance: Downloading new admin/agent with md5 signature: WF19vAJ7DYffVfYO6yT19A== took 245ms
438 [main] INFO com.thoughtworks.go.agent.common.util.JarUtil  - Attempting to load Go-Agent-Bootstrap-Class from agent.jar File:
439 [main] INFO com.thoughtworks.go.agent.common.util.JarUtil  - manifestClassKey: Go-Agent-Bootstrap-Class: com.thoughtworks.go.agent.AgentProcessParentImpl
442 [main] INFO com.thoughtworks.go.agent.AgentProcessParentImpl  - Agent is version: 16.1.0
558 [main] INFO com.thoughtworks.go.agent.launcher.ServerBinaryDownloader  - download started at Sat Feb 13 06:20:08 UTC 2016
564 [main] INFO com.thoughtworks.go.agent.launcher.ServerBinaryDownloader  - got server response at Sat Feb 13 06:20:08 UTC 2016
580 [main] INFO com.thoughtworks.go.agent.launcher.ServerBinaryDownloader  - pipe the stream to admin/agent-plugins.zip at Sat Feb 13 06:20:08 UTC 2016
581 [main] INFO com.thoughtworks.go.util.PerfTimer  - Performance: Downloading new admin/agent-plugins.zip with md5 signature: a267a82eacccce310ea197cb02b659c0 took 23ms
586 [main] INFO com.thoughtworks.go.agent.AgentProcessParentImpl  - Launching Agent with command: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -Dcruise.console.publish.interval=10 -Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom -Dagent.launcher.version=Unknown -Dagent.plugins.md5=a267a82eacccce310ea197cb02b659c0 -Dagent.binary.md5=WF19vAJ7DYffVfYO6yT19A== -Dagent.launcher.md5=e9SXM6cdV5kSkpVEmymHIg== -jar agent.jar https://gocd.efp.local:8154/go/

$ docker ps -a
CONTAINER ID        IMAGE                                     COMMAND             CREATED             STATUS              PORTS                              NAMES
3ce830106a3c        efpvoltrongocdagentdind_gocd-agent-test   "/sbin/my_init"     32 seconds ago      Up 31 seconds       0.0.0.0:8153-8154->8153-8154/tcp   gocd-agent-test

# And exec into it. The properties file is not there.
$ docker exec -it gocd-agent-test bash
root@9b00561cc118:/tmp# ls /var/lib/go-agent/config/autoregister.properties
ls: cannot access /var/lib/go-agent/config/autoregister.properties: No such file or directory
arvindsv commented 8 years ago

The file won't be around (will be removed), because it is needed only once during the registration between the agent and server. But, the registration should have happened. If so, on the server's agents page the agent should not show as "Pending". Is this happening?

holybit commented 8 years ago

@arvindsv I don't get why it would be "removed." It's a reference to how the application was initialized. Why remove it?

jamesgregory-myob commented 8 years ago

I'm having this issue too. Since upgrading to 16.1.0 my new agents are no longer auto-registering.

karlatkinson commented 8 years ago

Rather than copying the file in the Dockerfile, I've had this working by setting the relevant environment variables in the docker-compose.yml file.

e.g. environment:

emk commented 8 years ago

I'm also seeing this, with go-agent-15.2.0-2248.deb (via gocd-docker) and server 15.3.0(2361-15f38854eea874) installed manually. This was working correctly at some point, but now it has stopped.

ghost commented 7 years ago

The 'deleting autoregister.properties' is not a very useful feature, we shutdown our agents over night so we're not charged for them running (hosted on AWS). Now when they start they're 'unknown hosts' again with no resources. :-(

bizmate commented 7 years ago

@karlatkinson I am experiencing this problem on the latest version of GoCD. I am wondering where did you read about these environment variables as the process is not able to read the properties and it looks like a nice alternative while it gets fixed. Is the table on this page the correct reference? https://docs.gocd.org/current/faq/environment_variables.html Comparing to your post it looks different ie GO_SERVER_URL vs GO_SERVER

I need a reference for what the env variables for the GoCD agent are. Just to be precise.

karlatkinson commented 7 years ago

It's GO_SERVER_URL now. See the latest documentation on each of the latest docker agent images. Here is the Ubuntu 16 one for example: https://github.com/gocd/docker-gocd-agent-ubuntu-16.04