Skip to content

Instantly share code, notes, and snippets.

@metcalfc
Last active November 6, 2015 20:44
Show Gist options
  • Save metcalfc/62c785b6c2ae5061b535 to your computer and use it in GitHub Desktop.
Save metcalfc/62c785b6c2ae5061b535 to your computer and use it in GitHub Desktop.
Quick go utility to get the latest Docker Compose release from Github
/*
Copyright 2015 Chad Metcalf <metcalfc@gmail.com>
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 (
"fmt"
"io/ioutil"
"github.com/google/go-github/github"
)
func main() {
client := github.NewClient(nil)
fmt.Println("Getting most recent docker-compose")
release, resp, err := client.Repositories.GetLatestRelease("docker", "compose")
if err != nil {
fmt.Printf("Repositories.GetLatestRelease returned error: %v\n%v\n", err, resp.Body)
}
opt := &github.ListOptions{}
assets, resp, err := client.Repositories.ListReleaseAssets("docker", "compose", *release.ID, opt)
for _, asset := range assets {
if *asset.Name == "docker-compose-Darwin-x86_64" {
reader, err := client.Repositories.DownloadReleaseAsset("docker", "compose", *asset.ID)
if err != nil {
fmt.Printf("Repositories.DownloadReleaseAsset returned error: %v\n", err)
}
content, err := ioutil.ReadAll(reader)
if err != nil {
fmt.Printf("Repositories.DownloadReleaseAsset returned bad reader: %v\n", err)
}
err = ioutil.WriteFile("./docker-compose", content, 0755)
if err != nil {
fmt.Printf("Couldn't write file: %v\n", err)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment