gravitee-lab3 / svelte-workshop-backend

An Express backend for the https://github.com/gravitee-lab3/svelte-workshop
0 stars 0 forks source link

Add endpoint to get pipeline configuration file (and above all to get its parameters definition) #1

Open Jean-Baptiste-Lasselle opened 3 years ago

Jean-Baptiste-Lasselle commented 3 years ago

What I want, is that in the web app, the form to trigger the pipeline automatically adapts to the parameters, according the pipeline's configuration file :

SECRETHUB_ORG=gravitee-lab
SECRETHUB_REPO=cicd
# Nevertheless, I today think :
# Each team member should have his own personal secrethub repo in the [graviteeio] secrethub org.
# like this :
# a [graviteeio/${TEAM_MEMBER_NAME}] secrethub repo for each team member
# and the Circle CI Personal Access token stored with [graviteeio/${TEAM_MEMBER_NAME}/circleci/token]
# ---
export HUMAN_NAME=jblasselle
export CCI_TOKEN=$(secrethub read "${SECRETHUB_ORG}/${SECRETHUB_REPO}/humans/${HUMAN_NAME}/circleci/token")

export ORG_NAME="gravitee-lab3"

curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Circle-Token: ${CCI_TOKEN}" https://circleci.com/api/v2/me | jq .

# https://circleci.com/docs/api/v1/#projects

curl -iv -X GET https://circleci.com/api/v1.1/projects  -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Circle-Token: ${CCI_TOKEN}" | tail -n 1 | jq > all-followed-projects.json

# and to see this list is across all Github org,
# you can get the HTTP URL of each of those projects like this :  

curl -X GET https://circleci.com/api/v1.1/projects  -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Circle-Token: ${CCI_TOKEN}" | jq ' .[].vcs_url'

# you can also get the list of all git branches for eahc project, like this : 
curl -X GET https://circleci.com/api/v1.1/projects  -H 'Content-Type: application/json' -H 'Accept: application/json' -H "Circle-Token: ${CCI_TOKEN}" | jq ' .[].branches' | jq 'with_entries(.value = (.value | type))'

Now,this is where I Willneed Github OAuth :

2021-01-17T02:47:00.714259+00:00 app[web.1]: >>>>>>>>>>>>>>> GITHUB API RESPONSE (FOR AUTHENTICATED USER) IS :
2021-01-17T02:47:00.714448+00:00 app[web.1]: {
2021-01-17T02:47:00.714448+00:00 app[web.1]: login: 'Jean-Baptiste-Lasselle',
2021-01-17T02:47:00.714448+00:00 app[web.1]: id: 35227860,
2021-01-17T02:47:00.714449+00:00 app[web.1]: node_id: 'MDQ6VXNlcjM1MjI3ODYw',
2021-01-17T02:47:00.714449+00:00 app[web.1]: avatar_url: 'https://avatars2.githubusercontent.com/u/35227860?v=4',
2021-01-17T02:47:00.714450+00:00 app[web.1]: gravatar_id: '',
2021-01-17T02:47:00.714450+00:00 app[web.1]: url: 'https://api.github.com/users/Jean-Baptiste-Lasselle',
2021-01-17T02:47:00.714450+00:00 app[web.1]: html_url: 'https://github.com/Jean-Baptiste-Lasselle',
2021-01-17T02:47:00.714451+00:00 app[web.1]: followers_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/followers',
2021-01-17T02:47:00.714451+00:00 app[web.1]: following_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/following{/other_user}',
2021-01-17T02:47:00.714451+00:00 app[web.1]: gists_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/gists{/gist_id}',
2021-01-17T02:47:00.714452+00:00 app[web.1]: starred_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/starred{/owner}{/repo}',
2021-01-17T02:47:00.714452+00:00 app[web.1]: subscriptions_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/subscriptions',
2021-01-17T02:47:00.714453+00:00 app[web.1]: organizations_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/orgs',
2021-01-17T02:47:00.714453+00:00 app[web.1]: repos_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/repos',
2021-01-17T02:47:00.714453+00:00 app[web.1]: events_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/events{/privacy}',
2021-01-17T02:47:00.714453+00:00 app[web.1]: received_events_url: 'https://api.github.com/users/Jean-Baptiste-Lasselle/received_events',
2021-01-17T02:47:00.714453+00:00 app[web.1]: type: 'User',
2021-01-17T02:47:00.714454+00:00 app[web.1]: site_admin: false,
2021-01-17T02:47:00.714454+00:00 app[web.1]: name: null,
2021-01-17T02:47:00.714454+00:00 app[web.1]: company: 'Gravitee.io',
2021-01-17T02:47:00.714454+00:00 app[web.1]: blog: 'https://gravitee.io',
2021-01-17T02:47:00.714455+00:00 app[web.1]: location: 'Paris',
2021-01-17T02:47:00.714455+00:00 app[web.1]: email: null,
2021-01-17T02:47:00.714455+00:00 app[web.1]: hireable: null,
2021-01-17T02:47:00.714456+00:00 app[web.1]: bio: 'Fullstack architect, I totally fell into openstack years ago, then docker, n K8S. I focus on how you develop & operate software in a microservices world',
2021-01-17T02:47:00.714458+00:00 app[web.1]: twitter_username: null,
2021-01-17T02:47:00.714458+00:00 app[web.1]: public_repos: 198,
2021-01-17T02:47:00.714458+00:00 app[web.1]: public_gists: 4,
2021-01-17T02:47:00.714458+00:00 app[web.1]: followers: 10,
2021-01-17T02:47:00.714459+00:00 app[web.1]: following: 29,
2021-01-17T02:47:00.714459+00:00 app[web.1]: created_at: '2018-01-08T14:35:44Z',
2021-01-17T02:47:00.714459+00:00 app[web.1]: updated_at: '2021-01-15T12:52:29Z'
2021-01-17T02:47:00.714459+00:00 app[web.1]: }

