Skip to content

Commit

Permalink
feat(cli): experimental go frontend CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Oct 25, 2018
1 parent c11b16a commit 71c5e38
Show file tree
Hide file tree
Showing 26 changed files with 951 additions and 366 deletions.
60 changes: 52 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,60 @@
#
version: 2
jobs:
build-go:
docker:
- image: circleci/golang:1.10
working_directory: /go/src/github.com/garden-io/garden
steps:
- checkout
- restore_cache:
keys:
- pkg-cache-{{ checksum "Gopkg.lock" }}
- run:
name: Install dep
command: |
if [ ! -d /go/src/github.com/garden-io/garden/vendor ]; then
curl -L -s https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -o /go/bin/dep
chmod +x /go/bin/dep
/go/bin/dep ensure
fi
- save_cache:
key: pkg-cache-{{ checksum "Gopkg.lock" }}
paths:
- "/go/src/github.com/garden-io/garden/vendor"
- run:
name: Build All
command: |
cd garden-cli
package_name="garden"
platforms=("windows/amd64" "windows/386" "darwin/amd64" "linux/amd64")
for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi
env GOOS=$GOOS GOARCH=$GOARCH go build -o build/$output_name
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done
- store_artifacts:
path: garden-cli/build
destination: /downloads
test-node:
docker:
# specify the version you desire here
- image: circleci/node:10
steps:
- checkout
- run: sudo apt-get update && sudo apt-get install rsync
- setup_remote_docker:
docker_layer_caching: true

- run: sudo apt-get update && sudo apt-get install rsync

# Download and cache dependencies
- restore_cache:
keys:
Expand All @@ -40,17 +83,18 @@ jobs:
# build, lint and run tests
- run:
name: npm build
command: npm run build
name: ci-build
command: npm run ci-build
- run:
name: npm lint
name: npm run lint
command: npm run lint
- run:
name: npm test
command: npm test
command: npm run ci-test

workflows:
version: 2
all-tests:
jobs:
- build-go
- test-node
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
*.log
npm-debug.log*

# Node dependencies directory
# vendor dependencies
node_modules
vendor/

# IDEs
.idea
Expand All @@ -24,3 +25,4 @@ coverage/
gulpfile.js
*.map
*.tgz
build/
28 changes: 28 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Gopkg.toml
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
2 changes: 1 addition & 1 deletion bin/bootstrap-osx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# install/update homebrew dependencies
BREW_DEPS="cmake git kubectl kubernetes-helm stern rsync icu4c pkg-config faas-cli git-chglog"
BREW_DEPS="cmake git kubectl kubernetes-helm stern rsync icu4c pkg-config faas-cli dep git-chglog"

brew update
brew install ${BREW_DEPS}
Expand Down
1 change: 1 addition & 0 deletions bin/publish
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ git push origin HEAD --no-verify
# TODO: set this up to work with multiple packages
cd garden-service
npm publish
cd ..
gulp update-brew
83 changes: 83 additions & 0 deletions garden-cli/config.go
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
}
56 changes: 56 additions & 0 deletions garden-cli/dockerutil/docker.go
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
}
21 changes: 21 additions & 0 deletions garden-cli/gulpfile.ts
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"))
}
Loading

0 comments on commit 71c5e38

Please sign in to comment.