mirror of
https://github.com/khuedoan/homelab.git
synced 2025-01-24 01:36:10 +07:00
feat: auto create Gitea webhook for Tekton
This commit is contained in:
parent
d5eb6d9a76
commit
22a3ccd331
@ -18,14 +18,13 @@ repositories:
|
||||
migrate:
|
||||
source: https://github.com/khuedoan/homelab
|
||||
mirror: false
|
||||
# TODO create webhook (use a global one?)
|
||||
# webhooks:
|
||||
# - http://gitea-webhook.tekton-pipelines:3000
|
||||
hook: true
|
||||
- name: blog
|
||||
owner: khuedoan
|
||||
migrate:
|
||||
source: https://github.com/khuedoan/blog
|
||||
mirror: true
|
||||
hook: true
|
||||
- name: backstage
|
||||
owner: khuedoan
|
||||
migrate:
|
||||
|
@ -23,6 +23,7 @@ type Repository struct {
|
||||
Source string
|
||||
Mirror bool
|
||||
}
|
||||
Hook bool
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@ -48,6 +49,7 @@ func main() {
|
||||
gitea_host := os.Getenv("GITEA_HOST")
|
||||
gitea_user := os.Getenv("GITEA_USER")
|
||||
gitea_password := os.Getenv("GITEA_PASSWORD")
|
||||
webhook_token := os.Getenv("WEBHOOK_TOKEN")
|
||||
|
||||
options := (gitea.SetBasicAuth(gitea_user, gitea_password))
|
||||
client, err := gitea.NewClient(gitea_host, options)
|
||||
@ -89,5 +91,32 @@ func main() {
|
||||
Private: repo.Private,
|
||||
})
|
||||
}
|
||||
|
||||
if repo.Hook {
|
||||
hooks, _, _ := client.ListRepoHooks(repo.Owner, repo.Name, gitea.ListHooksOptions{})
|
||||
if len(hooks) == 0 {
|
||||
_, _, err = client.CreateRepoHook(repo.Owner, repo.Name, gitea.CreateHookOption{
|
||||
Type: gitea.HookTypeGitea,
|
||||
Config: map[string]string{
|
||||
"url": "http://el-workflows-listener.tekton-workflows:8080",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"secret": webhook_token,
|
||||
},
|
||||
Events: []string{
|
||||
"create",
|
||||
"delete",
|
||||
"push",
|
||||
"pull_request",
|
||||
},
|
||||
BranchFilter: "*",
|
||||
Active: true,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Create hook %s/%s: %v", repo.Owner, repo.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ spec:
|
||||
secretKeyRef:
|
||||
name: gitea-admin-secret
|
||||
key: password
|
||||
- name: WEBHOOK_TOKEN
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: gitea-webhook-secret
|
||||
key: token
|
||||
workingDir: /go/src/gitea-config
|
||||
command:
|
||||
- sh
|
||||
|
14
platform/gitea/templates/webhook-secret.yaml
Normal file
14
platform/gitea/templates/webhook-secret.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: gitea-webhook-secret
|
||||
namespace: {{ .Release.Namespace }}
|
||||
spec:
|
||||
secretStoreRef:
|
||||
kind: ClusterSecretStore
|
||||
name: vault
|
||||
data:
|
||||
- secretKey: token
|
||||
remoteRef:
|
||||
key: /tekton/webhook
|
||||
property: token
|
@ -16,4 +16,5 @@ resources:
|
||||
# Workflow
|
||||
- https://storage.googleapis.com/tekton-releases-nightly/workflows/latest/release.yaml
|
||||
# Pre-defined workflows
|
||||
- workflows/webhook-secret.yaml
|
||||
- workflows/master.yaml
|
||||
|
@ -1,7 +1,7 @@
|
||||
apiVersion: workflows.tekton.dev/v1alpha1
|
||||
kind: Workflow
|
||||
metadata:
|
||||
name: blog-master
|
||||
name: master
|
||||
namespace: tekton-workflows
|
||||
spec:
|
||||
triggers:
|
||||
|
14
platform/tekton-pipelines/workflows/webhook-secret.yaml
Normal file
14
platform/tekton-pipelines/workflows/webhook-secret.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: webhook-secret
|
||||
namespace: tekton-workflows
|
||||
spec:
|
||||
secretStoreRef:
|
||||
kind: ClusterSecretStore
|
||||
name: vault
|
||||
data:
|
||||
- secretKey: token
|
||||
remoteRef:
|
||||
key: /tekton/webhook
|
||||
property: token
|
@ -18,3 +18,10 @@
|
||||
- key: password
|
||||
length: 32
|
||||
special: true
|
||||
|
||||
# Tekton
|
||||
- path: tekton/webhook
|
||||
data:
|
||||
- key: token
|
||||
length: 32
|
||||
special: false
|
||||
|
Loading…
Reference in New Issue
Block a user