Skip to content

Commit

Permalink
add init code
Browse files Browse the repository at this point in the history
  • Loading branch information
ringtail committed Dec 24, 2017
1 parent 5d7f719 commit cab9ee6
Show file tree
Hide file tree
Showing 483 changed files with 231,531 additions and 177 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.dockerignore
Dockerfile
.git
.hg
.svn
415 changes: 247 additions & 168 deletions .idea/workspace.xml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: go
install: true
sudo: required
go:
- 1.7
- 1.8
- 1.9
- master
script:
- ./test.sh
after_success:
- bash <(curl -s https://codecov.io/bash)
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# build stage
FROM golang:1.8-alpine3.6 AS build-env
ADD . /src/github.com/ringtail/lucas
ENV GOPATH /:/src/github.com/ringtail/lucas/vendor
WORKDIR /src/github.com/ringtail/lucas
RUN go build -o app


# test stage
#FROM golang:1.8-alpine3.6
#WORKDIR /src/github.com/ringtail/lucas
#RUN go test


# release stage
FROM alpine
WORKDIR /app
EXPOSE 8080
COPY --from=build-env /src/github.com/ringtail/lucas/app /app/
CMD ["./app","run"]
52 changes: 52 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
pipeline {
environment {
REGISTRY_ENDPOINT = "https://registry.cn-hangzhou.aliyuncs.com/v2/"
IMAGE_WITH_TAG = "registry.cn-hangzhou.aliyuncs.com/ringtail/lucas:0.0.1"
REGISTRY_CERTS = "registry"
}
agent {
node {
label 'golang'
}

}
stages {
stage('Build') {
steps {
sh 'go build -o app'
}
}
stage('Test') {
steps {
sh 'go test'
}
}
stage('Code Quality') {
steps {
script {
try{
checkstyle canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: ''
}catch(e){
echo e
}
}

}
}
stage('Image Build&Publish') {
steps {
echo 'Build Images'
script {
docker.withRegistry("${REGISTRY_ENDPOINT}", "${REGISTRY_CERTS}") {
sh 'docker build -t ${IMAGE_WITH_TAG} .'
sh 'docker push ${IMAGE_WITH_TAG}'
}
}

}
}
}
triggers {
pollSCM('* * * * *')
}
}
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,27 @@
</p>

etcd v3 api browser

## Usage
```
NAME:
lucas - A etcd v3 key/value browser implemented in go
USAGE:
lucas [global options] command [command options] [arguments...]
VERSION:
0.0.1
COMMANDS:
run run lucas web server
GLOBAL OPTIONS:
--debug set debug mode to lucas
--endpoints value machine addresses in the cluster (default: "http://127.0.0.1:2379,http://127.0.0.1:4001")
--cert-file value identify HTTPS client using this SSL certificate file
--key-file value identify HTTPS client using this SSL key file
--ca-file value verify certificates of HTTPS-enabled servers using this CA bundle
--help show help
--version print the version
```
1 change: 1 addition & 0 deletions derrick_conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"platform": "Golang", "rigging_name": "GolangRigging", "config_file": "/Users/zhongweilzw/go/src/github.com/ringtail/lucas/derrick_conf"}
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "2"
services:
web:
build:
context: .
image: registry.cn-hangzhou.aliyuncs.com/ringtail/lucas:0.0.1
ports:
- 8080
restart: always
18 changes: 13 additions & 5 deletions frontend/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ const HOME_PAGE = `
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.min.css"/>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="http://localhost:8081/static/index.js"></script>
<link type="text/css" href="http://localhost:8081/static/index.css"/>
<title>Document</title>
<script src="http://ringtail-lucas.oss-cn-beijing.aliyuncs.com/index.js"></script>
<link rel="stylesheet" href="http://ringtail-lucas.oss-cn-beijing.aliyuncs.com/index.css"/>
<title>Lucas</title>
</head>
<body ng-app="app">
<div ng-controller="lucas">
<tree-view nodes="nodes.Nodes"></tree-view>
<div ng-controller="lucas" class="row main-container">
<div class="col-md-12 container-title">Lucas - etcd v3 key value browser</div>
<div class="col-md-8">
<tree-view nodes="nodes.Nodes"></tree-view>
</div>
<div class="col-md-4 form" style="min-height:500px" ng-if="json">
<textarea class="data-viewer form-control" ng-model="json.value"></textarea>
<button update-item kv="json" class="btn btn-primary pull-right" style="margin-right:5%;margin-top:8px;">更改</button>
<div>
</div>
</body>
</html>
Expand Down
40 changes: 40 additions & 0 deletions frontend/static/index.css
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
.main-container {
padding:16px;
}
.container-title {
margin:0 auto;
text-align: center;
font-size: 24px;
}
.item-key {
display: inline-block;
border: 1px solid #ccc;
padding: 5px 10px;
text-decoration: none;
color: #666;
font-family: arial, verdana, tahoma;
font-size: 11px;
border-radius: 5px;
pointer: cursor;
}

.item-key.has-key {
background-color: green;
color: white;
}

.item-key:hover {
background-color: #428bca;
text-decoration: none;
}

.item-value {
display: inline-block;
}

.data-viewer {
border: 1px solid #cccccc;
border-radius: 5px;
min-height: 500px;
overflow: auto;
width:95%;
}
68 changes: 64 additions & 4 deletions frontend/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ app.controller('lucas', ['$scope', '$http', function ($scope, $http) {
url: "/store"
}).success(function (data) {
$scope.nodes = data;
})
});

$scope.update = function (newValue) {
console.log(newValue);
}
}]);

app.directive("treeView", ["$compile", function ($compile) {
Expand All @@ -18,9 +22,9 @@ app.directive("treeView", ["$compile", function ($compile) {
}
};
element.append("<div ng-repeat='item in nodes'>" +
"{{ item.RootPath}}" +
"<span ng-if='item.KV != undefine'>: {{item.KV.value}}</span>" +
"<div ng-if='hasNodes(item.Nodes)' style='margin-left:6px'><tree-view nodes='item.Nodes'></tree-view></div>" +
"<p class='item-key' ng-click='hide=!hide' ng-class=\"{true: 'has-key', false: 'not-has-key'}[item.KV!=undefined]\">{{ item.RootPath}}</p>" +
"<p ng-if='item.KV != undefined' class='item-value'><button item-detail class='btn btn-primary btn-xs' kv='item.KV'>view</button></p>" +
"<div ng-show='hide==false' ng-if='hasNodes(item.Nodes)' style='margin-left:16px'><tree-view nodes='item.Nodes'></tree-view></div>" +
"</div>"
);
$compile(element.contents())(scope);
Expand All @@ -34,3 +38,59 @@ app.directive("treeView", ["$compile", function ($compile) {
link: link
};
}]);


app.directive("itemDetail", ['$rootScope', function ($rootScope) {
function link(scope, element, attrs) {
element.on("click", function () {
$rootScope.json = scope.kv;
$rootScope.$apply()
})
}

return {
restrict: 'AE',
scope: {
"kv": "="
},
link: link
}
}]);

app.directive("updateItem", ['$http', function ($http) {
function link(scope, element, attrs) {
element.on("click", function () {
console.log(scope.kv);
$http(
{
method: "POST",
url: "/store",
data: {
"key": scope.kv.key,
"value": scope.kv.value
},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
}
).success(function () {
alert("change value successfully")
}).error(function () {
alert("change value failed")
})

})
}

return {
restrict: 'AE',
scope: {
"kv": "="
},
link: link
}
}]);
39 changes: 39 additions & 0 deletions kubernetes-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: v1
kind: Service
metadata:
annotations:
derrick.service.type: nodeport
derrick.version: 0.0.14
labels:
derrick.service: lucas
name: lucas
spec:
ports:
- name: "8080"
port: 8080
targetPort: 8080
selector:
derrick.service: lucas
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
derrick.version: 0.0.14
labels:
derrick.service: lucas
name: lucas
spec:
replicas: 1
template:
metadata:
labels:
derrick.service: lucas
spec:
containers:
- image: registry.cn-hangzhou.aliyuncs.com/ringtail/lucas:0.0.1
name: web
ports:
- containerPort: 8080
10 changes: 10 additions & 0 deletions lucas.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ringtail/lucas/backend/types"
"flag"
"fmt"
"os"
)

const COMMAND_DESC = `
Expand Down Expand Up @@ -75,6 +76,15 @@ func main() {
fmt.Println(VERSION)
return
}
if os.Getenv("CA_FILE") != "" || os.Getenv("KEY_FILE") != "" || os.Getenv("CERT_FILE") != "" {
ca_file = os.Getenv("CA_FILE")
key_file = os.Getenv("KEY_FILE")
cert_file = os.Getenv("CERT_FILE")
}

if os.Getenv("ENDPOINTS") != "" {
endpoints = os.Getenv("ENDPOINTS")
}

args := flag.Args()
if args != nil && len(args) != 0 && args[0] == "run" {
Expand Down
12 changes: 12 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -e
echo "" > coverage.txt

for d in $(go list ./... | grep -v vendor); do
go test -race -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done
Loading

0 comments on commit cab9ee6

Please sign in to comment.