jeudi 29 février 2024

git pre-commit hooks library

cf.  https://codimd.nomadic-labs.com/p/YcXmjg1qv#/4


pre-commit is a tool that helps to configure git pre-commit hooks, with an abundance of already configured scripts


pre-commit install and configuration

  • Install in system

(apt-get / brew ) install pre-commit


  • install in repo 
then in each repo clone (set-up pre-commit for this repo):

pre-commit install


  • then (configure) edit .pre-commit-config.yaml


.pre-commit-config.yaml example  (from https://gitlab.com/tezos/tezos/-/blob/master/.pre-commit-config.yaml?ref_type=heads )

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
  - repo: https://github.com/koalaman/shellcheck-precommit
    rev: v0.9.0
    hooks:
      - id: shellcheck
        args: [ "--external-sources" ]
  - repo: https://github.com/cisagov/pre-commit-shfmt
    rev: v0.0.2
    hooks:
      - id: shfmt
        # These settings must mirror the ones set in `scripts/lint.sh`.
        args: [ "-i", "2", "-sr", "-d" ]
  - repo: https://github.com/arenadotio/pre-commit-ocamlformat
    rev: 0439858
    hooks:
      - id: ocamlformat
        args: [ "-i" ]
  - repo: https://github.com/hadolint/hadolint
    rev: v2.9.3
    hooks:
      - id: hadolint-docker
  - repo: https://github.com/python-jsonschema/check-jsonschema
    rev: 0.28.0
    hooks:
      - id: check-gitlab-ci
        args: ["--verbose"]
        files: '(\.gitlab-ci\.yml|\.gitlab/ci/.*\.yml)'



General Notes about pre-commits


  • runs only against staged files

 

  • to run manually :

pre-commit run --all-files


  • to run 1 check specifically  (example : run only  1 plugin (shfmt) )

pre-commit run shfmt





mardi 20 février 2024

[video] Situation Normal, everything must change

 https://www.youtube.com/watch?v=BnqyOYvKt9w




https://spaconference.org/spa2016/simon-wardley.html


[video] So You Think You Know Git - FOSDEM 2024

 Scott Chacon's FOSDEM 2024 talk on Git Tips and Tricks.



https://www.youtube.com/watch?v=aolI_Rz0ZqY&t=4s



Scott talks about:


00:00 - Introduction

01:06 - About Me (well, Scott Chacon)

02:36 - How Well Do You Know Git?

05:09 - Our Agenda

06:25 - Some Helpful Config Stuff

09:42 - Oldies But Goodies

16:22 - Some New Stuff (You May Not Have Noticed)

23:48 - Some Big Repo Stuff / Monorepo Stuff

33:29 - Some New Github Stuff

35:54 - GitButler


36:50 - End of talk

37:03 - Start of Q&A Session

37:06 - Q: Why does GitHub not do git range diff?

38:28 - Q: Why do submodules suck everywhere?

40:16 - Q: With SSH signing, is it possible to specify more than one key?

40:42 - Q: Why can't --force-with-lease be the default force?

42:33 - Q: If you were back on the Git development team, what direction would you like to see it move in?

44:58 - Q: We all love the Git CLI - but do you ever use any visual tools?

46:41 - That's all folks!-

terraform variable <-> variables {script, gitlab-ci}

 (Ici, ce que vous voulez avant le lien) (Ici vous racontez votre vie)


terraform -> gitlab/script/etc.


src: https://stackoverflow.com/questions/75531444/how-to-use-terraform-variable-into-gitlab-ci-yml

  • Terraform : use an "output" 

locals {
toto = format ("${var.ressource_name_pattern}-something", "cloudfront-edge")
}

output "toto" {
 value = local.toto
}

  • Script: get output from terraform command

foobar = ${terraform output toto}



gitlab -> Terraform


Read environment variables in terraform variables, add TF_VAR_ in front of the variable name,

=> env / exported  "TF_VAR_toto" => variable.tf variable toto





terraform -> gitlab/script/etc. VARIABLE (in project settings)

src https://www.reddit.com/r/Terraform/comments/mwmq4e/comment/gvjo7g3/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

     For example : create an EKS cluster & then create a variable with the KUBECONFIG data in another project which has the code for the apps & trigger the deployment of those apps into newly created cluster using that variable.

    - terragrunt run-all apply --terragrunt-non-interactive -auto-approve tfplan-$CI_COMMIT_SHA
    - terraform output kubectl_config > kubectl_config
    - |
      curl -s -XPUT -H "PRIVATE-TOKEN: $GITLAB_API_RW_PRIVATE_TOKEN" $CI_API_V4_URL/groups/$GROUP_ID/variables/KUBECONFIG \
      --form "value=$(cat kubectl_config)" \
      --form "variable_type=file" \
      --form "protected=false" \
      --form "masked=false" \ 
      --form "environment_scope=*"