Jaypore CI

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

commit e7749d1fe71586ae52f56d82d4ab511303da52f3
parent c3ed2e98006f0a6a735edbd3750e63b2fc61c38c
Author: arjoonn <arjoonn@noreply.localhost>
Date:   Sun, 25 Dec 2022 09:31:09 +0000

example_for_commonjobs (!16)

Branch auto created by JayporeCI

<details>
    <summary>JayporeCi: 🟢 50ba3f5fa1</summary>

```mermaid
flowchart TB

            subgraph Pipeline
                direction TB

            end

            subgraph Docker
                direction TB

                s_Docker(( )) -.-> Docker_0(Jci):::passed
                s_Docker(( )) -.-> Docker_1(JciEnv):::passed
            end

            subgraph Jobs
                direction TB

                s_Jobs(( )) -.-> Jobs_0(PublishDocs):::passed
                s_Jobs(( )) -.-> Jobs_1(pytest):::passed
                s_Jobs(( )) -.-> Jobs_2(pylint):::passed
                s_Jobs(( )) -.-> Jobs_3(black):::passed
            end

            subgraph Publish
                direction TB

                s_Publish(( )) -.-> Publish_0(DockerHubJci):::passed
                s_Publish(( )) -.-> Publish_1(DockerHubJcienv):::passed
            end

            Pipeline ---> Docker

            Docker ---> Jobs

            Jobs ---> Publish

            classDef pending fill:#aaa, color:black, stroke:black,stroke-width:2px,stroke-dasharray: 5 5;
            classDef skipped fill:#aaa, color:black, stroke:black,stroke-width:2px;
            classDef assigned fill:#ddd, color:black, stroke:black,stroke-width:2px;
            classDef running fill:#bae1ff,color:black,stroke:black,stroke-width:2px,stroke-dasharray: 5 5;
            classDef passed fill:#88d8b0, color:black, stroke:black;
            classDef failed fill:#ff6f69, color:black, stroke:black;
            classDef timeout fill:#ffda9e, color:black, stroke:black;
```

Co-authored-by: arjoonn sharma <arjoonn@midpathsoftware.com>
Reviewed-on: https://gitea.midpathsoftware.com/midpath/jaypore_ci/pulls/16

Diffstat:
Dcicd/edit_secrets.sh | 38--------------------------------------
Mcicd/pre-push.sh | 8++++++++
Dcicd/set_env.sh | 8--------
Mdocs/source/examples.rst | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msetup.sh | 8++++++++
5 files changed, 79 insertions(+), 46 deletions(-)

diff --git a/cicd/edit_secrets.sh b/cicd/edit_secrets.sh @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o pipefail - -main (){ - NAME=$1 - SOPS_AGE_KEY_FILE=secrets/$NAME.age sops --decrypt --input-type dotenv --output-type dotenv secrets/$NAME.enc > secrets/$NAME.env - vim secrets/$NAME.env - sops --encrypt --age $(age-keygen -y secrets/$NAME.age) secrets/$NAME.env > secrets/$NAME.enc - rm secrets/$NAME.env -} - -help_message (){ - - echo " - Easily edit env files. - Make sure you have age keys available in - - secrets/<envname>.age - - If that is available you can run the following to edit env files. - - edit_secrets.sh <envname> - - Upon exiting the editor the file will be re-encrypted. - " -} - -if [[ $1 == "--help" || $1 == "-h" ]]; then - help_message - exit 0 -fi -if [ -z $1 ]; then - help_message - exit 0 -fi -(main $1) diff --git a/cicd/pre-push.sh b/cicd/pre-push.sh @@ -5,6 +5,14 @@ set -o nounset set -o pipefail +editenv() { + NAME=$1 + SOPS_AGE_KEY_FILE=secrets/$NAME.age sops --decrypt --input-type dotenv --output-type dotenv secrets/$NAME.enc > secrets/$NAME.env + vim secrets/$NAME.env + sops --encrypt --age $(age-keygen -y secrets/$NAME.age) secrets/$NAME.env > secrets/$NAME.enc + rm secrets/$NAME.env +} + run() { export SECRETS_PATH=secrets export SECRETS_FILENAME=jaypore_ci diff --git a/cicd/set_env.sh b/cicd/set_env.sh @@ -1,8 +0,0 @@ -#! /bin/bash - -set -o errexit -set -o nounset -set -o pipefail - - -export $(SOPS_AGE_KEY_FILE=secrets/jaypore_ci.age sops --decrypt --input-type dotenv --output-type dotenv secrets/jaypore_ci.enc | xargs) diff --git a/docs/source/examples.rst b/docs/source/examples.rst @@ -1,6 +1,8 @@ Examples ======== +This document lists things that you can do using JayporeCI + Cache env dependencies in docker -------------------------------- @@ -135,3 +137,64 @@ Having database / other services during CICD p.job("UnitTest", "python3 -m pytest -m unit_tests tests") p.job("IntegrationTest", "python3 -m pytest -m integration_tests tests") p.job("RegressionTest", "python3 -m pytest -m regression_tests tests") + +Common jobs for multiple git repos +---------------------------------- + +- Sometimes we need to enforce common jobs for multiple git projects. A few examples: +- A common lint policy for company / clients. +- Common deploy targets and processes for things like docs / release notes. +- Common locations for built targets / artifact caches. +- Common notification targets like slack / telegram / email. +- Common PR description checklist for company / clients. +- Common PR merge policies / review policies etc. + +Since `JayporeCI` has a normal programming language as it's config language, these things can be solved without too much effort. + +1. Create a custom python file and add your common jobs to a function in that + file. For example if we want to make sure that `Black + <https://github.com/psf/black>`_ is the code formatter for all your + projects: + + .. code-block:: python + + # mycommonjobs.py + def add_common_lint_jobs(p): + p.job("black", "python3 -m black --check .") + +2. Create your own docker file based on top of `arjoonn/jci:latest` and add your own code to it. For example: + + .. code-block:: dockerfile + + from arjoonn/jci:latest + run python -m pip install black + add mycommonjobs.py . + + After this you can build and publish this image to dockerhub. If you don't + want to publish this image you can simply make sure that it is available on + the machine that will run your CI. + +3. Now in any project you can use this docker image in `cicd/pre-push.sh` + instead of `arjoonn/jci:latest`. For example if you pushed this image to + dockerhub with the name `myown/jobs:latest` then you can edit + your `cicd/pre-push.sh` file to have the docker run command look something + like this: + + .. code-block:: bash + + docker run -d \ + # ... Other parameters as it is ... + myown/jobs:latest \ # Instead of arjoonn/jci:latest + # ... Other parameters as it is ... + +4. Inside `cicd/cicd.py` you can now simply import and call your common code function to add those common jobs: + + .. code-block:: python + + from jaypore_ci import jci + from mycommonjobs import add_common_lint_jobs + + with jci.Pipeline() as p: + add_common_lint_jobs(p) + # --- + p.job("Test", "pytest -m unit_tests tests") diff --git a/setup.sh b/setup.sh @@ -29,6 +29,14 @@ set -o nounset set -o pipefail +editenv() { + NAME=\$1 + SOPS_AGE_KEY_FILE=secrets/\$NAME.age sops --decrypt --input-type dotenv --output-type dotenv secrets/\$NAME.enc > secrets/\$NAME.env + vim secrets/\$NAME.env + sops --encrypt --age \$(age-keygen -y secrets/\$NAME.age) secrets/\$NAME.env > secrets/\$NAME.enc + rm secrets/\$NAME.env +} + run() { export SECRETS_PATH=secrets export SECRETS_FILENAME=jaypore_ci