Jaypore CI

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

commit 13b5c30020e47498dea1a89c99188dab358d4d2c
parent dac9f0d1ed8f3430a82ab1e2eb926c002f027f45
Author: arjoonn <arjoonn@noreply.localhost>
Date:   Mon, 13 Mar 2023 04:52:37 +0000

Test the curl-bash install process (!54)

Branch auto created by JayporeCI

```jayporeci
╔ 🟢 : JayporeCI    [sha 08f37f6882]
┏━ build-and-test
┃
┃ 🟢 : JciEnv       [815dfcf5]   0:11
┃ 🟢 : Jci          [0ba5283e]   0:16            ❮-- ['JciEnv']
┃ 🟢 : black        [a20712ab]   0: 0            ❮-- ['JciEnv']
┃ 🟢 : install-test [e2764b0f]   0: 0            ❮-- ['JciEnv']
┃ 🟢 : pylint       [92200c1d]   0: 9            ❮-- ['JciEnv']
┃ 🟢 : pytest       [d7d228a9]   0:23 Cov: 91%   ❮-- ['JciEnv']
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
```

Co-authored-by: arjoonn sharma <arjoonn.94@gmail.com>
Co-authored-by: demo <demo@example.com>
Reviewed-on: https://gitea.midpathsoftware.com/midpath/jaypore_ci/pulls/54

Diffstat:
MDockerfile | 3++-
Mcicd/cicd.py | 6++++++
Acicd/test_installation.sh | 28++++++++++++++++++++++++++++
Msecrets/bin/edit_env.sh | 2+-
Msetup.sh | 41+++++++++++++++++++++++++++++++----------
5 files changed, 68 insertions(+), 12 deletions(-)

diff --git a/Dockerfile b/Dockerfile @@ -8,10 +8,11 @@ run poetry config virtualenvs.create false run poetry install env PYTHONPATH=/jaypore_ci/run/:/app env PATH=/jaypore_ci/run/:/app:$PATH +env EDITOR=vim add https://github.com/mozilla/sops/releases/download/v3.7.3/sops-v3.7.3.linux /bin/sops add https://github.com/FiloSottile/age/releases/download/v1.0.0/age-v1.0.0-linux-amd64.tar.gz ./age.tar.gz run tar xf ./age.tar.gz && mv ./age/age /bin && mv ./age/age-keygen /bin && rm -rf ./age -run apt update && apt install -y wget curl zip +run apt update && apt install -y wget curl zip vim run chmod u+x /bin/sops /bin/age /bin/age-keygen from jcienv as jci diff --git a/cicd/cicd.py b/cicd/cicd.py @@ -34,6 +34,12 @@ with jci.Pipeline() as p: p.job("black", "python3 -m black --check .", **kwargs) p.job("pylint", "python3 -m pylint jaypore_ci/ tests/", **kwargs) p.job("pytest", "bash cicd/run_tests.sh", image=jcienv, depends_on=["JciEnv"]) + p.job( + "install_test", + "bash cicd/test_installation.sh", + image=jcienv, + depends_on=["JciEnv"], + ) if should.release: with p.stage("Publish", image=jcienv): diff --git a/cicd/test_installation.sh b/cicd/test_installation.sh @@ -0,0 +1,28 @@ +#! /bin/bash + +set -o errexit +set -o nounset +set -o pipefail + + +main() { + mkdir /fake_py_repo + JCI_ROOT=$PWD + cd /fake_py_repo + echo " +print(1 ++ +1)" > code.py + git config --global user.email "fake@email.com" + git config --global user.name "Fake User" + git config --global init.defaultBranch develop + git init + git add -Av + git commit -m 'init' + export RUNNING_IN_CI=yes + bash $JCI_ROOT/setup.sh -y + git add -Av + git commit -m 'installed Jci' +} + +(main) diff --git a/secrets/bin/edit_env.sh b/secrets/bin/edit_env.sh @@ -21,7 +21,7 @@ main (){ if [[ -f "$ENC_FILE" ]]; then sops --decrypt --input-type dotenv --output-type dotenv "$ENC_FILE" > "$PLAINTEXT_FILE" fi - vim "$PLAINTEXT_FILE" + ${EDITOR:-nano} "$PLAINTEXT_FILE" sops --input-type dotenv --output-type dotenv --encrypt --age $(age-keygen -y "$KEY_FILE") "$PLAINTEXT_FILE" > "$ENC_FILE" rm "$PLAINTEXT_FILE" } diff --git a/setup.sh b/setup.sh @@ -30,6 +30,23 @@ should_continue (){ return 1 } +getfile(){ + if [ "$RUNNING_IN_CI" = "yes" ]; then + ROOT='/jaypore_ci/run' + SOURCE=$(echo "$ROOT$1") + if [ -f "$ROOT/cicd$1" ]; then + SOURCE=$(echo "$ROOT/cicd$1") + fi + if [ -f "$ROOT/secrets$1" ]; then + SOURCE=$(echo "$ROOT/secrets$1") + fi + echo "Getting file: $SOURCE $2" + cp $SOURCE $2 + else + wget --quiet -O $2 https://www.jayporeci.in$1 + fi +} + main (){ REPO_ROOT=$(git rev-parse --show-toplevel) LOCAL_HOOK=$(echo $REPO_ROOT/.git/hooks/pre-push) @@ -54,8 +71,8 @@ from jaypore_ci import jci with jci.Pipeline() as p: p.job("Black", "black --check .") EOF - curl -s https://www.jayporeci.in/pre-push.sh -o $REPO_ROOT/cicd/pre-push.sh - curl -s https://www.jayporeci.in/Dockerfile -o $REPO_ROOT/cicd/Dockerfile + getfile /pre-push.sh $REPO_ROOT/cicd/pre-push.sh + getfile /Dockerfile $REPO_ROOT/cicd/Dockerfile chmod u+x $REPO_ROOT/cicd/pre-push.sh # ----------------== ENV_PREFIX='' @@ -68,14 +85,14 @@ EOF if should_continue then echo "Downloading age/ binaries" - wget --quiet -O $HOME/.local/bin/age http://www.jayporeci.in/bin/age & - wget --quiet -O $HOME/.local/bin/age-keygen http://www.jayporeci.in/bin/age-keygen & - wget --quiet -O $HOME/.local/bin/sops http://www.jayporeci.in/bin/sops & + getfile /bin/age $HOME/.local/bin/age & + getfile /bin/age-keygen $HOME/.local/bin/age-keygen & + getfile /bin/sops $HOME/.local/bin/sops & wait fi echo "Downloading edit/set env scripts" - wget --quiet -O secrets/bin/edit_env.sh http://www.jayporeci.in/bin/edit_env.sh & - wget --quiet -O secrets/bin/set_env.sh http://www.jayporeci.in/bin/set_env.sh & + getfile /bin/edit_env.sh secrets/bin/edit_env.sh & + getfile /bin/set_env.sh secrets/bin/set_env.sh & wait echo "Created $REPO_ROOT/secrets/bin" echo "Adding gitignore so that key and plaintext files are never committed" @@ -85,9 +102,13 @@ EOF age-keygen > $REPO_ROOT/secrets/ci.key echo "You can now use (bash secrets/bin/edit_env.sh ci) to edit environment variables." echo "Editing secrets now" - if should_continue - then - (bash $REPO_ROOT/secrets/bin/edit_env.sh ci) + if [ "$RUNNING_IN_CI" = "yes" ]; then + echo "Skip setting env file. Running in CI" + else + if should_continue + then + (bash $REPO_ROOT/secrets/bin/edit_env.sh ci) + fi fi ENV_PREFIX='ENV=ci ' fi