-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): experimental go frontend CLI
- Loading branch information
Showing
26 changed files
with
951 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/mitchellh/go-homedir" | ||
version = "1.0.0" | ||
|
||
[[constraint]] | ||
name = "gopkg.in/yaml.v2" | ||
version = "2.2.1" | ||
|
||
# [[constraint]] | ||
# branch = "master" | ||
# name = "k8s.io/api" | ||
|
||
# [[constraint]] | ||
# name = "k8s.io/client-go" | ||
# branch = "release-8.0" | ||
|
||
# [[constraint]] | ||
# name = "k8s.io/apimachinery" | ||
# revision = "488889b0007f63ffee90b66a34a2deca9ec58774" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"path" | ||
"strings" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// Config type must be public for the yaml parser (for some reason). We only need the project key and the name. | ||
type Config struct { | ||
Project struct { | ||
Name *string | ||
} | ||
} | ||
|
||
func findProject(cwd string) (string, string) { | ||
projectDir := cwd | ||
|
||
for { | ||
configPath := path.Join(projectDir, "garden.yml") | ||
|
||
if _, err := os.Stat(configPath); !os.IsNotExist(err) { | ||
configYaml, err := ioutil.ReadFile(configPath) | ||
check(err) | ||
|
||
config := Config{} | ||
|
||
err = yaml.Unmarshal(configYaml, &config) | ||
if err != nil { | ||
log.Fatalf("Unable to parse %s as a valid garden configuration file", configPath) | ||
} | ||
|
||
if config.Project.Name != nil { | ||
// found project config | ||
return projectDir, *config.Project.Name | ||
} | ||
} | ||
|
||
// move up one level | ||
projectDir = path.Dir(projectDir) | ||
|
||
if projectDir == "/" { | ||
log.Fatalf("Not a project directory (or any of the parent directories): %s", cwd) | ||
} | ||
} | ||
} | ||
|
||
// Get or set the ID of this project (stored in PROJECT_ROOT/.garden/id). | ||
// TODO: might wanna use a lockfile for concurrency here | ||
func getProjectID(projectDir string) string { | ||
gardenDir := path.Join(projectDir, ".garden") | ||
ensureDir(gardenDir) | ||
|
||
idPath := path.Join(gardenDir, "id") | ||
|
||
var projectID string | ||
|
||
if _, err := os.Stat(idPath); !os.IsNotExist(err) { | ||
idData, err := ioutil.ReadFile(idPath) | ||
check(err) | ||
projectID = strings.TrimSpace(string(idData)) | ||
} else { | ||
projectID = randSeq(8) | ||
err := ioutil.WriteFile(idPath, []byte(projectID), 0644) | ||
check(err) | ||
} | ||
|
||
return projectID | ||
} | ||
|
||
func getGardenHomeDir() string { | ||
// TODO: allow override via env var | ||
homeDir := getHomeDir() | ||
gardenHome := path.Join(homeDir, ".garden") | ||
|
||
ensureDir(gardenHome) | ||
|
||
return gardenHome | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package dockerutil | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
// TODO: Use the Docker Golang SDK instead of shelling out here | ||
|
||
func Exec(args []string, silent bool) error { | ||
binary, err := exec.LookPath("docker") | ||
if err != nil { | ||
log.Fatal("Could not find docker - Garden requires docker to be installed in order to run.") | ||
} | ||
|
||
cmd := exec.Command(binary, args...) | ||
|
||
cmd.Env = os.Environ() | ||
if !silent { | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdin = os.Stdin | ||
cmd.Stdout = os.Stdout | ||
} | ||
|
||
return cmd.Run() | ||
} | ||
|
||
// TODO Use Docker SDK | ||
func HasVolume(volumeName string) bool { | ||
args := []string{"volume", "inspect", volumeName} | ||
err := Exec(args, true) | ||
if err != nil { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func MakeVolume(volumeName string) error { | ||
args := []string{"volume", "create", "--name", volumeName} | ||
return Exec(args, true) | ||
} | ||
|
||
func GetVolumeName(projectName string, projectID string) string { | ||
return "garden-volume--" + projectName + "-" + projectID | ||
} | ||
|
||
// TODO Use Docker SDK | ||
func HasContainer(containerName string) bool { | ||
args := []string{"inspect", containerName} | ||
err := Exec(args, true) | ||
if err != nil { | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { join } from "path" | ||
import { spawn } from "../support/support-util" | ||
|
||
const sources = join(__dirname, "**", "*.go") | ||
|
||
module.exports = (gulp) => { | ||
gulp.task("build", () => spawn("go", ["build", "-o", join("build", "garden")], __dirname)) | ||
gulp.task("watch", () => gulp.watch([sources, join(__dirname, "Dockerfile")], gulp.parallel("build"))) | ||
} | ||
|
||
if (process.cwd() === __dirname) { | ||
module.exports(require("gulp")) | ||
} |
Oops, something went wrong.