Now retrieving all those informations from both Github and Circle CI API v1, will be a btach job, that will need the Github API Token obtained from the Github OAuth:

Ok so the Batch job will take a parameter : the Github API scoped Token. With this token, the batch will get the user name , and use it to persist job result to database :

Jean-Baptiste-Lasselle commented 3 years ago

even better, simpler example of pushed notifications from mongodb (perfect mongo) : https://dev.to/m10otb/real-time-notification-web-app-2ebn

Ok,n SO i'll o that one :

Jean-Baptiste-Lasselle commented 3 years ago

I will use exact same pattern, batch job and mongo db , to reactively update web ui for piplines execution state : it will be a sync, wtih a force sync button, Or... I don't know... actually no, it will be so much simpler to just limit API call to update execution state for each pipeline, or for a page of pipelines.... Yeah I just pull the pipeline states, I really don't care about seeing more than what I have on page, I don't want to conduct like large sets metrics calculations , it's always just about displaying the state of a few pipelines.

Jean-Baptiste-Lasselle commented 3 years ago

yes indeed : what i do ned to be extremely reactive, pushed and solid, etc... is the git repos list, the branch list as well

All in all :say I have a new Pipeline execution and it shows a new git branch , between two syncs :

pipeline executions state are going to be pushed, but with rate limit like every 3 seconds (slow), and the push updates the database iff there are differences between persisted state, and new state

Jean-Baptiste-Lasselle commented 3 years ago
Jean-Baptiste-Lasselle commented 3 years ago

Conclusion of analysis : 2 main tasks

Task 1 : database persistence + Docekrize

Alright, So :

Finally , Dockerize everything, I wan in the end a docker-compse and a helmchart (tested on K3D) with :

later:

being able to persist to dataabse, shoudl be enough to implement all Endpoints in next Task :

Task 2 : create the needed Express Endpoint

Github API Client methods used by the batch and the Express Endpoints for pull :

For pull :

Ok, so all in all, here what is new,is that I want to remember the values of the passed parameters : can Jenkins tell you that?I am not sure.

Task 3 : POC on push

Ok, So here I will need to experiment to websocket and push pattern :

Jean-Baptiste-Lasselle commented 3 years ago

Future

Now, In this web ui ghallagher,I have a database with all pipeline parameters valeus for every Invocations :