Finally, i was able to get it working by myself, here are the following steps :
Pre-requisites:
- docker-ce and docker-compose must be installed on each agents
- go user must be on group docker
- /var/run/docker.sock must be on mode 666
- each agent must have an access to your gitlab/github/repository hub and the fingerprint host must be added before first connection
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
Then on gocd-server ui:
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"
Tips:
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".
Update:
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.