Skip to content

Commit f5175b8

Browse files
authored
Merge pull request #2 from crowdcompute/develop
Develop
2 parents 55b2c27 + 2353bcd commit f5175b8

90 files changed

Lines changed: 8752 additions & 377 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,34 @@ NODENAME := p2p-node
33
BINARY_NAME = gocc
44
VERSION := $(shell cat ./VERSION)
55

6-
build:
7-
go build -ldflags "-X main.Version=$(VERSION)" -o "./build/bin/$(BINARY_NAME)" "./cmd/gocc/main.go"
8-
9-
execute:
10-
./build/bin/${BINARY_NAME}
11-
126
run: build execute
137

148
test:
159
go test ./... -v
1610

17-
provision_script:
18-
./build/deploy/provisioner.sh $(NODENAME) $(DIR)/build/bin/$(BINARY_NAME)
11+
build:
12+
go build -ldflags "-X main.Version=$(VERSION)" -o "./build/bin/$(BINARY_NAME)" "./cmd/gocc/"
13+
cp "./cmd/gocc/config/config.development.toml" "./build/bin/"
1914

2015
deploy: build provision_script
2116

22-
image:
23-
#docker build -t {name} .
17+
execute:
18+
./build/bin/${BINARY_NAME}
19+
20+
run-logserver:
21+
sudo sysctl -w vm.max_map_count=262144
22+
docker run -p 5601:5601 -p 9200:9200 -p 5044:5044 --name gocc-logstack -d gocc-logstack
23+
echo "Open: http://localhost:5601"
24+
25+
stop-logserver:
26+
docker container stop gocc-logstack
27+
docker container rm -f gocc-logstack
28+
29+
build-logserver:
30+
docker build --tag gocc-logstack ./build/gocc-logstack/
31+
32+
provision_script:
33+
./build/deploy/provisioner.sh $(NODENAME)1 $(DIR)/build/bin/$(BINARY_NAME)
34+
./build/deploy/provisioner.sh $(NODENAME)2 $(DIR)/build/bin/$(BINARY_NAME)
2435

2536
.PHONY: test build run provision_script deploy

