We have setup a CentOS 7 repository in OpenAFS that we access from our images to install some applications.
This process is entirely manual and we're trying to automate the generation with GitLab-CI.
I've set up a runner following the instructions for setting Docker-in-Docker runner.
Then, I've modified the /etc/gitlab-runner/config.toml file to specify an OpenAFS host volume (volumes entry):
concurrent = 1
check_interval = 0
[[runners]]
name = "DinD builder"
url = "https://gitlab.ch/ci"
token = "7cf33172d567dd2504e988a78f64c3"
executor = "docker"
[runners.docker]
tls_verify = false
image = "docker:latest"
privileged = true
disable_cache = false
volumes = ["/afs:/afs:ro", "/cache"]
[runners.cache]
In the Dockerfile, we have a RUN command that copies the repo file from AFS to the currently-being-built-image, so we can install the software with yum install:
FROM gitlab-registry.ch/cc7-base
MAINTAINER Somebody
RUN echo "set completion-ignore-case On" >> /etc/inputrc
RUN yum update -y && \
yum install -y \
gcc \
git \
mc \
python-devel \
python-pip \
svn \
unzip \
vim
RUN cp /afs/<hugePathHere>/Linux/RPM/cc7/custom-repo.repo /etc/yum.repos.d && \
yum install --enablerepo=custom-repo -y CustomApp
CMD /bin/bash
The .gitlab-ci.yml file is:
services:
- docker:dind
build:
stage: build
tags:
- rtf-builder
before_script:
- docker info
- docker login -u $DOCKER_LOGIN_USERNAME -p $DOCKER_LOGIN_PASSWORD gitlab-registry.ch
script:
- docker build --pull -t $TO .
- docker push $TO
after_script:
- docker logout gitlab-registry.ch
variables:
TO: gitlab-registry.ch/<myUser>/testdockergitlabbuild:$CI_BUILD_REF_NAME
But this always fails, with GitLab-CI telling me that
cp: cannot stat '/afs/hugePathHere/Linux/RPM/cc7/custom-repo.repo': No such file or directory
In the host machine,
AFSis accesible and I can manually copy the repo file.A container created with
docker run --rm --privileged -ti -v /afs:/afs cc7-basehasAFSaccesible.
Am I missing something to make AFS accesible from the Dockerfile?
NOTE:
$DOCKER_LOGIN_USERNAME and $DOCKER_LOGIN_PASSWORD are GitLab secure variables.
I found a way to have
AFSandDockertogether, but not with aDocker-in-Dockerrunner.The trick is to use instead a
shellrunner. So when registering the runner, we should do it like:Afterwards, we just need to install Docker and make it available for the
gitlab-runneruser (for example, adding the user to thedockergroup).As stated here, we can't access the files inside
AFSfrom theDockerfile.Instead, we can use a 2-step build:
Dockerfileeverything that doesn't need to accessAFS.AFSmounted and install all theAFSrelated stuff.Then, we just have to commit the container and push it to the registry as the final image.
As an example, the files involved in this process could be something like this:
.gitlab-ci.yml
Dockerfile
postBuild.sh