Docker build slave for php for Jenkins
Image inspired by bibinwilson/jenkins-docker-slave
Used in a setup like the one found in this article
Because I also deploy from these images i have som ssh related files in the ssh folder which are not included.
- Create your ssh key and put it in
ssh/id_rsa
- Add the host identifier to
ssh/known_hosts
- Add the public key that the jenkins server needs to use to connect to the image to
ssh/authorized_keys
To build the image run docker-compose build
(docker-compose up --build -d
can also be used...)
I prefer not having to remember a lot of parameters and so on, so there is both a Dockerfile and a docker-compose.yml the yml file is solely there to tag and name the image correctly, if you choose to just keep the image on your docker host instead of forking it and putting it in github.
instead of digging though an existing known_hosts, just execute this command:
ssh-keyscan -H remote.server.dk >> ssh/known_hosts
There is a pitfall - a malicious actor may do a man-in-the-middle attack. by doing this in the image creation, and not in the jenkinsfile, My thought is that the risk is smaller, since we do it less often., this does require rebuilding the image when the keys change.