I have build a CI/CD with gitlab and docker. In my gitlab-ci.yml i just write commands to build and launch container to run test and that's it.
Now i m looking for a way to do the same thing with a GOCD ci/cd server. But the official documentation from gocd directly come to kubernetees or Docker in Docker or Docker outside Docker. I don't need this.
I have one GOCD-server and two GOCD-agents.
I want to build and run ONE container and perhaps deploy it. I m not able to find a simple tutorial to make a pipeline with three stages on GOCD:
Finally, i was able to get it working by myself, here are the following steps :
add manually the fingerprint host on each gocd-agent, you must be connected as go user (or don't forget to set the right owner to known_hosts file):
ssh-keyscan -H your.repository.com >> /var/go/.ssh/known_hosts
create pipeline
create a stage
create a job
create one or more tasks
--> add a new task -> choose "more" and you will have the possibility to add a custom command
at this point, you can add in the cell "commands"
/usr/bin/docker
or (depends of your use-case)
/usr/local/bin/docker-compose
and in the arguments list, one argument by line
build
.
-f
dockerfile
-t
yourrepository/tagOfYourImage
After that, don't forget, to clean before and after each run, your containers and created images. You can also use "/bin/bash" in cell "commands" and then two arguments
-c
"/usr/bin/docker rmi $(/usr/bin/docker image ls|/usr/bin/grep server_php|/usr/bin/awk '{ print $3 }'|/usr/bin/tr '\r' ' ') --force||true"
If you want all your jobs to success on each agent, don't forget to choose the option "Run on all agents" in the tab "Job settings".
If you restart docker service or one of your agent, it will remove the 666 permissons on /var/run/docker.sock, adding the user go to the group docker didn't help me. I have to set 666 permissions to this file again.