14 Commits

Author SHA1 Message Date
Chris Evich
b4dd3c667c Fix image tagging (again)
This CI environment is using a busybox `sh` so doesn't support all the
advanced features of bash.  Reimplement IMAGE_TAG processing so it
functions as intended.

Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
2022-11-16 10:53:52 -05:00
Chris Evich
e214a0549c Merge branch 'bugfix' into 'main'
Fix CI/CD typo and other misc items

See merge request qontainers/pipglr!4
2022-11-16 15:07:01 +00:00
Chris Evich
04b61422a9 Be helpful to CI/CD job maintainers
It's often hard to debug/maintain/improve a job when you can't observe
any of the (many!) auto-generated CI env. vars.  Print them all out on
every job.

Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
2022-11-16 10:01:51 -05:00
Chris Evich
341fbb8030 Fix kaniko command-line
For whatever reason, line-breaks must be used regardless of
string-block marker `|` or `>-`.  Fix this.

Also, support a fork/pull/MR model allowing contributors to run
pipelines on their fork w/ push to their registry.  In this case, images
should be tagged by MR number to be helpful.

Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
2022-11-16 09:46:19 -05:00
Chris Evich
64ce093a87 Ignore local pre-commit configuration files
Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
2022-11-16 09:23:17 -05:00
Chris Evich
5daaa407c8 Tweak some tag defaults
Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
2022-11-16 09:23:17 -05:00
Chris Evich
af48308a15 Merge branch 'set_name' into 'main'
Add runner-name build-arg

See merge request qontainers/pipglr!3
2022-11-16 14:05:06 +00:00
Chris Evich
98a0c4c9ab Merge branch 'upd_img_tag' into 'main'
Update image tagging w/ `mr` prefix for MRs

See merge request qontainers/pipglr!2
2022-11-16 14:04:45 +00:00
Chris Evich
9c95cf5074 Add runner-name build-arg
Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
2022-11-16 08:53:48 -05:00
Chris Evich
952ff81c4f Update image tagging w/ mr prefix for MRs
Prevent any possiblilty of confusion for tags (prefixed with a `v`) vs MR tags
(previously no prefix).

Signed-off-by: Chris Evich <chris_gitlab@icuc.me>
2022-11-13 18:45:10 -05:00
Chris Evich
8066716b67 Add background cleanup process
When given the "run" argument, in addition to launching `podman system
service` in the background, also start a small periodic maintenance
script.  It's only job is to clean up stale images, containers, and
volumes from old jobs.  Currently hard-coded to trigger every 2 days,
this could be tweaked via build-args or env. var.

Signed-off-by: Chris Evich <cevich@redhat.com>
2022-11-10 14:19:09 -05:00
Chris Evich
ba2dc82ac8 Fix disused session-port var in run label
Signed-off-by: Chris Evich <cevich@redhat.com>
2022-11-10 12:07:06 -05:00
Chris Evich
b9e5e066c8 Update documentation
Signed-off-by: Chris Evich <cevich@redhat.com>
2022-11-10 11:53:56 -05:00
Chris Evich
125d7cb9ac Tag images based on build context
For tag-pipelines, tag image with the repo. tag

For MR's, tag the image with the MR number

For Branches, use the branch name except for `main` use `latest`.

Signed-off-by: Chris Evich <cevich@redhat.com>
2022-11-10 11:47:20 -05:00
6 changed files with 59 additions and 9 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/.pre-commit-config.yaml

View File

