Jaypore CI

> Jaypore CI: Minimal, Offline, Local CI system.
Log | Files | Refs | README

commit dd3787cb57cd8a1d129865cd83626400cfa00ddb
parent c6ec416da9a522ff7b5f37593f56be07447fb9cc
Author: arjoonn <arjoonn@noreply.localhost>
Date:   Tue, 14 Mar 2023 13:47:04 +0000

Get pipe ID from cidfile (!64)

Branch auto created by JayporeCI

```jayporeci
╔ 🟢 : JayporeCI       [sha dbad68b0e1]
┏━ build-and-test
┃
┃ 🟢 : JciEnv          [a64f2db0]   0:50
┃ 🟢 : Jci             [97d9f8a5]   0:16            ❮-- ['JciEnv']
┃ 🟢 : black           [8a8c8bca]   0: 0            ❮-- ['JciEnv']
┃ 🟢 : install-test    [406462a2]   0: 0            ❮-- ['JciEnv']
┃ 🟢 : pylint          [b035e604]   0: 8            ❮-- ['JciEnv']
┃ 🟢 : pytest          [208eeeb6]   0:24 Cov: 91%   ❮-- ['JciEnv']
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┏━ Publish
┃
┃ 🟢 : DockerHubJci    [ccd9c668]   2: 7
┃ 🟢 : DockerHubJcienv [0932e3ad]   1:50
┃ 🟢 : PublishDocs     [517311b8]   0:41
┃ 🟢 : PublishPypi     [7c69ca81]   0: 6 v0.2.25
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
```

Co-authored-by: demo <demo@example.com>
Reviewed-on: https://gitea.midpathsoftware.com/midpath/jaypore_ci/pulls/64

