Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully automate dev setup with Gitpod #398

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM gitpod/workspace-full

# Install custom tools, runtimes, etc.
# For example "bastet", a command-line tetris clone:
# RUN brew install bastet
#
# More information: https://www.gitpod.io/docs/config-docker/
5 changes: 5 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
image:
file: .gitpod.Dockerfile

tasks:
- init: make
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/globalsign/mgo)

[![Build Status](https://travis-ci.org/globalsign/mgo.svg?branch=master)](https://travis-ci.org/globalsign/mgo) [![GoDoc](https://godoc.org/github.com/globalsign/mgo?status.svg)](https://godoc.org/github.com/globalsign/mgo)

The MongoDB driver for Go
Expand Down
40 changes: 36 additions & 4 deletions dbtest/dbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type DBServer struct {
dbpath string
host string
tomb tomb.Tomb
// ReplicaSet, if set to true, will initiate a 1-member replica set
ReplicaSet bool
}

// SetPath defines the path to the directory where the database files will be
Expand All @@ -55,15 +57,23 @@ func (dbs *DBServer) start() {
l.Close()
dbs.host = addr.String()

portString := strconv.Itoa(addr.Port)
args := []string{
"--dbpath", dbs.dbpath,
"--bind_ip", "127.0.0.1",
"--port", strconv.Itoa(addr.Port),
"--bind_ip", "127.0.0.1,127.0.1.1",
"--port", portString,
"--nssize", "1",
"--noprealloc",
"--smallfiles",
"--nojournal",
"--logpath", dbs.dbpath + "/mongo.log",
}
if dbs.ReplicaSet == false {
args = append(args, "--nojournal")
} else {
args = append(args, "--replSet", "rs0")
}

fmt.Println("TAHER: Starting mongod with args", args)
dbs.tomb = tomb.Tomb{}
dbs.server = exec.Command("mongod", args...)
dbs.server.Stdout = &dbs.output
Expand All @@ -74,6 +84,27 @@ func (dbs *DBServer) start() {
fmt.Fprintf(os.Stderr, "mongod failed to start: %v\n", err)
panic(err)
}

fmt.Println("Started mongodb...")
if dbs.ReplicaSet {
retryAttempts := 20
for retryAttempts > 0 {
retryAttempts--
time.Sleep(1 * time.Second)
fmt.Printf("Starting rs.initiate, attempt left %d...\n", retryAttempts)
out, err := exec.Command("mongo", "127.0.0.1:"+portString, "--eval", "rs.initiate()").CombinedOutput()
if err != nil {
fmt.Fprintf(os.Stderr, "replicaset initiate failed: %v\n", err)
if retryAttempts == 0 {
panic(err.Error() + "," + string(out))
}
} else {
retryAttempts = 0
fmt.Println("Mongod replset initiated")
}
}
}

dbs.tomb.Go(dbs.monitor)
dbs.Wipe()
}
Expand Down Expand Up @@ -140,7 +171,8 @@ func (dbs *DBServer) Session() *mgo.Session {
if dbs.session == nil {
mgo.ResetStats()
var err error
dbs.session, err = mgo.Dial(dbs.host + "/test")
d, err := mgo.ParseURL(dbs.host + "/test?connect=replicaSet")
dbs.session, err = mgo.DialWithInfo(d)
if err != nil {
panic(err)
}
Expand Down