Skip to content

Commit

Permalink
fix(cr-gateway): Remove GitHub API requirement from CR server.
Browse files Browse the repository at this point in the history
Relates to brigadecore#225
  • Loading branch information
technosophos committed Jan 9, 2018
1 parent 419e279 commit 0b4a23a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
1 change: 1 addition & 0 deletions brigade-worker/prestart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const process = require("process")
const fs = require("fs")

// Worker should always set both env vars. The defaults are for local testing.
const script = process.env.BRIGADE_SCRIPT || "/etc/brigade/script"
const vcsScript = process.env.BRIGADE_VCS_SCRIPT || "/vcs/brigade.js"

Expand Down
3 changes: 1 addition & 2 deletions charts/brigade-project/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ cloneURL: "https://github.com/deis/empty-testbed.git"
sharedSecret: "IBrakeForSeaBeasts"

# OPTIONAL: Use this to have Brigade update your project about the build.
# You probably want this if you want pull requests or commits to show
# the build status.
# This is REQUIRED for the GitHub gateway, but optional otherwise.
github: {}
# token: "github oauth token"

Expand Down
18 changes: 4 additions & 14 deletions pkg/webhook/dockerhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,24 @@ func (s *dockerPushHook) Handle(c *gin.Context) {
return
}

// This will clone the repo before responding to the webhook. We need
// to make sure that this doesn't cause the hook to hang up.
brigadeJS, err := s.getFile(commit, "./brigade.js", proj)
if err != nil {
log.Printf("aborting DockerImagePush event due to error: %s", err)
c.JSON(http.StatusBadRequest, gin.H{"status": "brigadejs not found"})
return
}

go s.notifyDockerImagePush(proj, commit, body, brigadeJS)
go s.notifyDockerImagePush(proj, commit, body)
c.JSON(200, gin.H{"status": "Success"})
}

func (s *dockerPushHook) notifyDockerImagePush(proj *brigade.Project, commit string, payload, brigadeJS []byte) {
if err := s.doDockerImagePush(proj, commit, payload, brigadeJS); err != nil {
func (s *dockerPushHook) notifyDockerImagePush(proj *brigade.Project, commit string, payload []byte) {
if err := s.doDockerImagePush(proj, commit, payload); err != nil {
log.Printf("failed dockerimagepush event: %s", err)
}

}

func (s *dockerPushHook) doDockerImagePush(proj *brigade.Project, commit string, payload, brigadeJS []byte) error {
func (s *dockerPushHook) doDockerImagePush(proj *brigade.Project, commit string, payload []byte) error {
b := &brigade.Build{
ProjectID: proj.ID,
Type: "image_push",
Provider: "dockerhub",
Commit: commit,
Payload: payload,
Script: brigadeJS,
}
return s.store.CreateBuild(b)
}
7 changes: 1 addition & 6 deletions pkg/webhook/dockerhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import (
)

func TestDoDockerImagePush(t *testing.T) {
script := `events.dockerhub = function(e) {
if (e.payload.push_data.tag == "latest") {
throw "Unexpected test: " + e.payload.push_data.tag
}
}`
proj := &brigade.Project{
ID: "brigade-1234",
Name: "org/proj",
Expand All @@ -32,7 +27,7 @@ func TestDoDockerImagePush(t *testing.T) {

hook := NewDockerPushHook(&testStore{})

if err := hook.doDockerImagePush(proj, commit, []byte(exampleWebhook), []byte(script)); err != nil {
if err := hook.doDockerImagePush(proj, commit, []byte(exampleWebhook)); err != nil {
t.Errorf("failed docker image push: %s", err)
}
}
Expand Down

0 comments on commit 0b4a23a

Please sign in to comment.