how to change gitlab-ci runner build path - linux

How to change the gitlab multi runner build path.
in my server it have /home/gitlab-runner/builds.
I want to change this path to my secondary HDD that is mounted in the same server.

You can change your runners build path by adjusting the config.toml. In the [[runners]] section add or change the builds_dir directory.
For further reference on runner configuration you can check out the documentation here.

On macOS I was able to find one more way (can be helpful if you have many runners, I guess):
Edit ~/Library/LaunchAgents/gitlab-runner.plist
and modify the path under --working-directory to whatever you want
e.g. from Terminal vim /Users/Me/Library/LaunchAgents/gitlab-runner.plist
or using your favorite Text Editor
Restart it for the changes to take effect
gitlab-runner restart

One may prefer to setup build directories globally.
In the file /etc/systemd/system/gitlab-ci-multi-runner.service there is a line
Environment="DAEMON_ARGS=run --working-directory /var/lib/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner"
So, you may change --working-directory /var/lib/gitlab-runner to whatever path you want, and wouldn't specify the --builds-dir on every new registered runner
Environment="DAEMON_ARGS=run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner"

Related

"Docker context ls" and "sudo docker context ls" don't have same setting options

I am a docker newbie. I just installed Docker and Docker Desktop as per offical instruction. Soon, I start to have problem like: the Docker Desktop does not show container. I think it's because I haven’t set the contexts same for with and without sudo privilege, according to this post.
But I don’t understand why I only have the “default” option for “sudo docker context ls”. Please help me on this. Many thanks!
OS:Ubuntu 20.04.5 LTS
screenshot
The docker context data is stored in the user's home directory. When you use sudo, that changes users and home directories. Without sudo it might look in /home/yourname/.docker/contexts, but when you switch to root with sudo it also changes home directories and looks in /root/.docker/contexts.
You do not need Docker Desktop on native Linux. Installing Docker (what the Docker documentation now calls "Docker Engine") through your OS's package manager is sufficient. If you are on a single-user system, you can grant your ordinary user access to the Docker socket, but be aware that it's all but trivial to use this access to root the entire host.
When you do uninstall Docker Desktop, there are additional files in your home directory you need to remove
rm -rf $HOME/.docker/desktop
$EDITOR $HOME/.docker/config.json
# and remove `credsStore` and `currentContext`
Once you've done this cleanup, you'll revert to Docker's default behavior of using the $DOCKER_SOCK environment variable, or without that, /var/run/docker.sock. That system-global Docker socket file is the same regardless of which user you are, and it won't be affected by sudo.

How to connect paths in Docker file

I am running a Jenkins job, inside a docker container, this job requires doxygen but im getting an error saying -
[exec] /bin/sh: /opt/fc4-usr-local/bin/doxygen: No such file or directory
I have doxygen installed in my Docker image, but the path is -
usr/bin/doxygen
Inside my docker image, I want to connect this old path - /opt/fc4-usr-local/bin/doxygen with new path usr/bin/doxygen
So whenever my job looks for doxygen it goes to new path usr/bin/doxygen.
Note 1. The reason I cant just edit my job to look for doxygen in the new path is that its files are locked and im not allowed to changes them,
Note 2. So my idea is that, when my Jenkins job look for doxygen in my docker container it goes straight for new path not the old one.
Could anyone please suggest any ideas for this.
Add these lines near the bottom of your Dockerfile:
RUN mkdir -p /opt/fc4-usr-local/bin
RUN ln -s /usr/bin/doxygen /opt/fc4-usr-local/bin/doxygen
The first line creates the directory.
The second line creates a symlink from one path to the other

create an app in a docker container (confused about tasks order)