@@ -15,12 +15,26 @@ build:
BASE_TAG: latest BASE_TAG: latest
FLAVOR: stable FLAVOR: stable
script: script:
- mkdir -p /kaniko/.docker - 'mkdir -p /kaniko/.docker'
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json - 'echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json'
- >- - |
echo "Select CI env. vars.:";
printenv | egrep '^CI_' | sort
# N/B: There could be more than one merge-request open with this branch's HEAD
- |
IMAGE_TAG="${CI_COMMIT_BRANCH}";
if [[ -n "$CI_COMMIT_TAG" ]]; then
IMAGE_TAG="${CI_COMMIT_TAG}";
elif [[ -n "$CI_OPEN_MERGE_REQUESTS" ]]; then
IMAGE_TAG=mr$(echo "${CI_OPEN_MERGE_REQUESTS}" | cut -d, -f -1 | cut -d\! -f 2);
elif [[ "$CI_COMMIT_BRANCH" == "main" ]]; then
IMAGE_TAG="latest";
fi
echo "Building/Pushing to: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}";
- |
/kaniko/executor \ /kaniko/executor \
--context $CI_PROJECT_DIR \ --context $CI_PROJECT_DIR \
--dockerfile $CI_PROJECT_DIR/Containerfile \ --dockerfile $CI_PROJECT_DIR/Containerfile \
--destination "$CI_REGISTRY_IMAGE:${CI_COMMIT_TAG:-latest}" \ --destination "${CI_REGISTRY_IMAGE}:${IMAGE_TAG}" \
--build-arg "BASE_TAG=$BASE_TAG" \ --build-arg "BASE_TAG=$BASE_TAG" \
--build-arg "FLAVOR=$FLAVOR" --build-arg "FLAVOR=$FLAVOR"

View File

