Skip to content

Commit

Permalink
switch to go embed
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Jun 26, 2022
1 parent da7cdb6 commit bfbdaff
Show file tree
Hide file tree
Showing 51 changed files with 15,285 additions and 9,456 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml → .github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: API

on:
push:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ReleasePkg
name: Release Package

on:
push:
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: UI

on:
push:
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
node-version: [15.x, 18.x]

steps:
- uses: actions/checkout@v2

- name: Cache node modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Node ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install vuejs cli
run: npm install -g @vue/cli@5.0.4

- name: Run build ui
run: make build_ui
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# dist dir
dist

!web/dist

sync

*.db
52 changes: 24 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
GO ?= go
GOFMT ?= $(GO)fmt
NPM ?= npm
NPX ?= npx
RHINO ?= rhino
go ?= go
gofmt ?= $(go)fmt
npm ?= npm
npx ?= npx
pkgs = ./...
PKGER ?= pkger


help: Makefile
Expand All @@ -19,17 +17,17 @@ help: Makefile
.PHONY: install_revive
install_revive:
@echo ">> ============= Install Revive ============= <<"
$(GO) get github.com/mgechev/revive
$(go) get github.com/mgechev/revive


## style: Check code style.
.PHONY: style
style:
@echo ">> ============= Checking Code Style ============= <<"
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
@fmtRes=$$($(gofmt) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
if [ -n "$${fmtRes}" ]; then \
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
echo "Please ensure you are using $$($(go) version) for formatting code."; \
exit 1; \
fi

Expand All @@ -51,24 +49,24 @@ check_license:
.PHONY: test_short
test_short:
@echo ">> ============= Running Short Tests ============= <<"
$(GO) clean -testcache
$(GO) test -mod=readonly -short $(pkgs)
$(go) clean -testcache
$(go) test -mod=readonly -short $(pkgs)


## test: Run test cases.
.PHONY: test
test:
@echo ">> ============= Running All Tests ============= <<"
$(GO) clean -testcache
$(GO) test -mod=readonly -run=Unit -bench=. -benchmem -v -cover $(pkgs)
$(go) clean -testcache
$(go) test -mod=readonly -run=Unit -bench=. -benchmem -v -cover $(pkgs)


## integration: Run integration test cases (Requires etcd)
.PHONY: integration
integration:
@echo ">> ============= Running All Tests ============= <<"
$(GO) clean -testcache
$(GO) test -mod=readonly -run=Integration -bench=. -benchmem -v -cover $(pkgs)
$(go) clean -testcache
$(go) test -mod=readonly -run=Integration -bench=. -benchmem -v -cover $(pkgs)


## lint: Lint the code.
Expand All @@ -82,60 +80,60 @@ lint:
.PHONY: verify
verify:
@echo ">> ============= List Dependencies ============= <<"
$(GO) list -m all
$(go) list -m all
@echo ">> ============= Verify Dependencies ============= <<"
$(GO) mod verify
$(go) mod verify


## format: Format the code.
.PHONY: format
format:
@echo ">> ============= Formatting Code ============= <<"
$(GO) fmt $(pkgs)
$(go) fmt $(pkgs)


## vet: Examines source code and reports suspicious constructs.
.PHONY: vet
vet:
@echo ">> ============= Vetting Code ============= <<"
$(GO) vet $(pkgs)
$(go) vet $(pkgs)


## coverage: Create HTML coverage report
.PHONY: coverage
coverage:
@echo ">> ============= Coverage ============= <<"
rm -f coverage.html cover.out
$(GO) test -mod=readonly -coverprofile=cover.out $(pkgs)
$(go) test -mod=readonly -coverprofile=cover.out $(pkgs)
go tool cover -html=cover.out -o coverage.html


## serve_ui: Serve admin dashboard
.PHONY: serve_ui
serve_ui:
@echo ">> ============= Run Vuejs App ============= <<"
cd web;$(NPM) run serve
cd web;$(npm) run serve


## build_ui: Builds admin dashboard for production
.PHONY: build_ui
build_ui:
@echo ">> ============= Build Vuejs App ============= <<"
cd web;$(NPM) run build
cd web;$(npm) install;$(npm) run build


## check_ui_format: Check dashboard code format
.PHONY: check_ui_format
check_ui_format:
@echo ">> ============= Validate js format ============= <<"
cd web;$(NPX) prettier --check .
cd web;$(npx) prettier --check .


## format_ui: Format dashboard code
.PHONY: format_ui
format_ui:
@echo ">> ============= Format js Code ============= <<"
cd web;$(NPX) prettier --write .
cd web;$(npx) prettier --write .


## package: Package assets
Expand All @@ -144,16 +142,14 @@ package:
@echo ">> ============= Package Assets ============= <<"
-rm $(shell pwd)/web/.env
echo "VUE_APP_API_URL=" > $(shell pwd)/web/.env.dist
cd web;$(NPM) run build
$(PKGER) list -include $(shell pwd)/web/dist
$(PKGER) -o cmd
cd web;$(npm) run build


## run: Run the API Server
.PHONY: run
run:
@echo ">> ============= Run Tower ============= <<"
$(GO) run peanut.go api -c config.dist.yml
$(go) run peanut.go api -c config.dist.yml


## ci: Run all CI tests.
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<p align="center">
<img src="https://raw.githubusercontent.com/Clivern/Peanut/main/assets/logo.png?v=0.4.3" width="240" />
<img src="/static/logo.png?v=0.5.0" width="240" />
<h3 align="center">Peanut</h3>
<p align="center">Deploy Databases and Services Easily for Development and Testing Pipelines.</p>
<p align="center">
<a href="https://github.com/Clivern/Peanut/actions/workflows/build.yml">
<img src="https://github.com/Clivern/Peanut/actions/workflows/build.yml/badge.svg">
<a href="https://github.com/Clivern/Peanut/actions/workflows/api.yml">
<img src="https://github.com/Clivern/Peanut/actions/workflows/api.yml/badge.svg">
</a>
<a href="https://github.com/Clivern/Peanut/actions/workflows/ui.yml">
<img src="https://github.com/Clivern/Peanut/actions/workflows/ui.yml/badge.svg">
</a>
<a href="https://github.com/Clivern/Peanut/actions">
<img src="https://github.com/Clivern/Peanut/workflows/Release/badge.svg">
</a>
<a href="https://github.com/Clivern/Peanut/releases">
<img src="https://img.shields.io/badge/Version-0.4.3-red.svg">
<img src="https://img.shields.io/badge/Version-0.5.0-red.svg">
</a>
<a href="https://goreportcard.com/report/github.com/Clivern/Peanut">
<img src="https://goreportcard.com/badge/github.com/Clivern/Peanut?v=0.4.3">
<img src="https://goreportcard.com/badge/github.com/Clivern/Peanut?v=0.5.0">
</a>
<a href="https://godoc.org/github.com/clivern/peanut">
<img src="https://godoc.org/github.com/clivern/peanut?status.svg">
Expand All @@ -25,15 +28,15 @@
</p>
<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/Clivern/Peanut/main/assets/chart.png?v=0.4.3" width="80%" />
<img src="/static/chart.png?v=0.5.0" width="80%" />
</p>
<p align="center">
<h4 align="center">Dashboard Screenshots</h4>
<p align="center">
<img src="https://raw.githubusercontent.com/Clivern/Peanut/main/assets/screenshot_01.png?v=0.4.3" width="90%" />
<img src="https://raw.githubusercontent.com/Clivern/Peanut/main/assets/screenshot_02.png?v=0.4.3" width="90%" />
<img src="https://raw.githubusercontent.com/Clivern/Peanut/main/assets/screenshot_03.png?v=0.4.3" width="90%" />
<img src="https://raw.githubusercontent.com/Clivern/Peanut/main/assets/screenshot_04.png?v=0.4.3" width="90%" />
<img src="/static/screenshot_01.png?v=0.5.0" width="90%" />
<img src="/static/screenshot_02.png?v=0.5.0" width="90%" />
<img src="/static/screenshot_03.png?v=0.5.0" width="90%" />
<img src="/static/screenshot_04.png?v=0.5.0" width="90%" />
</p>
</p>

Expand Down Expand Up @@ -310,12 +313,11 @@ $ make serve_ui
# Build Vuejs app
$ make build_ui
# Any changes to the dashboard, must be reflected to cmd/pkged.go
# You can use these commands to do so
$ go get github.com/markbates/pkger/cmd/pkger
# Build the Vuejs app
$ make package
```


#### The command line tool

In order to interact with peanut API server, you can either do basic API calls or use the provided command line tool. It is still not finished yet but it will be ready soon.
Expand Down
18 changes: 14 additions & 4 deletions cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"io"
"io/fs"
"io/ioutil"
"net/http"
"os"
Expand All @@ -21,7 +22,6 @@ import (

"github.com/drone/envsubst"
"github.com/gin-gonic/gin"
"github.com/markbates/pkger"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -149,7 +149,6 @@ var towerCmd = &cobra.Command{
c.String(http.StatusNoContent, "")
})

r.GET("/", controller.Home)
r.GET("/_health", controller.Health)
r.GET("/_ready", controller.Ready)

Expand All @@ -158,8 +157,6 @@ var towerCmd = &cobra.Command{
gin.WrapH(controller.Metrics()),
)

r.NoRoute(gin.WrapH(http.FileServer(pkger.Dir("/web/dist"))))

apiv1 := r.Group("/api/v1")
{
apiv1.POST("/service", func(c *gin.Context) {
Expand All @@ -186,6 +183,19 @@ var towerCmd = &cobra.Command{
apiv1.GET("/tag/:serviceType/:fromCache", controller.GetTags)
}

dist, err := fs.Sub(Static, "web/dist")

if err != nil {
panic(fmt.Sprintf(
"Error while accessing dist files: %s",
err.Error(),
))
}

staticServer := http.StripPrefix("/", http.FileServer(http.FS(dist)))

r.NoRoute(gin.WrapH(staticServer))

go workers.Watch()
go workers.Finalize(workers.HandleWorkload())

Expand Down
12 changes: 0 additions & 12 deletions cmd/pkged.go

This file was deleted.

3 changes: 3 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package cmd

import (
"embed"
"fmt"

"github.com/spf13/cobra"
Expand All @@ -21,6 +22,8 @@ var (
BuiltBy = "unknown"
)

var Static embed.FS

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Expand Down
28 changes: 0 additions & 28 deletions core/controller/home.go

This file was deleted.

2 changes: 1 addition & 1 deletion core/driver/db_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package driver

import (
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
)

// Database interface
Expand Down
2 changes: 1 addition & 1 deletion core/driver/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/clivern/peanut/core/util"

"github.com/spf13/viper"
"go.etcd.io/etcd/clientv3"
"go.etcd.io/etcd/client/v3"
)

// Etcd driver
Expand Down
Loading

0 comments on commit bfbdaff

Please sign in to comment.