I was using Gitlab CI for a php project and the first line of .gitlab-ci.yml was this:
and in some lines below was this:
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
The problem is that php:5.6 image does not contain neither openssh-client nor git
so each time i was deploying something i had to wait for the container to update ubuntu packages and install git and openssh-client. A really slow process.
The solution was to create a php image that had these packages already installed.
I did this in Docker like this:
apt-get install openssh-client git
Before we exit the above php:5.6 container we open another shell and we get the docker ID of the running container.
Then we save an image kotsis/gitlabphp-5.6-fast of that container and we submit it in the docker hub.
docker commit DOCKER_ID kotsis/gitlabphp-5.6-fast
docker push kotsis/gitlabphp-5.6-fast:latest
That’s it! Now inside .gitlab-ci.yml I put in the first line:
No more installing packages during CI.