@@ -86,13 +86,14 @@ RUN if [[ "$RUNNER_LISTEN_ADDRESS" == "disabled" ]]; then \
# A small wrapper is needed to launch a background podman system service # A small wrapper is needed to launch a background podman system service
# process for the gitlab-runner to connect to. # process for the gitlab-runner to connect to.
ADD /gitlab-runner-wrapper /usr/local/bin/ ADD /gitlab-runner-wrapper /podman-in-podman-maintenance /usr/local/bin/
# Base image UTS NS configuration causes runner to break when launching # Base image UTS NS configuration causes runner to break when launching
# nested rootless containers. # nested rootless containers.
RUN sed -i -r \ RUN sed -i -r \
-e 's/^utsns.+host.*/utsns="private"/' \ -e 's/^utsns.+host.*/utsns="private"/' \
/etc/containers/containers.conf && \ /etc/containers/containers.conf && \
chmod +x /usr/local/bin/gitlab-runner-wrapper && \ chmod +x /usr/local/bin/gitlab-runner-wrapper && \
chmod +x /usr/local/bin/podman-in-podman-maintenance && \
chown -R podman.podman /home/podman && \ chown -R podman.podman /home/podman && \
rm -f /home/podman/.bash* && \ rm -f /home/podman/.bash* && \
echo DOCKER_HOST="unix:///tmp/podman-run-1000/podman/podman.sock" > /etc/profile.d/podman.sh echo DOCKER_HOST="unix:///tmp/podman-run-1000/podman/podman.sock" > /etc/profile.d/podman.sh
@@ -106,10 +107,11 @@ ENTRYPOINT ["/usr/local/bin/gitlab-runner-wrapper"]
# Gitlab-runner configuration options. Default to unprivileged (nested) # Gitlab-runner configuration options. Default to unprivileged (nested)
# runner. Privileged is required to permit nested container image building. # runner. Privileged is required to permit nested container image building.
ARG RUNNER_NAME="qontainers-pipglr"
ARG PRIVILEGED_RUNNER="false" ARG PRIVILEGED_RUNNER="false"
# Tags allow pinning jobs to specific runners, comma-separated list of # Tags allow pinning jobs to specific runners, comma-separated list of
# tags to add to runner (no spaces!) # tags to add to runner (no spaces!)
ARG RUNNER_TAGS="podman_in_podman" ARG RUNNER_TAGS="podman-in-podman"
# Permit running jobs without any tag at all # Permit running jobs without any tag at all
ARG RUNNER_UNTAGGED="true" ARG RUNNER_UNTAGGED="true"
ENV REGISTER_NON_INTERACTIVE="true" \ ENV REGISTER_NON_INTERACTIVE="true" \
@@ -118,6 +120,7 @@ ENV REGISTER_NON_INTERACTIVE="true" \
REGISTER_ACCESS_LEVEL="ref_protected" \ REGISTER_ACCESS_LEVEL="ref_protected" \
REGISTER_MAXIMUM_TIMEOUT="3600" \ REGISTER_MAXIMUM_TIMEOUT="3600" \
CI_SERVER_URL="https://gitlab.com/" \ CI_SERVER_URL="https://gitlab.com/" \
RUNNER_NAME="${RUNNER_NAME}" \
RUNNER_EXECUTOR="docker" \ RUNNER_EXECUTOR="docker" \
RUNNER_SHELL="bash" \ RUNNER_SHELL="bash" \
REGISTER_MAINTENANCE_NOTE="Podman-in-Podman containerized runner" \ REGISTER_MAINTENANCE_NOTE="Podman-in-Podman containerized runner" \
@@ -141,4 +144,4 @@ LABEL register="podman run -it --rm $_pm --secret REGISTRATION_TOKEN,type=env \$
# DEBU[0019] running conmon: /usr/bin/conmon args="[--api-version 1 -c 289...c08 -u 289...c08 -r /usr/bin/crun -b /home/podman/.local/share/containers/storage/overlay-containers/289...c08/userdata -p /tmp/podman-run-1000/containers/overlay-containers/289...c08/userdata/pidfile -n runner-8pxm3xb-project-19009784-concurrent-0-a71b53d132a29e56-predefined-0 --exit-dir /tmp/podman-run-1000/libpod/tmp/exits --full-attach -l k8s-file:/home/podman/.local/share/containers/storage/overlay-containers/289...c08/userdata/ctr.log --log-level debug --syslog --runtime-arg --cgroup-manager --runtime-arg disabled -i --conmon-pidfile /tmp/podman-run-1000/containers/overlay-containers/289...c08/userdata/conmon.pid --exit-command /usr/bin/podman --exit-command-arg --root --exit-command-arg /home/podman/.local/share/containers/storage --exit-command-arg --runroot --exit-command-arg /tmp/podman-run-1000/containers --exit-command-arg --log-level --exit-command-arg debug --exit-command-arg --cgroup-manager --exit-command-arg cgroupfs --exit-command-arg --tmpdir --exit-command-arg /tmp/podman-run-1000/libpod/tmp --exit-command-arg --network-config-dir --exit-command-arg --exit-command-arg --network-backend --exit-command-arg netavark --exit-command-arg --volumepath --exit-command-arg /home/podman/.local/share/containers/storage/volumes --exit-command-arg --runtime --exit-command-arg crun --exit-command-arg --storage-driver --exit-command-arg overlay --exit-command-arg --events-backend --exit-command-arg file --exit-command-arg --syslog --exit-command-arg container --exit-command-arg cleanup --exit-command-arg 289...c08]" # DEBU[0019] running conmon: /usr/bin/conmon args="[--api-version 1 -c 289...c08 -u 289...c08 -r /usr/bin/crun -b /home/podman/.local/share/containers/storage/overlay-containers/289...c08/userdata -p /tmp/podman-run-1000/containers/overlay-containers/289...c08/userdata/pidfile -n runner-8pxm3xb-project-19009784-concurrent-0-a71b53d132a29e56-predefined-0 --exit-dir /tmp/podman-run-1000/libpod/tmp/exits --full-attach -l k8s-file:/home/podman/.local/share/containers/storage/overlay-containers/289...c08/userdata/ctr.log --log-level debug --syslog --runtime-arg --cgroup-manager --runtime-arg disabled -i --conmon-pidfile /tmp/podman-run-1000/containers/overlay-containers/289...c08/userdata/conmon.pid --exit-command /usr/bin/podman --exit-command-arg --root --exit-command-arg /home/podman/.local/share/containers/storage --exit-command-arg --runroot --exit-command-arg /tmp/podman-run-1000/containers --exit-command-arg --log-level --exit-command-arg debug --exit-command-arg --cgroup-manager --exit-command-arg cgroupfs --exit-command-arg --tmpdir --exit-command-arg /tmp/podman-run-1000/libpod/tmp --exit-command-arg --network-config-dir --exit-command-arg --exit-command-arg --network-backend --exit-command-arg netavark --exit-command-arg --volumepath --exit-command-arg /home/podman/.local/share/containers/storage/volumes --exit-command-arg --runtime --exit-command-arg crun --exit-command-arg --storage-driver --exit-command-arg overlay --exit-command-arg --events-backend --exit-command-arg file --exit-command-arg --syslog --exit-command-arg container --exit-command-arg cleanup --exit-command-arg 289...c08]"
# [conmon:d]: failed to write to /proc/self/oom_score_adj: Permission denied # [conmon:d]: failed to write to /proc/self/oom_score_adj: Permission denied
LABEL run="podman run -d --privileged --name gitlab-runner $_pm -p $RUNNER_SESSION_PORT:$RUNNER_SESSION_PORT \$IMAGE run" LABEL run="podman run -d --privileged --name gitlab-runner $_pm \$IMAGE run"

