Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Add docker and cli support #7

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
docker-compose.yml
LICENSE
README.md

9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM alpine:3.4

RUN apk add --no-cache git bash vim ca-certificates openssl docker go nodejs

COPY zoneinfo.zip /build/zoneinfo.zip
COPY upx /bin/upx

ENV GOPATH /go
RUN mkdir /pkg
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Instructions for using these binaries are on the GitHub [releases page](https://

If you want to try the latest version, you can build SummitDB from the master branch.


If your using docker you can get the specific version of summitdb like this,
`docker pull pyros2097/summitdb:0.2.2`

### Building SummitDB

SummitDB can be compiled and used on Linux, OSX, Windows, FreeBSD, and probably others since the codebase is 100% Go. We support both 32 bit and 64 bit systems. Go must be installed on the build machine.
Expand All @@ -55,6 +59,12 @@ To run tests:
````
$ make test
```

To build the docker image:
```
$ RELEASE=0.2.2 docker-compose run build-image
```




Expand Down Expand Up @@ -85,6 +95,11 @@ $ ./summitdb-server -p 7483 -dir data3 -join :7481

That's it. Now if node1 goes down, node2 and node3 will continue to operate.


To Run it using docker use this command,

`docker run -v /tmp:/tmp -p 7481:7481 pyros2097/summitdb:0.2.2`

## Difference between SummitDB and Redis

*It may be worth noting that SummitDB is not a Redis clone. Redis has a lot of commands and data types that are not available in SummitDB, such Sets, Hashes, Sorted Sets, and PubSub.*
Expand Down
41 changes: 41 additions & 0 deletions cmd/summitdb-cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"flag"
"fmt"

"github.com/garyburd/redigo/redis"
)

func Command(conn redis.Conn, name string, args ...string) {
reply, err := conn.Do(name, args[0], args[1])
if err != nil {
fmt.Printf("Error %v\n", err)
}
switch t := reply.(type) {
case []byte:
fmt.Println(string(t))
case string:
fmt.Println(t)
default:
fmt.Printf("Result %v\n", reply)
}
}

func main() {
var host = flag.String("h", "localhost" , "Server host")
var port = flag.String("p", ":7481" , "Server port")
flag.Parse()
var url = *host + ":" + *port
conn, err := redis.Dial("tcp", url)
if err != nil {
fmt.Println("Could not connect to SummitDB at "+url)
fmt.Println("Please pass the right parameters")
flag.PrintDefaults()
return
}
fmt.Println("Connected to SummitDB at "+url)
defer conn.Close()
// Command(conn, "JSET", "user24", "age", "44")
Command(conn, "JGET", "user24", "age")
}
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '2'
services:
server:
build: .
working_dir: /go/src/github.com/tidwall/summitdb
command: go run cmd/summitdb-server/main.go
ports:
- "7481:7481"
volumes:
- .:/go/src/github.com/tidwall/summitdb
cli:
build: .
working_dir: /go/src/github.com/tidwall/summitdb
command: go run cmd/summitdb-cli/main.go -h server -p 7481
volumes:
- .:/go/src/github.com/tidwall/summitdb
links:
- server
build-image:
build: .
working_dir: /go/src/github.com/tidwall/summitdb
command: bash ./prod.sh
environment:
RELEASE: ${RELEASE}
volumes:
- .:/go/src/github.com/tidwall/summitdb
- /var/run/docker.sock:/var/run/docker.sock
18 changes: 18 additions & 0 deletions prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -e
if [ -z "$RELEASE" ]; then
echo "Need to set RELEASE env variable"
exit 1
fi
echo "Building executable"
CGO_ENABLED=0 go build -a -ldflags '-s -w' -o /build/prj cmd/summitdb-server/main.go
echo "Compressing executable"
./upx --best --lzma /build/prj
echo "Builing docker image"
cat >/build/Dockerfile <<EOL
FROM centurylink/ca-certs
COPY zoneinfo.zip /usr/lib/go/lib/time/zoneinfo.zip
COPY prj /
ENTRYPOINT ["/prj"]
EOL
cd /build
docker build -t pyros2097/summitdb:$RELEASE .
Binary file added upx
Binary file not shown.
Binary file added zoneinfo.zip
Binary file not shown.