cloud-native-robotz-hackathon / infrastructure

0 stars 0 forks source link

Try pipeline as code & gitea #28

Open rbo opened 4 days ago

rbo commented 2 days ago

PaC Works with webhook:

https://gitea.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com/team-1/starter-app-python/settings/hooks

image

And a token: https://gitea.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com/user/settings/applications

image

rbo commented 2 days ago

At the OpenShift Cluster

apiVersion: pipelinesascode.tekton.dev/v1alpha1
kind: Repository
metadata:
  creationTimestamp: '2024-06-27T09:05:18Z'
  generation: 4
  name: git-starter-app-python
  namespace: team-1-dev
spec:
  git_provider:
    secret:
      key: provider.token
      name: git-starter-app-python-token-8gxxt
    url: 'https://gitea.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com/'
    webhook_secret:
      key: webhook.secret
      name: git-starter-app-python-token-8gxxt
  url: 'https://gitea.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com/team-1/starter-app-python'
rbo commented 2 days ago

Create token via API:

$ curl -X 'POST'   'https://gitea.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com/api/v1/users/team-1/tokens'   -H 'accept: application/json' -u opentlc-mgr:openshift   -H 'Content-Type: a
pplication/json'   -d '{"name": "asdf","scopes": ["write:repository"]}'
{"id":2,"name":"asdf","sha1":"b2bf8019e15f0d38f9dceb2ba85b07ee24ee9e0e","token_last_eight":"24ee9e0e","scopes":null}
$ curl -s -H "Content-Type: application/json" -u opentlc-mgr:openshift ${GITEA}/api/v1/users/team-1/tokens | jq
[
  {
    "id": 2,
    "name": "asdf",
    "sha1": "",
    "token_last_eight": "24ee9e0e",
    "scopes": [
      "write:repository"
    ]
  },
  {
    "id": 1,
    "name": "tesr",
    "sha1": "",
    "token_last_eight": "c0d53d97",
    "scopes": [
      "write:repository"
    ]
  }
]
$ 
rbo commented 2 days ago

Webhook api


$ curl -s -H "Content-Type: application/json" -u opentlc-mgr:openshift ${GITEA}/api/v1/repos//team-1/starter-app-python/hooks | jq
[
  {
    "id": 1,
    "type": "gitea",
    "branch_filter": "*",
    "config": {
      "content_type": "json",
      "url": "https://pipelines-as-code-controller-openshift-pipelines.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com"
    },
    "events": [
      "push"
    ],
    "authorization_header": "",
    "active": true,
    "updated_at": "2024-06-28T15:46:35Z",
    "created_at": "2024-06-27T09:02:30Z"
  }
]

$ curl -X 'POST' \
  'https://gitea.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com/api/v1/repos/team-1/starter-app-python/hooks' \
  -H 'accept: application/json'  -u opentlc-mgr:openshift  \
  -H 'Content-Type: application/json' \
  -d '{
  "active": true,
  "branch_filter": "*",
    "config": {
      "content_type": "json",
      "url": "https://pipelines-as-code-controller-openshift-pipelines.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com"
    },
    "events": [
      "push"
    ],
"type": "gitea"
}'
{"id":2,"type":"gitea","branch_filter":"*","config":{"content_type":"json","url":"https://pipelines-as-code-controller-openshift-pipelines.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com"},"events":["push"],"authorization_header":"","active":true,"updated_at":"2024-06-28T16:34:29Z","created_at":"2024-06-28T16:34:29Z"}
$ curl -s -H "Content-Type: application/json" -u opentlc-mgr:openshift ${GITEA}/api/v1/repos//team-1/starter-app-python/hooks | jq
[
  {
    "id": 1,
    "type": "gitea",
    "branch_filter": "*",
    "config": {
      "content_type": "json",
      "url": "https://pipelines-as-code-controller-openshift-pipelines.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com"
    },
    "events": [
      "push"
    ],
    "authorization_header": "",
    "active": true,
    "updated_at": "2024-06-28T15:46:35Z",
    "created_at": "2024-06-27T09:02:30Z"
  },
  {
    "id": 2,
    "type": "gitea",
    "branch_filter": "*",
    "config": {
      "content_type": "json",
      "url": "https://pipelines-as-code-controller-openshift-pipelines.apps.cluster-2q7fv.2q7fv.sandbox2813.opentlc.com"
    },
    "events": [
      "push"
    ],
    "authorization_header": "",
    "active": true,
    "updated_at": "2024-06-28T16:34:29Z",
    "created_at": "2024-06-28T16:34:29Z"
  }
]
$