Skip to content

Commit

Permalink
add env and pipe ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Ignatev committed Jan 18, 2023
1 parent 4345d1b commit c290419
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
5 changes: 3 additions & 2 deletions charts/bpdispatcher/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ metadata:
labels:
{{- include "bpdispatcher.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "bpdispatcher.selectorLabels" . | nindent 6 }}
Expand Down Expand Up @@ -45,6 +43,9 @@ spec:
httpGet:
path: /ready
port: http
envFrom:
- secretRef:
name: {{ include "bpdispatcher.fullname" . }}-secret
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
11 changes: 11 additions & 0 deletions charts/bpdispatcher/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "bpdispatcher.fullname" . }}-secret
labels:
{{- include "bpdispatcher.labels" . | nindent 4 }}
type: Opaque
data:
{{- range $key, $val := .Values.env }}
{{ $key }}: {{ $val | b64enc }}
{{- end}}
8 changes: 8 additions & 0 deletions charts/bpdispatcher/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ podAnnotations: {}
podSecurityContext: {}
# fsGroup: 2000

# env variables
env:
ACCESS_TOKEN: token_here
REPO_OWNER: repo_owner
REPO_SLUG: repo_slug
PIPELINE_KEY: pipe_key
PIPELINE_REF: master

securityContext: {}
# capabilities:
# drop:
Expand Down
4 changes: 3 additions & 1 deletion cmd/bpdispatcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
RepoOwner, ok2 = os.LookupEnv("REPO_OWNER")
RepoSlug, ok3 = os.LookupEnv("REPO_SLUG")
PipelineKey, ok4 = os.LookupEnv("PIPELINE_KEY")
PipelineRef, ok5 = os.LookupEnv("PIPELINE_REF")
)

type Webhook struct {
Expand Down Expand Up @@ -61,7 +62,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
fmt.Println("Timestamp:", data.Timestamp)
fmt.Fprint(w, "JSON received and parsed!")

if err := pipeline.TriggerPipeline(AccessToken, RepoOwner, RepoSlug, PipelineKey); err != nil {
if err := pipeline.TriggerPipeline(AccessToken, RepoOwner, RepoSlug, PipelineKey, PipelineRef); err != nil {
log.Println("Error:", err)
}
}
Expand All @@ -86,6 +87,7 @@ func main() {
checkEnv("REPO_OWNER", ok2)
checkEnv("REPO_SLUG", ok3)
checkEnv("PIPELINE_KEY", ok4)
checkEnv("PIPELINE_REF", ok5)
http.HandleFunc("/webhook", handleWebhook)
http.HandleFunc("/healthz", livenessProbe)
http.HandleFunc("/ready", readinessProbe)
Expand Down
4 changes: 2 additions & 2 deletions pkg/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"net/http"
)

func TriggerPipeline(accessToken, repoOwner, repoSlug, pipelineKey string) error {
func TriggerPipeline(accessToken, repoOwner, repoSlug, pipelineKey, pipelineRef string) error {
client := &http.Client{}
data := map[string]interface{}{
"target": map[string]string{
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "master",
"ref_name": pipelineRef,
},
}
body, err := json.Marshal(data)
Expand Down

0 comments on commit c290419

Please sign in to comment.