Skip to content

Commit

Permalink
git secrets integration and code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishThakur committed Aug 17, 2020
1 parent 741dac1 commit d5deeec
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 36 deletions.
51 changes: 23 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,29 @@ Several options to install:
- Via released binaries:
- [releases](https://github.com/srijanone/vega/releases)

---

## Requirements

- git
- [tilt](https://docs.tilt.dev/install.html)
- [Docker](https://docs.docker.com/install/)
- [docker-compose](https://docs.docker.com/compose/install/)

---

## Getting Started

- `vega`: Vega usage

![vega usage](.screenshots/vega_usage.png)
- `vega`: vega usage

- `vega init`: Initializes vega

![vega init](.screenshots/vega_init.png)

- `vega starterkit list`: List all available starterkits

![vega starterkit list](.screenshots/vega_starterkit_list.png)

- `vega create awesome-app --starterkit nodejs+redis`

![vega create](.screenshots/vega_create.png)

- `vega up`
- `vega create my-drupal-app --starterkit drupal8-php-fpm-apache`: Bootload a new app using starterkit

![vega down](.screenshots/vega_up.png)
- `vega up`: Get your docker containers up & running.

- `vega down`
- `vega down`: Stop all docker containers.

![vega down](.screenshots/vega_down.png)

---
The above commands are mostly used commands, please refer commands table for further details.

## Commands

Expand All @@ -64,7 +50,7 @@ Several options to install:
| `vega version` | Prints out version | | Vega 1.0.0 |
| `vega home` | Prints out home vega home | | |
| `vega init` | Initializes vega | | |
| `vega starterkit list` | List all available starterkits | | drupal8<br>nodejs |
| `vega starterkit list` | List all available starterkits | | drupal9-php-fpm-apache<br>react |
| `vega create [path] --starterkit <name>` | Creates the starter kit at provided directory | \--starterkit <name><br>\--repo <repo> | |
| `vega install [path]` | Install a starterkit to existing project | \--repo <repo> | |
| `vega repo add <repo-name> <url>` | Add another starterkit repo, Can choose local folder as well | | |
Expand All @@ -80,8 +66,6 @@ Several options to install:
1. `vega repo add globe git@github.com:vs4vijay/vega-starterkits.git`
2. `vega repo add new /Users/viz/SrijanX/custom`

---

## Development

- Run Vega: `go run main.go`
Expand All @@ -91,15 +75,26 @@ Several options to install:
- `make release-dry-run` # to test and verify on local machine
- `make release-using-gorelease`

---

## Secrets
vega has been integrated with [git-secrets](https://github.com/awslabs/git-secrets) which adds following hooks to your repositories when ```vega hooks install``` is executed.

1. ```pre-commit```: Used to check if any of the files changed in the commit
use prohibited patterns.
2. ```commit-msg```: Used to determine if a commit message contains a
prohibited patterns.
3. ```prepare-commit-msg```: Used to determine if a merge commit will
introduce a history that contains a prohibited pattern at any point.
Please note that this hook is only invoked for non fast-forward merges.

```vega hooks install``` overrides any current git hooks if you have added any. In case you would like to have multiple
hooks please refer: https://gist.github.com/carlos-jenkins/89da9dcf9e0d528ac978311938aade43

## Credits

- Srijan Team (https://srijan.net)
- Inspiration from Draft (https://draft.sh)
- Utilized Tilt (https://tilt.dev) for running the application

---
- Tilt (https://tilt.dev) is used for running the applications
- git-secrets

## LICENSE

Expand Down
7 changes: 4 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cmd
import (
"errors"
"fmt"
"github.com/srijanone/vega/pkg/git_secrets"
"io"

"github.com/srijanone/vega/pkg/git_secrets"

"github.com/spf13/cobra"

common "github.com/srijanone/vega/pkg/common"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (iCmd *initCmd) setupVegaHome() error {
directories := []string{
iCmd.home.String(),
iCmd.home.StarterKits(),
iCmd.home.GitHooks(),
// iCmd.home.GitHooks(),
iCmd.home.Logs(),
}

Expand All @@ -95,7 +96,7 @@ func (iCmd *initCmd) setupVegaHome() error {
return nil
}

func (iCmd *initCmd) setupGitSecrets() error {
func (iCmd *initCmd) setupGitSecrets() error {
git_secrets.Configure(iCmd.out)
return nil
}
1 change: 0 additions & 1 deletion pkg/core/git_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ func (gitHook *GitHooks) Install(path string) {
args := []string{"secrets", "--install", "-f"}
git.Execute(gitHook.Out, args...)
}

7 changes: 4 additions & 3 deletions pkg/git_secrets/git_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package git_secrets
import (
"errors"
"fmt"
"github.com/srijanone/vega/pkg/common"
"github.com/srijanone/vega/pkg/git"
"io"
"os"
"os/exec"
"path/filepath"

"github.com/srijanone/vega/pkg/common"
"github.com/srijanone/vega/pkg/git"
)

const (
Expand All @@ -17,7 +18,7 @@ const (
git-secrets is not installed, which is required to run the application.
`
InstallInstructions = `
Install using: curl -fsSL https://raw.githubusercontent.com/srijanone/vega/develop/scripts/install.sh| bash
Install using: curl -fsSL https://raw.githubusercontent.com/srijanone/vega/develop/scripts/install_git_secrets.sh| bash
`
)

Expand Down
2 changes: 1 addition & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function shell_rc() {
}

function next_step_message() {
local name="Vega"
local name="vega"
echo -e "${yellow}${name} is installed to \$HOME/.local/bin, Please add following line to your $(shell_rc) file and reload it using: ${bold}source $(shell_rc) ${reset}"
echo ""
echo -e "${bold}export PATH=\"\$PATH:\$HOME/.local/bin\"${reset}"
Expand Down
74 changes: 74 additions & 0 deletions scripts/install_git_secrets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
# Vega Installer Script
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/srijanone/vega/develop/scripts/install-git-secrets.sh | bash

VERSION="1.0.4"

red="\033[31m"
green="\033[32m"
yellow="\033[33m"
blue="\033[34m"
bold="\033[1m"
reset="\033[0m"

show_next_step_message="NO"

function shell() {
# ps -p $$ | tail -1 | awk '{print $NF}'
echo "${SHELL##*/}"
}

function shell_rc() {
local shell_name=$(shell)
echo ".${shell_name/-/}rc"
}

function next_step_message() {
local name="git-secrets"
echo -e "${yellow}${name} is installed to \$HOME/.local/bin, Please add following line to your $(shell_rc) file and reload it using: ${bold}source $(shell_rc) ${reset}"
echo ""
echo -e "${bold}export PATH=\"\$PATH:\$HOME/.local/bin\"${reset}"
echo ""
}

function copy_binary() {
name="$1"
if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then
mv "${name}" "$HOME/.local/bin/${name}"
else
show_next_step_message="YES"
mkdir -p "$HOME/.local/bin"
mv "${name}" "$HOME/.local/bin/${name}"
fi
}

function install_git_secrets() {
if [[ "$OSTYPE" == "linux-gnu" ]] || [[ "$OSTYPE" == "darwin"* ]]; then
curl -sSL -o git-secrets -D - -L -s 'https://raw.githubusercontent.com/awslabs/git-secrets/master/git-secrets'
chmod +x git-secrets
copy_binary "git-secrets"
else
echo -e "${red}git-secrets installer is not supported for your platform: ${OS} ${reset}"
echo -e "${red}Please file an issue at https://github.com/awslabs/git-secrets/issues/new ${reset}"
exit 1
fi
}

function install() {
GIT_SECRETS_PATH=$(command -v git-secrets 2>&1 || true)

if [[ -z $GIT_SECRETS_PATH ]]; then
echo -e "${green}Installing git-secrets${reset}"
install_git_secrets
else
echo -e "${green}git-secrets already installed, Please run 'git-secrets for details${reset}"
fi

if [[ "${show_next_step_message}" == "YES" ]]; then
next_step_message
fi
}

install

0 comments on commit d5deeec

Please sign in to comment.