Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

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 :)

Friday, June 1, 2018

Installing WSL+Ubunutu+Docker on Windows 10/2019 1803

How's that for a needfully-long title? This article comes years after my first taste of Docker and some weeks after diving deep to migrate a legacy app, to node.js, to docker containers so it can be managed and run more effectively.

There is a LOT to share, but for the moment I'm going to focus on the biggest pain-point in getting to really appreciate what Docker can do for a Windows developer; getting Docker running in an environment friendly to all you'll find about Docker on Linux or OSX!

In a nut-shell, you need WSL (which effectively connects a "distro" to Windows low-level APIs). Then you need an environment/distro to actually work in. I'm using Ubuntu here and some of the script is sensitive to that, but there are many other distros available now so you have freedom. Once you have Ubuntu and WSL, you can install Docker-CE. You need CE specifically to work nicely with WSL, otherwise you can use the regular Docker, but then why are you reading this?!

To help ensure my environments were consistent (and because I had to try this dozens of times before it all worked for me), I've created a bash script and in the comments are 4 PowerShell commands you can use to get started with nothing more than a working install of Windows 10 1803 or Server 2019 Preview 1803. I'll let the script explain the details and I make no guarantees about this script so test in a safe place, but I rely on it :)


**Bash script**
https://gist.github.com/rainabba/6f345c439261882e0c1e648fcfc43df4

Followers