From 16b15426f6c631278a98180a4156337769c7b662 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Mar 20 2020 14:29:35 +0000 Subject: Adjust the project for openshift deployment - Add a Dockerfile to build the project - Add an entrypoint.sh file called when starting the project in openshift - Hide password from the logs if the command failed - Do regular prints in openshift so the lines show in the logs (triggered via an environment variable) Signed-off-by: Pierre-Yves Chibon --- diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..34f29c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# This Dockerfile is used to build and run monitor-gating on Openshift +FROM fedora:31 + +LABEL maintainer "Pierre-Yves Chibon " + +RUN dnf -y install python3-requests bodhi-client fedpkg fedpkg-stage \ + python3-toml git python3-koji python3-fedora-messaging cracklib-dicts \ + && dnf clean all && mkdir /.ssh && mkdir /.fedora + +COPY . /opt/code + +RUN echo "packagerbot" > /.fedora.upn \ + && chgrp -R 0 /opt/code \ + && chmod -R g=u /opt/code \ + && chgrp -R 0 /.ssh \ + && chmod -R g=u /.ssh \ + && chgrp -R 0 /.fedora \ + && chmod -R g=u /.fedora \ + && chmod g=u /etc/passwd \ + && id + + +USER 1000 +WORKDIR / +ENTRYPOINT ["sh", "/opt/code/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..ff57bbb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if ! whoami &> /dev/null; then + if [ -w /etc/passwd ]; then + echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd + fi +fi + +ln -s /opt/ssh/id_rsa /.ssh/id_rsa || true +kinit monitor-gating/os-master01.stg.phx2.fedoraproject.org@STG.FEDORAPROJECT.ORG -kt /etc/keytabs/koji-keytab +ssh-keyscan pkgs.stg.fedoraproject.org >> /.ssh/known_hosts +python3 /opt/code/runner.py /opt/config/runner.cfg diff --git a/runner.py b/runner.py index 0c3be7b..7ef762e 100644 --- a/runner.py +++ b/runner.py @@ -55,7 +55,7 @@ def schedule(conf): delay = conf["delay"] delay_when_failing = conf["delay_when_failing"] blocker_tags = conf["blocker_tags"] - print("Tests started:", datetime.datetime.utcnow()) + print("Tests started:", datetime.datetime.utcnow(), flush=True) try: # Single Build Gating single_args = conf["workflow_single_gating_args"].split() @@ -97,17 +97,19 @@ def schedule(conf): } ) - print("Tests finished:", datetime.datetime.utcnow()) + print("Tests finished:", datetime.datetime.utcnow(), flush=True) except Exception as err: - print(f"Tests failed with: {err}") + print(f"Tests failed with: {err}", flush=True) print(sys.exc_info()[0]) blocking_issues = utils.blocking_issues(blocker_tags) + now = datetime.datetime.utcnow().strftime("%H:%M:%S") if blocking_issues: - print(f"Next run in: {delay_when_failing} seconds because of {len(blocking_issues)} open issues") + print(f"{now} Next run in: {delay_when_failing} seconds because of " + f"{len(blocking_issues)} open issues", flush=True) s.enter(delay_when_failing, 1, schedule, argument=(conf,)) else: - print(f"Next run in: {delay} seconds") + print(f"{now} Next run in: {delay} seconds", flush=True) s.enter(delay, 1, schedule, argument=(conf,)) diff --git a/utils.py b/utils.py index e7d0563..67ebf53 100644 --- a/utils.py +++ b/utils.py @@ -60,7 +60,10 @@ class MonitoringUtils: else: content = "{} {}".format(content.ljust(spaces), "[FAILED]") else: - end = "\r" + if os.environ.get("OPENSHIFT"): + end = None + else: + end = "\r" now = datetime.datetime.utcnow() time = now.strftime("%H:%M:%S") @@ -715,6 +718,9 @@ def run_command(command, cwd=None): command, cwd=cwd, stderr=subprocess.PIPE ) except subprocess.CalledProcessError as e: + if "--password" in command: + idx = command.index("--password") + command[idx + 1] = "" _log.error( "Command `{}` return code: `{}`".format( " ".join(command), e.returncode