Diffstat:
MREADME.md | 3++-
Mcicd/pre-push.sh | 8++++++++
Mdocs/source/index.rst | 6++++--
Mjaypore_ci/executors/docker.py | 1+
Mjaypore_ci/jci.py | 25+++++++++++++++----------
Mpyproject.toml | 2+-
Mtests/conftest.py | 1+
Atests/jayporeci_patch.py | 8++++++++
8 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/README.md b/README.md @@ -6,7 +6,8 @@ Documentation is at : https://www.jayporeci.in - Github is only the mirror for this codebase. - Actual development is on a personal gitea instance. -- Please use github to file issues / PRs and I'll get them merged when I have time. +- Please use github discussions for describing problems / asking for help / adding ideas. +- If you want you can submit PRs and I'll get them merged as and when I have time. ## Usage diff --git a/cicd/pre-push.sh b/cicd/pre-push.sh @@ -10,6 +10,7 @@ run() { echo "ENV : ? -> SKIP sourcing from secrets." else echo "ENV : '$ENV' -> Sourcing from secrets" + echo "---" source /jaypore_ci/repo/secrets/bin/set_env.sh $ENV fi env | awk -F\= '{print $1}' @@ -17,6 +18,10 @@ run() { cd /jaypore_ci/run/ git clean -fdx # Change the name of the file if this is not cicd.py + echo "---- Run container ID:" + cat /jaypore_ci/cidfiles/$SHA + echo + echo "---- =======" python /jaypore_ci/run/$JAYPORE_CODE_DIR/cicd.py } @@ -33,6 +38,7 @@ hook() { # # We also pass docker.sock and the docker executable to the run so that # jaypore_ci can create docker containers + mkdir -p /tmp/jayporeci__cidfiles &> /dev/null echo '----------------------------------------------' echo "JayporeCi: " docker build \ @@ -46,6 +52,8 @@ hook() { -e SHA=$SHA \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /tmp/jayporeci__src__$SHA:/jaypore_ci/run \ + -v /tmp/jayporeci__cidfiles:/jaypore_ci/cidfiles:ro \ + --cidfile /tmp/jayporeci__cidfiles/$SHA \ --workdir /jaypore_ci/run \ im_jayporeci__pipe__$SHA \ bash -c "ENV=$ENV bash /jaypore_ci/repo/$JAYPORE_CODE_DIR/pre-push.sh run" diff --git a/docs/source/index.rst b/docs/source/index.rst @@ -393,10 +393,12 @@ commit message contains **jci:release** as one of it's lines. if p.repo.commit_message.contains("jci:release"): p.job("release", "bash cicd/release.sh", depends_on=["build"]) -[`💬 <https://github.com/theSage21/jaypore_ci/discussions/20>`_ ] Select remote based on job status / branch / authors +`💬 <https://github.com/theSage21/jaypore_ci/discussions/20>`_ :Select remote based on job status / branch / authors ------------------------------------------------------------- - `Discuss this workflow on github <https://github.com/theSage21/jaypore_ci/discussions/20>`_ +.. note:: + If you want this feature please go and vote for it on the `github + discussion https://github.com/theSage21/jaypore_ci/discussions/20>`_. At times it's necessary to inform multiple people about CI failues / passing. diff --git a/jaypore_ci/executors/docker.py b/jaypore_ci/executors/docker.py @@ -129,6 +129,7 @@ class Docker(Executor): "volumes": [ "/var/run/docker.sock:/var/run/docker.sock", "/usr/bin/docker:/usr/bin/docker:ro", + "/tmp/jayporeci__cidfiles:/jaypore_ci/cidfiles:ro", f"/tmp/jayporeci__src__{self.pipeline.remote.sha}:/jaypore_ci/run", ], "name": self.get_job_name(job), diff --git a/jaypore_ci/jci.py b/jaypore_ci/jci.py @@ -3,7 +3,6 @@ The code submodule for Jaypore CI. """ import time import os -import subprocess from itertools import product from collections import defaultdict from typing import List, Union, Callable @@ -242,15 +241,7 @@ class Pipeline: # pylint: disable=too-many-instance-attributes self.reporter = reporter if reporter is not None else reporters.text.Text() self.poll_interval = poll_interval self.stages = ["Pipeline"] - self.pipe_id = ( - subprocess.check_output( - "cat /proc/self/cgroup | grep name= | awk -F/ '{print $3}'", - shell=True, - stderr=subprocess.STDOUT, - ) - .decode() - .strip() - ) + self.__pipe_id__ = None self.executor.set_pipeline(self) # --- kwargs["image"] = kwargs.get("image", "arjoonn/jci:latest") @@ -260,6 +251,20 @@ class Pipeline: # pylint: disable=too-many-instance-attributes self.pipe_kwargs = kwargs self.stage_kwargs = None + @property + def pipe_id(self): + if self.__pipe_id__ is None: + self.__pipe_id__ = self.__get_pipe_id__() + return self.__pipe_id__ + + def __get_pipe_id__(self): + """ + This is mainly here so that during testing we can override this and + provide a different way to get the pipe id + """ + with open(f"/jaypore_ci/cidfiles/{self.repo.sha}", "r", encoding="utf-8") as fl: + return fl.read().strip() + def logging(self): """ Return a logger with information about the current pipeline bound to diff --git a/pyproject.toml b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "jaypore_ci" -version = "0.2.23" +version = "0.2.25" description = "" authors = ["arjoonn sharma <arjoonn.94@gmail.com>"] homepage = "https://www.jayporeci.in/" diff --git a/tests/conftest.py b/tests/conftest.py @@ -5,6 +5,7 @@ import pytest import tests.subprocess_mock # pylint: disable=unused-import import tests.docker_mock # pylint: disable=unused-import from tests.requests_mock import add_gitea_mocks, add_github_mocks, Mock +import tests.jayporeci_patch # pylint: disable=unused-import from jaypore_ci import jci, executors, remotes, reporters, repos diff --git a/tests/jayporeci_patch.py b/tests/jayporeci_patch.py @@ -0,0 +1,8 @@ +from jaypore_ci import jci + + +def __get_pipe_id__(self): + return f"fake_docker_container_id_{self.repo.sha}" + + +jci.Pipeline.__get_pipe_id__ = __get_pipe_id__