View File

@@ -3,7 +3,11 @@
This container image is built daily from this `Containerfile`, and This container image is built daily from this `Containerfile`, and
made available as: made available as:
* FIXME * `registry.gitlab.com/qontainers/pipglr:latest`
-or-
* `registry.gitlab.com/qontainers/pipglr:<version>`
It's purpose is to provide an easy method to execute a GitLab runner, It's purpose is to provide an easy method to execute a GitLab runner,
to service CI/CD jobs for groups and/or repositories on to service CI/CD jobs for groups and/or repositories on
@@ -30,6 +34,8 @@ configuration, please edit the config.toml file within the
`gitlab-runner-config` volume. `gitlab-runner-config` volume.
Note: These commands assume you have both `podman` and `jq` available. Note: These commands assume you have both `podman` and `jq` available.
Instead of `eval`, if your podman version supports `container runlabel`,
you may use that.
```bash ```bash
$ echo '<registration token>' | podman secret create REGISTRATION_TOKEN - $ echo '<registration token>' | podman secret create REGISTRATION_TOKEN -
@@ -44,6 +50,8 @@ the GitLab runner container may be launched with the following commands.
Note: The first time this is run, startup will take an extended amount Note: The first time this is run, startup will take an extended amount
of time as the runner downloads and runs several (inner) support containers. of time as the runner downloads and runs several (inner) support containers.
As above, instead of `eval`, if your podman version supports `container runlabel`,
you may use that.
Debugging: You may `export PODMAN_RUNNER_DEBUG=debug` to enable inner-podman Debugging: You may `export PODMAN_RUNNER_DEBUG=debug` to enable inner-podman
debugging (or any other supported log level) to stdout. debugging (or any other supported log level) to stdout.

View File

@@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# This script is intended to be called as the entrypoint for
# a podman-in-podman gitlab runner container. Any usage
# outside that context is not supported and may cause harm.
set -e set -e
unset _debug_args unset _debug_args
@@ -9,7 +13,8 @@ fi
if [[ "$1" == "run" ]] && [[ ! -S "/tmp/podman-run-1000/podman/podman.sock" ]]; then if [[ "$1" == "run" ]] && [[ ! -S "/tmp/podman-run-1000/podman/podman.sock" ]]; then
podman $_debug_args system service -t 0 & podman $_debug_args system service -t 0 &
# Prevent SIGHUP propigation to podman process /usr/local/bin/podman-in-podman-maintenance &
# Prevent SIGHUP propagation to podman process
disown -ar disown -ar
fi fi

View File

@@ -0,0 +1,19 @@
#!/bin/bash
# This script is intended to be called by the entrypoint for
# a podman-in-podman gitlab runner container. Any usage
# outside that context is not supported and may cause harm.
set -e
maintain_podman() {
# Two days seems to be a good happy-medium beween filling up
# about 40gig of storage space from moderate CI activity,
# and maintaining a useful level of caching.
while sleep 2d; do
if [[ -n "$PODMAN_RUNNER_DEBUG" ]]; then
echo "$(date --iso-8601=second) ${BASH_SOURCE[0] performing podman maintenance}"
fi
podman system prune --all --force
done
}