mirror of
https://github.com/khuedoan/homelab.git
synced 2025-07-16 10:49:43 +07:00
feat: auto create Gitea webhook for Tekton
This commit is contained in:
@ -18,14 +18,13 @@ repositories:
|
|||||||
migrate:
|
migrate:
|
||||||
source: https://github.com/khuedoan/homelab
|
source: https://github.com/khuedoan/homelab
|
||||||
mirror: false
|
mirror: false
|
||||||
# TODO create webhook (use a global one?)
|
hook: true
|
||||||
# webhooks:
|
|
||||||
# - http://gitea-webhook.tekton-pipelines:3000
|
|
||||||
- name: blog
|
- name: blog
|
||||||
owner: khuedoan
|
owner: khuedoan
|
||||||
migrate:
|
migrate:
|
||||||
source: https://github.com/khuedoan/blog
|
source: https://github.com/khuedoan/blog
|
||||||
mirror: true
|
mirror: true
|
||||||
|
hook: true
|
||||||
- name: backstage
|
- name: backstage
|
||||||
owner: khuedoan
|
owner: khuedoan
|
||||||
migrate:
|
migrate:
|
||||||
|
@ -23,6 +23,7 @@ type Repository struct {
|
|||||||
Source string
|
Source string
|
||||||
Mirror bool
|
Mirror bool
|
||||||
}
|
}
|
||||||
|
Hook bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@ -48,6 +49,7 @@ func main() {
|
|||||||
gitea_host := os.Getenv("GITEA_HOST")
|
gitea_host := os.Getenv("GITEA_HOST")
|
||||||
gitea_user := os.Getenv("GITEA_USER")
|
gitea_user := os.Getenv("GITEA_USER")
|
||||||
gitea_password := os.Getenv("GITEA_PASSWORD")
|
gitea_password := os.Getenv("GITEA_PASSWORD")
|
||||||
|
webhook_token := os.Getenv("WEBHOOK_TOKEN")
|
||||||
|
|
||||||
options := (gitea.SetBasicAuth(gitea_user, gitea_password))
|
options := (gitea.SetBasicAuth(gitea_user, gitea_password))
|
||||||
client, err := gitea.NewClient(gitea_host, options)
|
client, err := gitea.NewClient(gitea_host, options)
|
||||||
@ -89,5 +91,32 @@ func main() {
|
|||||||
Private: repo.Private,
|
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:
|
secretKeyRef:
|
||||||
name: gitea-admin-secret
|
name: gitea-admin-secret
|
||||||
key: password
|
key: password
|
||||||
|
- name: WEBHOOK_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: gitea-webhook-secret
|
||||||
|
key: token
|
||||||
workingDir: /go/src/gitea-config
|
workingDir: /go/src/gitea-config
|
||||||
command:
|
command:
|
||||||
- sh
|
- 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
|
# Workflow
|
||||||
- https://storage.googleapis.com/tekton-releases-nightly/workflows/latest/release.yaml
|
- https://storage.googleapis.com/tekton-releases-nightly/workflows/latest/release.yaml
|
||||||
# Pre-defined workflows
|
# Pre-defined workflows
|
||||||
|
- workflows/webhook-secret.yaml
|
||||||
- workflows/master.yaml
|
- workflows/master.yaml
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
apiVersion: workflows.tekton.dev/v1alpha1
|
apiVersion: workflows.tekton.dev/v1alpha1
|
||||||
kind: Workflow
|
kind: Workflow
|
||||||
metadata:
|
metadata:
|
||||||
name: blog-master
|
name: master
|
||||||
namespace: tekton-workflows
|
namespace: tekton-workflows
|
||||||
spec:
|
spec:
|
||||||
triggers:
|
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
|
- key: password
|
||||||
length: 32
|
length: 32
|
||||||
special: true
|
special: true
|
||||||
|
|
||||||
|
# Tekton
|
||||||
|
- path: tekton/webhook
|
||||||
|
data:
|
||||||
|
- key: token
|
||||||
|
length: 32
|
||||||
|
special: false
|
||||||
|
Reference in New Issue
Block a user