Giter Site home page Giter Site logo

wlun001 / path-change Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 3.0 127 KB

⚠️ Depracated - A server to detect path changes based on glob pattern based on last commit

Dockerfile 2.88% Go 97.12%
tekton tektoncd tekton-pipelines tekton-triggers cluster-interceptor paths path-change diff triggers cicd

path-change's Introduction

⚠️ Depracated in flavour of changed files

Path Change server

Summary

A server for CI/CD pipelines to detect file change based on last commit, with glob pattern, compatible with Tekton ClusterInterceptor .

The behaviour will be similar to github actions paths and cloud build includeFile . Only trigger build when the file changes match the patterns

Not all CI server/service support file change detection feature. This project will make this available to CI servers, for example, Tekton.

Explanation

Assume have the following config

repos:
  demo:
    url: https://github.com/username/repo
    paths:
      - "examples/**"

If last file changes matches the pattern

$ git --no-pager diff --name-only HEAD^
examples/main.go

It will return the following response, with continue set to true

{
  "extensions": {
    "paths": "MATCH"
  },
  "continue": true,
  "status": {}
}

If last file changes not matches

$ git --no-pager diff --name-only HEAD^
util/util.go

It will return the following response, with continue set to false

{
  "extensions": {
    "paths": "NOT_MATCH"
  },
  "continue": false,
  "status": {}
}

Installation

Environment variables

  • PORT port (:8080)
  • CONFIG_FILE config file location
  • APP_ENV app env (dev or prod)
  • SECRET_TOKEN (optional) secret token for webhook

Interceptor Params

- ref:
    name: path-change-interceptor
    kind: ClusterInterceptor
    params:
      - name: repo
        value: demo2 # this will map the values in config.yaml

Config

Config can be updated at examples/02_config.yaml

Can set config file location with CONFIG_FILE env

 containers:
   - name: path-change
     ...
     env:
       - name: CONFIG_FILE
         value: /etc/fc/config.yaml

Setting ref to be read

Most of the webhook has ref on the request body, for example

ref will be retrieved from req.body

Git credentials

The examples show git authentication with ssh, please check examples/02_secret.yaml to replace the actual value.

It works with any git credentials, for examples ssh or git-credential-store. Just mount the related files to home directory volume

webhook secret

if you have set webhook secret, please update the secret at examples/02_secret.yaml

set the secret env at examples/01_deployment

 containers:
   - name: path-change
     ...
     env:
       - name: SECRET_TOKEN
         valueFrom:
           secretKeyRef:
             name: webhook-secret
             key: token

Apply the examples

Make sure you have already installed Tekton Pipelines, Trigger and dashboard

kubectl apply -f examples
tkn hub install task git-clone -n tekton
Testing webhook

For more permanent deployment, consider to use an Ingress to expose it as public url

kubectl port-forward -n tekton service/el-simple-listener 8080

Run a tunnel to test webhook, add the generated URL to webhook

ngrok http 8080

Make some commits on, the tunnel will received status 202, it should trigger the pipeline, can view it from the dashbaord

Testing locally

 curl localhost:8080 -d '{"ref": "refs/heads/main", "repository": {"ssh_url": "[email protected]:WLun001/path-change.gitt"}}' -H 'Content-Type: application/json' -v

Output

*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 93
>
* upload completely sent off: 93 out of 93 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 202 Accepted
< Content-Type: application/json
< Content-Length: 164
<
{"eventListener":"simple-listener","namespace":"tekton","eventListenerUID":"685ffd5e-2a63-46ef-9405-f325e9f1ba94","eventID":"9a6a4530-9aef-4551-ab89-aaaa1c4eae07"}
* Connection #0 to host localhost left intact

it should trigger the pipeline, can view it from the dashbaord

path-change's People

Contributors

wlun001 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.