Last active
December 14, 2022 12:41
-
-
Save adamstraube/b5c8eae3034f3d8d5561cfb143751d7e to your computer and use it in GitHub Desktop.
Bash shell wrapper for running git-runner locally within WSL on a Windows 10 machine using Docker Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ $# -eq 0 ]] | |
then | |
echo "Usage: {up|down|runStages}" | |
exit 0 | |
fi | |
PWD_RESOLVED="$(pwd -P)" | |
function gitlabLoop() { | |
stages=($(echo "$1" | tr ',' '\n')) | |
if [ -z "$stages" ]; then | |
echo "Running test stage only" | |
gitlabExec "test" | |
else | |
echo "Running stage(s): ${stages[*]}" | |
for stage in ${stages[*]}; | |
do | |
gitlabExec $stage | |
done | |
fi | |
} | |
function gitlabExec() { | |
docker exec -w $PWD_RESOLVED -it gitlab-runner \ | |
gitlab-runner exec docker $1 \ | |
--docker-privileged \ | |
--docker-disable-cache \ --cache-dir=/tmp/gitlabrunner \ | |
--docker-volumes '/var/run/docker.sock:/var/run/docker.sock' \ | |
--env ROOT_PWD=$PWD_RESOLVED | |
} | |
case "$1" in | |
## TO CREATE/START DOCKER CONTAINER FOR GITLAB | |
up) | |
docker run -d --name gitlab-runner --restart always \ | |
-v $PWD_RESOLVED:$PWD_RESOLVED \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
--workdir $PWD_RESOLVED \ | |
-v /srv/gitlab-runner/config:/etc/gitlab-runner \ | |
gitlab/gitlab-runner:latest | |
;; | |
## TO RUN RUNNER AFTER GITLAB CONTAINER HAS STARTED | |
runStages) | |
mkdir -p /tmp/gitlabrunner | |
gitlabLoop ${2} | |
rm -r /tmp/gitlabrunner | |
;; | |
## TO STOP GITLAB CONTAINER | |
down) | |
docker stop gitlab-runner | |
docker rm gitlab-runner | |
;; | |
esac |
I've updated this for a bit more robustness and to make it almost functionally equivalent to running Docker in Docker on Gitlab CI. I haven't tested under WSL, but it works great on macOS and should still work in Linux.
https://gist.github.com/dragon788/485a483f20bcb205bd75866cbfb921f6
You might find https://gitlab.com/cunity/gitlab-emulator useful
Aha! I just realised that exec doesn't work for jobs that are included from other files.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like now you need to write job name and not step name, here is my updated version that worked in WSL2: