in ,

cyberark / bash-lib, Hacker News

cyberark / bash-lib, Hacker News


                    

        

_______________ _______________                  . ' . ' . |                . ' . ' . ' |              .'_______________.'______________. ' |              | ___ _____ ___ || ___ _____ ___ | |              || _=_ | __=__ | _=_ |||| _=_ | __=__ | _=_ || |        ______ || _____===_____ |||| _____===_____ || | __________     . ' || _____===_____ |||| _____===_____ || . ' . '|   . ' || _____===_____ |||| _____===_____ || . ' . ' | .'___________ | _______________ || _______________ | .'__________. ' | | .----------. |. ----- ___-----. ||. ----- ___-----. || | _____.----------. |] ||| _____________ |||| _____________ ||| . ' [          |||          ||.-----___-----.||.-----___-----.||.'        |          |||          |||_____________||||_____________|||==========|          |||          ||.-----___-----.||.-----___-----.||    |_____|          ||] o ||| _____________ |||| _____________ ||| . ' [        'o|||          ||.-----___-----.||.-----___-----.||.'        |          |||          |||             ||||_____________|||==========|          |||          |||             |||.-----___-----.||    |_____|          ||] ||| |||| ||| . ' [| || __________ ||| _____________ |||| _____________ ||| .'________ | __________ | `` ----------''' ------------------------------ ''-- -------- ''             (o) LGB (o)

The place to store functions that are used in pipelines for multiple repos.

Please add whatever is useful to you, but keep it tidy so its still useful to everyone else:)

Release Status: Alpha

TL; DR: Ready for use, but needs expansion.

The functions in this repo are tested and ready for use, but certain libs are pretty much place holders (eg logging). Those need further contributions before they provide a comprehensive solution.

License: Apache 2.0

See thelicense file

Usage

Add bash-lib into your project in the way that best fits your workflow. The only requirement is that youpin the version of bash-lib that you use. This is important so that changes to bash-lib do not have the power to break all projects that use bash-lib. Your project can then test updates to bash-lib and roll forward periodicly.

Options:

  • Add a submodule: they are an easy way to integrate bash-lib and automatically use a single SHA until manually updated. Submodules add a pointer from a mount point in your repo to the external repo (bash-lib), and require workflow changes to ensure that pointer is derferenced during clone, checkout and some other opertaions.
  • Add a subtree: This repo uses subtrees to pull in test dependencies. Subtrees copy an external repo into a subdirectory of the host repo, no workflow changes are required. Subtrees naturally keep a single version of bash-lib until explicitly updated. Note that subtree merge commits do not rebase well⚠️, so best to keep subtree updates in separate PRs from normal commits.
  • Clone bash-lib in your deployment process, bash-lib doesn’t have to be within your repo, just needs to be somewhere where your scripts can sourceinit. This is where it’s most important that you implement a mechanism to always use the same SHA, as aclone will track master by default, which is not an allowed use of bash-lib.

Once you have bash- lib cloned in your project, you source two things:

  1. Sourcebash-lib / init. This ensures submodules are initalized and sets the BASH_LIB_DIR env var to the absolute path to the bash-lib dir. This makes it easy to source libraries from other scripts.
  2. Source$ {BASH_LIB_DIR} / lib-name / libfor any libraries you are interested in.

You are now ready to use bash-lib functions:)

Structure

The/ initscript sets up everything required to use the library, most importantly theBASH_LIB_DIRvariable which gives the absolute path to the root of the library and should be used for sourcing the modules.

The repo is organized into libraries, each library is a directory that has a lib file. Sourcing the lib for a library should expose all the functions that library offers. The lib file may source or reference other supporting files within it’s directory.

. ├── libname Ib ├── lib └── └── supporting-file ├── init # init script, source this first ├── run-tests # top level test script, executes all tests ├── secrets.yml # secrets required for executing tests ├── test-utils Ats ats bats # git subtree Ats ats bats-assert-1 # git subtree Ats ats bats-support # git subtree Ib ├── lib 2 tap2junit └── tests-for-this-repo     ├── filehandling.bats     ├── fixtures #     Ib ib libname # Dir containing test fixtures for a library     2 tap2junit     ├── libname.bats # contains tests for libname / lib     ├── python-lint # supporting files for python lint     ├── run-bats-tests # script to run bats tests     ├── run-gitleaks # script to check for leaked secrets     └── run-python-lint # script to run python lint

Contents

      

      

    

      

        

  1. abs_path: Ensure a path is absolute
  2.         

    

      

      

    

      

      

    

      

      

    

      

      

    

      

      

    

Library Description Functions
filehandling Functions relating to file and path handling       
git Git helpers         

  1. repo_root: Find the root of the current git repo.
  2.           

  3. all_files_in_repo: List files tracked by git.
  4.           

  5. remote_latest_tag: Returns the symbolic name of the latest tag from a remote.
  6.           

  7. remote_latest_tagged_commit: Returns the SHA of the most recently tagged commit in a remote repo (tag ^ {}).
  8.           

  9. remote_sha_for_ref: Returns the SHA for a given ref from a named remote.
  10.           

  11. remote_tag_for_sha: Returns the tag corresponding to a SHA from a named remote – if there is one.
  12.           

  13. tracked_files_excluding_subtrees: List files tracked by git, but excluding any files that are in paths listed in.gittrees.
  14.           

  15. cat_gittrees: Returns the contents of .gittrees from the top level of the repo, excluding any comments. Fails if .gittrees is not present.
  16.         

Helpers Bash scripting helpers         

  1. die: print message and exit 1
  2.           

  3. spushd / spopd: Safe verisons of pushd & popd that call die if the push / pop fails, they also drop stdout.
  4.           

  5. Retry : Retry a command until it succeeds up to a user specified maximum number of attempts. Escalating delay between attempts.
  6.         

K8S Utils for connecting to K8s         

  1. build_gke_image: Build docker image for running kubectl commands against GKE.
  2.           

  3. delete_gke_image: Delete image from GKE.
  4.           

  5. run_docker_gke_command: Run command in gke-utils container, already authenticated to k8s cluster.
  6.         

logging Helpers related to login         

  1. announce: Echo message in ascii banner to distinguish it from other log messages.
  2.         

test-utils Helpers for executing tests         

  1. shellcheck_script: Execute shellcheck against a script, uses docker.
  2.           

  3. find_scripts: Find git tracked files with extension.
  4.           

  5. tap2junit: Convert a subset of (TAP) to JUnit XML. Retains logs for errors.
  6.         

For further information on contributing, style & testing, please seeCONTRIBUTING.md

  

Brave Browser
Read More
Payeer

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

Give Firefox a Chance for a Faster, Calmer and Distraction-Free Internet, Hacker News

Can science break its plastic addiction ?, Ars Technica

Can science break its plastic addiction ?, Ars Technica