Monday, September 21, 2020

Executing Gitlab-runner locally with Docker (local runner and local code)

It's hard to prioritize writing when I have so many responsibilities AND interests, but when my battles stand to save others days or weeks of pain (or abandoning a project) and it can hilite my work (rare), I must write, right!? ;P

So far, I cannot get a runner to use my local files mounted, but I can commit locally, execute the runner locally and have it use that latest commit (not yet pushed). This is arguably better than my present approach other than having to commit (even locally) for every change.

If anyone knows how to skip Git locally all-together, I'd love to hear how!

What you wanted!

mkdir -p ./.gitlab-runner/builds \  
 docker run --name=runner-${PWD##*/} --privileged -t --rm \  
 -v /var/run/docker.sock:/var/run/docker.sock \  
 -v $PWD/.gitlab-runner/:/etc/gitlab-runner \  
 -v ${PWD}:${PWD} \  
 --workdir $PWD \  
 gitlab/gitlab-runner \  
 exec docker --builds-dir $PWD/.gitlab-runner/builds/ yourStage;  

If "yourStage" were debug and your .gitlab-ci.yml looked like the following, you should expect to see the output of the `ls` command reflecting your WORKDIR.

image: docker:git  
 stages:  
  - debug  
 variables:  
  DOCKER_DRIVER: overlay2  
  DOCKER_TLS_CERTDIR: "/certs"  
  CI_REGISTRY: registry.gitlab.com  
 before_script:  
  - printf "::STARTING_BEFORE_SCRIPT\n\n";  
  - export REVISION=$(git rev-parse --short HEAD)  
  - printf "::REVISION=${REVISION}\n"  
 debug:  
  image: docker:19.03-dind  
  stage: debug  
  script:  
   - pwd; ls -lah;  

I hope to spend time in the near future covering the experiences I've had implementing GitLab, challenges I've faced, solutions to those challenges and my hot-takes on the overall approach. For now, I hope that helped someone else because it was a long-time coming for me :)

Wednesday, September 2, 2020

Followers