diff --git a/.travis.yml b/.travis.yml index 2baf204..fafbaa0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,11 @@ script: --description "All-in-one PXE booting" --url "https://github.com/google/netboot" ./pixiecore=/usr/bin/pixiecore env: + # packagecloud.io API key secure: "S8R+j1uSi0+gZHcEI7lZGkECWXTv50d/g23kKaIH7HHgQO2ljplSE0egkWRr5s0yQnDuBRAw0bLfN9EI2IYo/iTEuBuACoO0fg/FnyJnrlNcugUeejMdbXbAgrI6phTqqr+LGmSAv8sNbSKDppJ8nkfCU0P6GXOyh63JjrnT8J7yeP3evs//Qe/WtMGBsh2o+9FlHldy+E7Vb8HePIwJ+KoOvFByoug3GtZ0yHr26XX0rwmXANo4QrA8TNuk9rGyu/teNrG0IOmAgnb6V3fNjjVJ15EwCM9c9YXtbo1Dz5r2fl8etmkSC0EvKAuTOfoyxEs2UjObu2gxy/Ow6oYvCUtEfBqoWAwlEpcuKjX7S92iNtlzNNcp1jILYAjcbcqwY18kOXfzXWtnSeSdf1DNruvljQuG55Hk7HuXQ+ljjvY4s9jHXN+w6b3IP6nvNhhXL+a3iKJVOzC2PjrXte3PTYiCsEPISAA1NQUNQly6QCUf3Feo0NMRnnh0W5/nZg0qW24rBOp0Y4fM6mh8d8TtpTEfpXacqJFy2q+8ypAR981kRvq81F2aEpFr+7+dHoUom/2k0xotp9VJ9x2b7HQBJGS2AmmT3bFk6ZNh4fLIjsBWy2fqwnq/vFqsJCErkX7q38XVJxbaZGZQ9e3NVGwwne5E/i4u39zOGHVB8XpQgKc=" + # quay.io trigger URL + secure: "XDV3Wf57zoCQx8BMUxdkYFuioEwJo/WQHO4rA9tbMLgOeDdHiS2gTPnF7OdxXwYuT1jEkBODUBql/U2Xku0b5fhJQV30oUdsL5R8wXR59xSYYUFOF5yg6MfhEdkh8VgcMNQcRGrkdTSHyOZ1ITEqqMAA6w/tg3sD4zLaUx5Ad4TlaHr3xB/1DJdgRbYJp2UMPzbLrmsTC/S/bJ4lEkJiFkUAdWejWKc3ji4ReGoHiYriwtDVvSPZLNucT76c1058KC/KA6r/Mf4Gr6Dn6ixQDa5T+7GWOf8+V/5qvYogURdxcc1faFOJNDnnJp7pe0NYnZHjl0onYN9dTul1gQoyPrq1MvXBvoINXtXWE9y54OWjtybiIasZ4IYpbW9VXylWEoFd+qpweFSAKTdYPXONzNgER3v33+HoRLjYRMrVUd4xgyxGRhwZqj3ankOwana3UhhSd+9SImR7tGUzh2V+NoMZWG3wk+GAP+2ak8SInbjHIHm3ZZ4/TpAtmK/W4yGww0BqQSvxkinS1zUxGCk1ZO33ZAHmutc+hSMr/DmGHKSbQ23lJpALVp/S2r0WgQOkcEnmau1okHupuFnBkLBQqc3dk4auCOWBmu5r24Ea+q0bG/ZPGkKqU9FPlsCQCJ84sn5o8HQ31bFGSRjZUwAazk8notbt7LY1HKfBReqyRMA=" + deploy: - provider: packagecloud repository: pixiecore @@ -40,3 +44,8 @@ deploy: on: branch: master go: '1.7' +- provider: script + script: go run scripts/trigger_quay_build.go + on: + branch: master + go: '1.7' diff --git a/scripts/trigger_quay_build.go b/scripts/trigger_quay_build.go new file mode 100644 index 0000000..a807a72 --- /dev/null +++ b/scripts/trigger_quay_build.go @@ -0,0 +1,71 @@ +// Copyright 2017 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "os" +) + +type commitInfo struct { + Commit string `json:"commit"` + Ref string `json:"ref"` + Branch string `json:"default_branch"` +} + +func fatal(msg string, args ...interface{}) { + fmt.Printf(msg+"\n", args...) + os.Exit(1) +} + +func main() { + info := commitInfo{ + Commit: os.Getenv("TRAVIS_COMMIT"), + Ref: "refs/heads/master", + Branch: "master", + } + + if info.Commit == "" { + fatal("no TRAVIS_COMMIT found in environment") + } + + bs, err := json.Marshal(info) + if err != nil { + fatal("marshal commitInfo: %s", err) + } + + url := os.Getenv("QUAY_TRIGGER_URL") + if url == "" { + fatal("no QUAY_TRIGGER_URL found in environment") + } + + resp, err := http.Post(url, "application/json", bytes.NewBuffer(bs)) + if err != nil { + fatal("post to quay trigger: %s", err) + } + if resp.StatusCode != 200 { + msg, err := ioutil.ReadAll(resp.Body) + if err != nil { + fatal("reading error message from quay trigger response: %s", err) + } + fatal("non-200 status from quay trigger: %s (%q)", resp.Status, string(msg)) + } + + fmt.Printf("Triggered Quay build on commit %s\n", info.Commit) +}