I have to build a simple app which reads a text file and process it's content (like remove multiple spaces, process words etc) but my I am confused about the first part of my homework.
"Initialize a git repository in a docker container then implement an app...."
I use Debian, I installed docker and git and I studied about it. From what I read I have to create a Dockerfile which will contain some instructions then I build the image and then run the container, run?
But I am still confused, what is the order of these thigs? Can I go firstly and write the app in Intelij and then to create that Dockerfiler? Or I have to create first the container then to code the app? But how I build the container? I read a lot about this, can you give me some advice? I mention that after every app "task" (read text file, process text etc) I have to execute git add, git commit and git push (if it helps for answer)
If the instruction says to "Initialize a Git repository in a docker container" then you are expected to:
run e.g. a Debian container
if Git is not present install it
initialize the repo
write your app
submit homework
You could:
docker run \
--interactive --tty --rm \
--name=homework \
--volume=${PWD}/homework:/homework \
--workdir=/homework \
debian:buster-slim
This will run a Debian "buster" image as a container and should (!) give you a shell prompt in the container.
A directory /homework in the container will be mapped to your host machine's ${PWD}/homework and you will be in the /homework directory when the container starts. This means that you won't lose your work if you exit the container.
From within the container's prompt:
# pwd
/homework
# git
bash: git: command not found
# apt update && apt install -y git
...
done.
# git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
# git init
Initialized empty Git repository in /homework/.git/
Notes
If you exit the container, you can rerun the docker run ... command to return to it.
When you exist the container, you can ls -la ${PWD}/homework to see the .git directory (at least) persisted on your host.
Ensure you run it from the same directory where it created ${PWD}/homework. Or revise the --volume=...
I'd recommend an overall workflow of
Build the application, without Docker; then
Package it in a Docker image (if it makes sense to).
You should be able to build the application totally normally. Whatever language you're using to build the application, make sure to use its normal packaging tools. For example, your package.json/Gemfile/requirements.txt/go.mod should list out all of the library dependencies your application needs to run. Run it locally, write appropriate unit tests for it, and generally build something that works.
Once it works, then push it into Docker. You'll need to write a Dockerfile that builds the image. A generic recipe for this is
FROM language-base-image # python:3.9, node:14, ...
WORKDIR /app
COPY dependencies-file . # requirements.txt, package.json, ...
RUN install the dependencies # pip install, npm install, ...
COPY . .
RUN build the application # npm run build, ...
CMD ./the_application # npm run start, ...
You should then be able to docker build an image, and docker run a container from the resulting image. The Docker documentation includes a sample application that runs through this sequence.
Note in particular that the problem task of "read a text file" is substantially harder in Docker than without. You need to use a bind mount to give access to the host filesystem to the container, and then refer to the container-side path. For example,
docker run --rm -v $PWD/data:/data my-image \
./the_application --input /data/file.txt
I would not bother trying to use Docker as my primary development environment, especially for an introductory project. Docker is designed as an isolation system and it's intentionally tricky to work with host files from a container, and vice versa. Especially if you can use a fairly routine programming language that you can easily install with apt-get or brew, and you don't have tricky host-library dependencies, it's substantially easier to do most of your development in an ordinary host build environment use Docker only at a late stage.

errbot: scripted plugin installation for docker?

I have a Dockerfile to run errbot, looking for a way to script plugin installation. The documentation only seems to list the manual !repos install ... method.
Is there any way for automatic plugin installation from git repo?
Yes, you can simply use the BOT_EXTRA_PLUGIN_DIR config parameter and put any plugins you want to preload there.
https://github.com/errbotio/errbot/blob/master/errbot/config-template.py#L85
If you've initialized Docker swarm mode (even if just on the one Docker host), you can use Docker Configs to pull in files to a container at run-time rather than baking them into the Docker image.
For your specific use case, check out the Docker image https://github.com/swarmstack/errbot-docker which does exactly what you are looking for.

Volume Mounting in local OSX gitlab-runner for exec docker

I'm trying to test my gitlab-ci.yml file by running the jobs through gitlab-runner on my laptop (OSX). The yml looks like
image: ruby:2.2
start:
script:
- echo "made it"
The executor is docker. I've tried:
gitlab-runner --debug exec docker start
gitlab-runner --debug exec docker --docker-volumes /users/Shared/Sites/Werk/werk-mailer:/users/Shared/Sites/Werk/werk-mailer
And a many other paths and flags, but no luck. I keep getting this message:
ERROR: Job failed (system failure): Error response from daemon: Mounts denied:
The path /users/Shared/Sites/Werk/werk-mailer
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.
So apparently either gitlab-runner or docker only mounts the /Users/ folder. The /Users/Shared folder (in which I share repos with other accounts) is not added.
I moved my repo into /Users//Sites/ and it was fine.
An alternative fix for a related problem, although it doesn't seem to be apparent from the initial question: I found that Docker tried to locate a folder all in lower case. Docker runs linux, which is case sensitive, whereas MacOS's file system is not case sensitive :/ I simply created a new self-owned directory /development (sudo mkdir /development && sudo chown {username}:staff /development) and symlinked my project's folder there (cd /development && ln -s {path to project}) and added /development to the list of folders Docker for macOS has access to. Running the gitlab runner from that point worked for me.

Resources