Skip to content

Commit

Permalink
Adds docker changes for cli framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
ackleymi committed Aug 20, 2018
1 parent 89b2048 commit 0bfead6
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 64 deletions.
48 changes: 34 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
FROM golang:1.10.3-alpine

ARG tag
# -*- mode: dockerfile -*-
#
# A multi-stage Dockerfile that builds a Linux target then creates a small
# final image for deployment.

#
# STAGE 1
#
# Uses a Go image to build a release binary.
#
FROM golang:1.10.3-alpine AS builder
ARG tag=latest
ENV DOCKER_TAG=$tag

RUN apk update
RUN apk --no-cache add git make tar bash curl alpine-sdk su-exec
RUN go get -u github.com/golang/dep/... && mv /go/bin/dep /usr/local/bin/dep

ADD . /go/src/github.com/alpacahq/marketstore
WORKDIR /go/src/github.com/alpacahq/marketstore
RUN apk --no-cache add git make gcc g++
RUN go get -u github.com/golang/dep/...
WORKDIR /go/src/github.com/alpacahq/marketstore/
ADD ./ ./
RUN dep ensure -vendor-only
RUN make install plugins

RUN make configure all plugins
#
# STAGE 2
#
# Use a tiny base image (alpine) and copy in the release target. This produces
# a very small output image for deployment.
#
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /
COPY --from=builder /go/bin/marketstore /bin/
COPY --from=builder /go/bin/*.so /bin/

COPY entrypoint.sh /bin/
RUN chmod +x /bin/entrypoint.sh
ENTRYPOINT ["/bin/entrypoint.sh"]
RUN ["marketstore", "init"]
RUN mv mkts.yml etc/
VOLUME /data
EXPOSE 5993

CMD marketstore
ENTRYPOINT ["marketstore"]
CMD ["start", "--config", "etc/mkts.yml"]
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ unittest:
go test ./...

push:
docker build --build-arg tag=$(DOCKER_TAG) -t alpacamarkets/marketstore:$(DOCKER_TAG) .
docker build --build-arg tag=$(DOCKER_TAG) -t alpacamarkets/marketstore:$(DOCKER_TAG) -t alpacamarkets/marketstore:latest .
docker login -u $(DOCKER_USER) -p $(DOCKER_PASS)
docker push alpacamarkets/marketstore:$(DOCKER_TAG)
docker push alpacamarkets/marketstore:latest
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ MarketStore is production ready! At [Alpaca](https://alpaca.markets) it has been
## Install

### Docker
If you want to get started right away, you can bootstrap a marketstore db instance using our latest [docker image](https://hub.docker.com/r/alpacamarkets/marketstore/tags/).

These examples assume that the directory "/tmp" and the file "/tmp/mkts.yml" exist. So, the following procedure is needed when you run docker containers for the first time:

If you want to get started right away, you can bootstrap a marketstore db instance using our latest [docker image](https://hub.docker.com/r/alpacamarkets/marketstore/tags/). The image comes pre-loaded with the default mkts.yml file and declares the VOLUME `/data`, as its root directory. To run the container with the defaults:
``` sh
$ mkdir /tmp
$ pwd
/path/to/marketstore
$ cp mkts.yml /tmp
docker run -i -p 5993:5993 alpacamarkets/marketstore:latest
```

The following example runs the docker image using a temporary configuration file mkts.yml located in the /tmp folder. The -v refers to mounting to a volume. So, the "/tmp/mktsdb" replaces the original "/project/data/mktsdb" root directory. Note that you can edit this mkts.yml.
If you want to run a custom `mkts.yml` with your instance, you can create a new container, load your mkts.yml file into it, then run it.
``` sh
docker create --name mktsdb -p 5993:5993 alpacamarkets/marketstore:latest
docker cp mkts.yml mktsdb:etc/mkts.yml
docker start -i mktsdb
```

Open a session with your running docker instance using
``` sh
docker run -v /tmp/mktsdb:/project/data/mktsdb -v /tmp/mkts.yml:/tmp/mkts.yml -p 5993:5993 alpacamarkets/marketstore:v2.3.8 marketstore state --config /tmp/mkts.yml
marketstore connect --url localhost:5993
```

### Source
Expand Down
26 changes: 11 additions & 15 deletions cmd/create/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cmd/create/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Package create - because packages cannot be named 'init' in go.
//go:generate go-bindata -pkg create default.yml
package create

import (
Expand Down Expand Up @@ -30,7 +31,7 @@ var (
// executeInit implements the init command.
func executeInit(*cobra.Command, []string) error {
// serialize default file.
data, err := Asset("cmd/create/default.yml")
data, err := Asset("default.yml")
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package cmd

import (
"fmt"

"github.com/alpacahq/marketstore/cmd/connect"
"github.com/alpacahq/marketstore/cmd/create"
"github.com/alpacahq/marketstore/cmd/start"
"github.com/alpacahq/marketstore/cmd/tool"
"github.com/alpacahq/marketstore/utils"
. "github.com/alpacahq/marketstore/utils/log"
"github.com/spf13/cobra"
)

Expand All @@ -22,9 +23,9 @@ func Execute() error {
RunE: func(cmd *cobra.Command, args []string) error {
// Print version if specified.
if flagPrintVersion {
Log(INFO, "version: %+v\n", utils.Tag)
Log(INFO, "commit hash: %+v\n", utils.GitHash)
Log(INFO, "utc build time: %+v\n", utils.BuildStamp)
fmt.Printf("version: %+v\n", utils.Tag)
fmt.Printf("commit hash: %+v\n", utils.GitHash)
fmt.Printf("utc build time: %+v\n", utils.BuildStamp)
return nil
}
// Print information regarding usage.
Expand Down
14 changes: 0 additions & 14 deletions entrypoint.sh

This file was deleted.

2 changes: 0 additions & 2 deletions marketstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate go-bindata -pkg create -o cmd/create/bindata.go cmd/create/default.yml

package main

import (
Expand Down

0 comments on commit 0bfead6

Please sign in to comment.