Skip to content

Instantly share code, notes, and snippets.

@RaviTezu
Last active April 30, 2017 05:53
Show Gist options
  • Save RaviTezu/b8607ff3e0c3da176df89cb8b1c315ec to your computer and use it in GitHub Desktop.
Save RaviTezu/b8607ff3e0c3da176df89cb8b1c315ec to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"io/ioutil"
"strings"
"cloud.google.com/go/storage"
"github.com/golang/glog"
"google.golang.org/api/option"
)
const (
chromeBrowserBktName = "chromium-browser-continuous"
prefixLinux64 = "Linux_x64"
objLastChange = "Linux_x64/LAST_CHANGE"
chromeFilename = "chrome-linux.zip"
)
// Notes:
// chromium-browser-continuous/Linux_x64/"LAST_CHANGE" file has the latest object name.
// Read that file and then, go to that object and then, to the latest object to download the chrome file.
// https://github.com/GoogleCloudPlatform/golang-samples/tree/master/storage
// https://console.cloud.google.com/storage/browser/chromium-browser-continuous/?pli=1
// Check the checksum after downloading the file.
func main() {
ctx := context.Background()
client, err := storage.NewClient(ctx, option.WithServiceAccountFile("/home/ravitezu/creds.json"))
if err != nil {
glog.Infof("Cannot create a storage client: %s", err)
}
chromeBkt := client.Bucket(chromeBrowserBktName)
// Get the latest build version using objLAST_CHANGE object
lastChange := chromeBkt.Object(objLastChange)
rc, err := lastChange.NewReader(ctx)
if err != nil {
glog.Infof("Cannot get a reader for LAST_CHANGE: %s", err)
}
defer rc.Close()
data, err := ioutil.ReadAll(rc)
if err != nil {
glog.Infof("Cannot read from LAST_CHANGE: %s", err)
}
latestChromeBuild := string(data)
latestChromePackage := strings.Join([]string{prefixLinux64, latestChromeBuild, chromeFilename}, "/")
latestObjHandler := chromeBkt.Object(latestChromePackage)
chromeZip, err := latestObjHandler.NewReader(ctx)
if err != nil {
glog.Infof("Cannot get a reader for LAST_CHANGE: %s", err)
}
defer chromeZip.Close()
fileData, err := ioutil.ReadAll(chromeZip)
if err != nil {
glog.Infof("Cannot get a reader for LAST_CHANGE: %s", err)
}
fmt.Println("Downloading the latest chrome version ... ")
err = ioutil.WriteFile(chromeFilename, fileData, 0644)
if err != nil {
glog.Infof("Cannot write to file: %s", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment