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
edvald committed Oct 12, 2018
1 parent b0b5599 commit 5b78a77
Show file tree
Hide file tree
Showing 22 changed files with 1,045 additions and 773 deletions.
46 changes: 32 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,63 @@ version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:10
environment:
GOPATH: /home/circleci/go

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4

working_directory: ~/repo
working_directory: ~/go/src/github.com/garden-io/garden

steps:
- checkout

- setup_remote_docker:
docker_layer_caching: true

- run: export

- run:
name: Install apt dependencies
command: sudo apt install rsync cmake libicu-dev pkg-config
command: |
sudo add-apt-repository ppa:gophers/archive
sudo apt-get update
sudo apt install rsync cmake libicu-dev pkg-config golang-1.11-go
- run:
name: Install kubectl
command: |
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- run:
name: Install dep
command: |
mkdir -p $GOPATH/bin
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
# Download and cache dependencies
- restore_cache:
keys:
- v3-dependencies-{{ checksum "package-lock.json" }}
- v0-npm-deps-{{ checksum "package-lock.json" }}
- restore_cache:
keys:
- v0-garden-service-deps-{{ checksum "garden-service/package-lock.json" }}
- restore_cache:
keys:
- v0-go-deps-{{ checksum "Gopkg.lock" }}

# install using package-lock only
# install dependencies
- run: npm ci
- run: node_modules/.bin/lerna bootstrap --ci
- run: $GOPATH/bin/dep ensure

- save_cache:
paths:
- node_modules
- garden-service/node_modules
key: v3-dependencies-{{ checksum "package-lock.json" }}
paths: [node_modules]
key: v0-npm-deps-{{ checksum "package-lock.json" }}
- save_cache:
paths: [garden-service/node_modules]
key: v0-garden-service-deps-{{ checksum "garden-service/package-lock.json" }}
- save_cache:
paths: [vendor]
key: v0-go-deps-{{ checksum "Gopkg.lock" }}

# a couple of special cases needed just for local builds
- run: |
Expand Down
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
81 changes: 81 additions & 0 deletions garden-cli/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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)
}

return projectID
}

func getGardenHomeDir() string {
// TODO: allow override via env var
homeDir := getHomeDir()
gardenHome := path.Join(homeDir, ".garden")

ensureDir(gardenHome)

return gardenHome
}
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. <info@garden.io>
*
* 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], gulp.parallel("build")))
}

if (process.cwd() === __dirname) {
module.exports(require("gulp"))
}
Loading

0 comments on commit 5b78a77

Please sign in to comment.