build/deploy/provisioner.sh

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set -e
44
# Variables
55
VMNAME=$1
66
ARTIFACT=$2
7+
IFACE=$(route | grep '^default' | grep -o '[^ ]*$')
8+
HOSTIP=$(ifconfig ${IFACE} | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
79

810
# colors and helpers
911
bold() { echo -e "\e[1m$@\e[0m" ; }
@@ -13,8 +15,7 @@ yellow() { echo -e "\e[33m$@\e[0m" ; }
1315
die() { red "ERR: $@" >&2 ; exit 2 ; }
1416
ok() { green "${@:-OK}" ; }
1517

16-
function set_defaults ()
17-
{
18+
set_defaults() {
1819
AUTOSTART=false # Automatically start VM at boot time
1920
CPUS=1 # Number of virtual CPUs
2021
FEATURE=host # Use host cpu features to the guest
@@ -43,6 +44,11 @@ function set_defaults ()
4344
OPTIND=1
4445
}
4546

47+
clean_vms() {
48+
(virsh destroy ${VMNAME} > /dev/null 2>&1 || true )
49+
(virsh undefine ${VMNAME} > /dev/null 2>&1 || true )
50+
(rm -rf ${VMDIR}/${VMNAME} > /dev/null 2>&1 || true )
51+
}
4652

4753
provision_vm() {
4854
check_vmname_set
@@ -85,7 +91,8 @@ provision_vm() {
8591
# copy image to the destination directory
8692
DISK=${VMNAME}.qcow2
8793
cp $IMAGE "${VMDIR}/${VMNAME}/${DISK}" && ok
88-
94+
95+
sudo qemu-img resize "${VMDIR}/${VMNAME}/${DISK}" 10G && ok
8996

9097
import_vm
9198

@@ -122,7 +129,8 @@ provision_vm() {
122129
IP="<IP address>"
123130
fi
124131

125-
green "SSH to ${VMNAME}: 'ssh ubuntu@${IP}' or 'ssh ubuntu@${VMNAME}'"
132+
133+
green "SSH to ${VMNAME}: 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@${IP}'"
126134

127135
# Remove the unnecessary cloud init files
128136
green "Cleaning up cloud-init files"
@@ -152,15 +160,13 @@ check_vmname_set() {
152160
[ -n "${VMNAME}" ] || die "VMNAME not set."
153161
}
154162

155-
function domain_exists ()
156-
{
163+
domain_exists() {
157164
virsh dominfo "${1}" > /dev/null 2>&1 \
158165
&& DOMAIN_EXISTS=1 \
159166
|| DOMAIN_EXISTS=0
160167
}
161168

162-
function storpool_exists ()
163-
{
169+
storpool_exists() {
164170
virsh pool-info "${1}" > /dev/null 2>&1 \
165171
&& STORPOOL_EXISTS=1 \
166172
|| STORPOOL_EXISTS=0
@@ -213,10 +219,16 @@ timezone: ${TIMEZONE}
213219
214220
# Remove cloud-init when finished with it
215221
runcmd:
222+
- mkdir -p /home/ubuntu/uploads
223+
- sudo chmod 777 /home/ubuntu/uploads
224+
- rm -r /home/ubuntu/go1.11.4.linux-amd64.tar.gz
216225
- sudo usermod -a -G docker ubuntu
217226
- sudo touch /etc/cloud/cloud-init.disabled
218227
- sudo systemctl stop networking && systemctl start networking
219228
- sudo systemctl disable cloud-init.service
229+
- export HOSTIP=${HOSTIP}
230+
- echo "export HOSTIP=${HOSTIP}" >> /home/ubuntu/.profile
231+
- cd /home/ubuntu/ && ./gocc
220232
_EOF_
221233

222234
if [ ! -z "${SCRIPTNAME+x}" ]
@@ -259,6 +271,7 @@ _EOF_
259271
kvm_group="$(ls -l /dev/kvm | awk '{ print $4 }')"
260272
if groups $username | grep &>/dev/null "\b$kvm_group\b"; then
261273
green "[OK] Permissions are correct"
274+
clean_vms
262275
set_defaults
263276
provision_vm
264277

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
input {
2+
tcp {
3+
port => 5044
4+
codec => json
5+
}
6+
}

build/gocc-logstack/30-output.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
output {
2+
elasticsearch {
3+
hosts => ["localhost"]
4+
#manage_template => false
5+
#index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
6+
#document_type => "%{[@metadata][type]}"
7+
}
8+
}

build/gocc-logstack/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM sebp/elk
2+
3+
ADD 02-beats-input.conf /etc/logstash/conf.d/02-beats-input.conf
4+
ADD 30-output.conf /etc/logstash/conf.d/30-output.conf
5+
ADD elasticsearch.yml /etc/elasticsearch/elasticsearch.yml
6+
ADD elasticsearch.yml /opt/elasticsearch/config/elasticsearch.yml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
path.repo: /var/backups
2+
network.host: 0.0.0.0
3+
http.cors.enabled: true
4+
http.cors.allow-origin: "*"
5+
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
6+
http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type, Content-Length

cmd/gocc/commands/account.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Manage accounts, create update and import new stuff`,
2020
Usage: "add a new account",
2121
Action: func(c *cli.Context) error {
2222
fmt.Println("new account...")
23+
fmt.Println(c.GlobalFlagNames())
2324
return nil
2425
},
2526
},

cmd/gocc/commands/init.go

Lines changed: 0 additions & 108 deletions
This file was deleted.

cmd/gocc/commands/run.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// // Copyright 2018 The crowdcompute:crowdengine Authors
2+
// // This file is part of the crowdcompute:crowdengine library.
3+
// //
4+
// // The crowdcompute:crowdengine library is free software: you can redistribute it and/or modify
5+
// // it under the terms of the GNU Lesser General Public License as published by
6+
// // the Free Software Foundation, either version 3 of the License, or
7+
// // (at your option) any later version.
8+
// //
9+
// // The crowdcompute:crowdengine library is distributed in the hope that it will be useful,
10+
// // but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// // GNU Lesser General Public License for more details.
13+
// //
14+
// // You should have received a copy of the GNU Lesser General Public License
15+
// // along with the crowdcompute:crowdengine library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package commands
18+
19+
// import (
20+
// "bufio"
21+
// "fmt"
22+
// "os"
23+
24+
// "github.com/crowdcompute/crowdengine/common"
25+
// "github.com/urfave/cli"
26+
// )
27+
28+
// var (
29+
// // P2pPortFlag p2p port
30+
// P2pPortFlag = cli.IntFlag{
31+
// Name: "port, p",
32+
// Usage: "The p2p port the node will listen to.",
33+
// Value: 12000,
34+
// }
35+
36+
// // IPFlag listen
37+
// IPFlag = cli.StringFlag{
38+
// Name: "ip",
39+
// Usage: "Setting the IP address",
40+
// Value: "127.0.0.0",
41+
// }
42+
// // RPCFlag settings
43+
// RPCFlag = cli.BoolFlag{
44+
// Name: "rpc",
45+
// Usage: "Setting this flag will make this node listet to JSON-RPC calls",
46+
// }
47+
// )
48+
49+
// var (
50+
// // RunCommand runs a node
51+
// RunCommand = cli.Command{
52+
// Action: runNode,
53+
// Name: "run",
54+
// Usage: "Run a Crowd Compute node",
55+
// ArgsUsage: "<bootnodes>",
56+
// Flags: []cli.Flag{
57+
// P2pPortFlag,
58+
// IPFlag,
59+
// RPCFlag,
60+
// },
61+
// Category: "CC CLI",
62+
// Description: `
63+
// The command runs a new node.
64+
// It expects the <bootnodes> file as an argument.`,
65+
// }
66+
// )
67+
68+
// // It creates a default node based on the command line arguments and runs it in
69+
// // blocking mode, waiting for it to be shut down.
70+
// // func runNode(ctx *cli.Context) error {
71+
// // bootnodesFile := ctx.Args().First()
72+
// // port := ctx.Int("port")
73+
// // ip := ctx.String("ip")
74+
// // rpcFlag := ctx.Bool("rpc") // BoolTFlag returns false if no flag was set
75+
76+
// // bootnodes := getBootnodesFromFile(bootnodesFile)
77+
78+
// // // Creating a new Node.
79+
// // // Takes port and ip command line arguments as parameters
80+
// // n, err := node.NewNode(port, ip, bootnodes)
81+
// // common.CheckErr(err, "[initNode] Failed to create node.")
82+
83+
// // // Create a cancellable context for our GRPC call
84+
// // ctxt, cancel := context.WithCancel(context.Background())
85+
// // defer cancel()
86+
// // n.Start(ctxt, rpcFlag)
87+
88+
// // return nil
89+
// // }
90+
91+
// // getBootnodesFromFile returns a slice of bootnodes given the file bootnodesFile
92+
// func getBootnodesFromFile(bootnodesFile string) []string {
93+
// bootnodes := make([]string, 0)
94+
// if bootnodesFile != "" {
95+
// file, err := os.Open(bootnodesFile)
96+
// common.CheckErr(err, "[getBootnodes] Failed to open the bootnodes file.")
97+
98+
// defer file.Close()
99+
// scanner := bufio.NewScanner(file)
100+
// for scanner.Scan() {
101+
// bootnodes = append(bootnodes, scanner.Text())
102+
// fmt.Println(scanner.Text())
103+
// }
104+
// }
105+
// return bootnodes
106+
// }

0 commit comments

Comments
 (0)