nomad

HCL and Docker files for Nomad deployments
git clone https://git.in0rdr.ch/nomad.git
Log | Files | Refs | Pull requests

commit 076701f1f4531038351113990a6173f557f67d59
parent 85784447a34bb3b388effbcca767c52bb7f5c2d4
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Thu, 30 May 2024 00:29:53 +0200

feat(git): jenkins notifyCommit

Diffstat:
Mdocker/docker-git/Dockerfile | 2+-
Mdocker/docker-git/docker/create.sh | 26+++++++++++++-------------
Mdocker/docker-git/docker/example_post-receive.sh | 6++++++
Mdocker/docker-jenkins-inbound-agent/README | 30++++++++++++------------------
Mhcl/default/git/README.md | 2+-
5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/docker/docker-git/Dockerfile b/docker/docker-git/Dockerfile @@ -7,7 +7,7 @@ RUN sed -i 's/#\(http.*community\)$/\1/g' /etc/apk/repositories RUN apk update RUN apk add --no-cache apache2 apache2-utils apache2-ssl \ make gcc musl-dev mandoc \ - libgit2-dev git-daemon git + libgit2-dev git-daemon git curl # Build and install stagit RUN git clone --depth=1 git://git.codemadness.org/stagit /opt/stagit diff --git a/docker/docker-git/docker/create.sh b/docker/docker-git/docker/create.sh @@ -18,16 +18,16 @@ cd "${stagitdir}" stagit-index "${reposdir}/"*/ > "${stagitdir}/index.html" # make files per repo. -for dir in "${reposdir}/"*/; do - # strip .git suffix. +for dir in "${reposdir}/"*/; do + # strip .git suffix. r=$(basename "${dir}") d=$(basename "${dir}" ".git") printf "%s... " "${d}" - + if [ -f "${reposdir}/${r}/git-daemon-export-ok" ]; then # create stagit static repo files for published repos. mkdir -p "${stagitdir}/${d}" - cd "${stagitdir}/${d}" || continue + cd "${stagitdir}/${d}" || continue # set post-recieve hook, owner and description ln -fs "${stagitsrc}/example_post-receive.sh" "${reposdir}/${r}/hooks/post-receive" @@ -36,20 +36,20 @@ for dir in "${reposdir}/"*/; do if [ ! -f "${reposdir}/${r}/url" ]; then echo "https://git.in0rdr.ch/${r}" > "${reposdir}/${r}/url"; fi stagit -c ".cache" -u "https://git.in0rdr.ch/$d/" "${reposdir}/${r}" - + # symlinks ln -sf log.html index.html ln -sf ../style.css style.css ln -sf ../logo.png logo.png - ln -sf ../favicon.png favicon.png - else + ln -sf ../favicon.png favicon.png + else # unpublish repos. - rm -rf "${stagitdir}/${d}" - fi - - echo "done" -done + rm -rf "${stagitdir}/${d}" + fi + + echo "done" +done # ensure webserver permissions. -chown -R apache: "${stagitdir}" +chown -R apache: "${stagitdir}" chown -R apache: "${reposdir}" diff --git a/docker/docker-git/docker/example_post-receive.sh b/docker/docker-git/docker/example_post-receive.sh @@ -70,4 +70,10 @@ ln -sf log.html index.html ln -sf ../style.css style.css ln -sf ../logo.png logo.png +# trigger jenkins, create a token first +# https://plugins.jenkins.io/git/#plugin-content-push-notification-from-repository +TOKEN="" +curl --max-time 5 -s \ + "https://jenkins.in0rdr.ch/git/notifyCommit?token=$TOKEN&url=https://git.in0rdr.ch/$r" + echo "done" diff --git a/docker/docker-jenkins-inbound-agent/README b/docker/docker-jenkins-inbound-agent/README @@ -156,24 +156,8 @@ then start the Podman socket as systemd user job on the Nomad nodes. On all the Nomad clients, prepare the Jenkins user and the workspace directory (1312 can be any UID/GID combination, it just needs to map with the User in the -Jenkins cloud plugin configuration where the Nomad job is spawned): - - groupadd -g 1312 jenkins - useradd -m -s /bin/bash -u 1312 -g 1312 jenkins - - # keep my podman.socket enabled even if no jenkins user is logged in - loginctl enable-linger jenkins - #loginctl user-status jenkins | grep -i linger - - # https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#-M - systemctl --user -M jenkins@ start podman.socket - systemctl --user -M jenkins@ enable podman.socket - #systemctl --user -M jenkins@ is-enabled podman.socket - - # create the mountpoint for the workspaces, podman does not create it for us - sudo -u jenkins mkdir /home/jenkins/workspace - -<TODO: LINK-TO-PACKER-SCRIPT> +Jenkins cloud plugin configuration where the Nomad job is spawned). Example +script: https://code.in0rdr.ch/hashipi/file/nomad.sh.html If you need to redo the jenkins user configuration (e.g., to change the UID/GID), make sure to stop the systemd service for the user. Otherwise, new @@ -289,3 +273,13 @@ Docker container (-u flag). Few examples: Even more examples (not necessarily docker related): * https://www.jenkins.io/doc/pipeline/examples + +== Integration with Git post-receiv hooks == + +There exists the option to nudge Jenkins on every push, see +https://plugins.jenkins.io/git/#plugin-content-push-notification-from-repository:: +* Create token in security settings of jenkins +* Configure post-receive hook, add the curl request (branch optional) + + curl --max-time 5 -s \ + "https://jenkins.in0rdr.ch/git/notifyCommit?token=$GIT_TOKEN&url=$REPO_URL&branches=$BRANCH" diff --git a/hcl/default/git/README.md b/hcl/default/git/README.md @@ -81,5 +81,5 @@ The user credentials for BasicAuth can be stored on the server. To create a new file for $user: $ nomad exec -task smarthttp 1dc64f2f sh -/ # htpasswd -c /srv/git/.htpasswd $user +/ # htpasswd /srv/git/.htpasswd $user