Skip to content

Commit

Permalink
docker: add docker file for dev and runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 committed Jul 25, 2017
1 parent d951854 commit 2637359
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 37 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ language: go
services:
- docker


before_install:
- docker pull deepfabric/elasticell-dev
- docker pull deepfabric/elasticell-build
- mkdir -p /tmp/elasticell

install: true

script:
- docker build -t deepfabric/elasticell .
- docker build -t deepfabric/elasticell .
- docker run -it --rm -v /tmp/elasticell:/apps/deepfabric/dist -e ELASTICELL_BUILD_TARGET=all deepfabric/elasticell-build
10 changes: 0 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@ COPY ./ /go/src/github.com/deepfabric/elasticell
RUN cd /go/src/github.com/deepfabric/elasticell \
&& go test -v ./...

RUN cd /go/src/github.com/deepfabric/elasticell/cmd/pd \
&& go build -ldflags "-w -s" pd.go \
&& chmod +x ./pd \
&& mv ./pd /apps/deepfabric

RUN cd /go/src/github.com/deepfabric/elasticell/cmd/cell \
&& go build -ldflags "-w -s" cell.go \
&& chmod +x ./cell \
&& mv ./cell /apps/deepfabric

WORKDIR /apps/deepfabric
12 changes: 12 additions & 0 deletions Dockerfile-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM deepfabric/elasticell-dev

RUN mkdir -p /apps/deepfabric

COPY ./entrypoint-build.sh /apps/deepfabric

RUN apt-get update \
&& apt-get install -y git \
&& chmod +x /apps/deepfabric/entrypoint-build.sh

WORKDIR /apps/deepfabric
ENTRYPOINT ./entrypoint-build.sh
25 changes: 25 additions & 0 deletions Dockerfile-cell
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM ubuntu:16.04

RUN mkdir -p /apps/deepfabric

COPY ./dist/cell /apps/deepfabric
COPY ./entrypoint.sh /apps/deepfabric

RUN apt-get update \
&& apt-get -y install libsnappy-dev \
&& apt-get -y install zlib1g-dev \
&& apt-get -y install libbz2-dev \
&& apt-get -y install libgtest-dev \
&& apt-get -y install libjemalloc-dev

RUN chmod +x /apps/deepfabric/cell \
&& chmod +x /apps/deepfabric/entrypoint.sh \

ENV ELASTICELL_HOME=/apps/deepfabric
ENV ELASTICELL_EXEC=cell
ENV ELASTICELL_LOG_LEVEL=INFO
ENV ELASTICELL_LOG_TARGET=CONSOLE

WORKDIR /apps/deepfabric

ENTRYPOINT ./entrypoint.sh
18 changes: 18 additions & 0 deletions Dockerfile-pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:16.04

RUN mkdir -p /apps/deepfabric

COPY ./dist/pd /apps/deepfabric
COPY ./entrypoint.sh /apps/deepfabric

RUN chmod +x /apps/deepfabric/pd \
&& chmod +x /apps/deepfabric/entrypoint.sh

ENV ELASTICELL_HOME=/apps/deepfabric
ENV ELASTICELL_EXEC=pd
ENV ELASTICELL_LOG_LEVEL=INFO
ENV ELASTICELL_LOG_TARGET=CONSOLE

WORKDIR /apps/deepfabric

ENTRYPOINT ./entrypoint.sh
18 changes: 18 additions & 0 deletions Dockerfile-proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:16.04

RUN mkdir -p /apps/deepfabric

COPY ./dist/redis-proxy /apps/deepfabric
COPY ./entrypoint.sh /apps/deepfabric

RUN chmod +x /apps/deepfabric/pd \
&& chmod +x /apps/deepfabric/entrypoint.sh \

ENV ELASTICELL_HOME=/apps/deepfabric
ENV ELASTICELL_EXEC=redis-proxy
ENV ELASTICELL_LOG_LEVEL=INFO
ENV ELASTICELL_LOG_TARGET=CONSOLE

WORKDIR /apps/deepfabric

ENTRYPOINT ./entrypoint.sh
87 changes: 87 additions & 0 deletions entrypoint-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#/bin/bash

SRC=/go/src/github.com/deepfabric
DIST_DIR=/apps/deepfabric/dist
TARGET=$ELASTICELL_BUILD_TARGET
VERSION=$ELASTICELL_BUILD_VERSION

clone_all() {
clone_elasticell
clone_elasticell_proxy
}

clone_elasticell() {
cd $SRC
git clone https://github.com/deepfabric/elasticell.git
echo "elasticell clone complete."
cd $SRC/elasticell
git checkout $VERSION
echo "elasticell checkout to: $VERSION."
}

clone_elasticell_proxy() {
cd $SRC
git clone https://github.com/deepfabric/elasticell-proxy.git
echo "elasticell-proxy clone complete."
cd $SRC/elasticell-proxy
git checkout $VERSION
echo "elasticell-proxy checkout to: $VERSION."
}

build_proxy() {
echo "start to build elasticell-proxy."
cd $SRC/elasticell-proxy/cmd/redis
go build -ldflags "-w -s" redis-proxy.go
echo "complete build elasticell-proxy."
chmod +x ./redis-proxy
mv ./redis-proxy $DIST_DIR
}

build_pd() {
echo "start to build pd."
cd $SRC/elasticell/cmd/pd
go build -ldflags "-w -s" pd.go
echo "complete build pd."
chmod +x ./pd
mv ./pd $DIST_DIR
}

build_cell() {
echo "start to build cell."
cd $SRC/elasticell/cmd/cell
go build -ldflags "-w -s" cell.go
echo "complete build cell."
chmod +x ./cell
mv ./cell $DIST_DIR
}

build_all() {
build_proxy
build_pd
build_cell
}

if [ "$VERSION" = "" ]; then
VERSION="master"
fi

DIST_DIR=$DIST_DIR/$VERSION
mkdir -p $DIST_DIR

echo "build target: $TARGET"
echo "build version: $VERSION"
echo "build dist: $DIST_DIR"

if [ "$TARGET" = "pd" ]; then
clone_elasticell
build_pd
elif [ "$TARGET" = "cell" ]; then
clone_elasticell
build_cell
elif [ "$TARGET" = "proxy" ]; then
clone_all
build_proxy
elif [ "$TARGET" = "all" ]; then
clone_all
build_all
fi
18 changes: 18 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

HOME=$ELASTICELL_HOME
EXEC=$HOME/$ELASTICELL_EXEC

LOG_LEVEL=$ELASTICELL_LOG_LEVEL
LOG_TARGET=$ELASTICELL_LOG_TARGET
CFG_FILE=$HOME/cfg/cfg.json
LOG_FILE=$HOME/log/$ELASTICELL_EXEC.log

if [ "$LOG_TARGET" = "CONSOLE" ]; then
$EXEC --cfg=$CFG_FILE --log-level=$LOG_LEVEL
elif [ "$LOG_TARGET" = "FILE" ]; then
$EXEC --cfg=$CFG_FILE --log-level=$LOG_LEVEL --log-file=$LOG_FILE
else
echo "invalid ELASTICELL_LOG_TARGET env: $LOG_TARGET"
fi

15 changes: 4 additions & 11 deletions pkg/storage/nemo_engine_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,10 @@ func (s *testNemoDataSuite) SetUpSuite(c *C) {
}

func (s *testNemoDataSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-data")
c.Assert(err, IsNil)

err = os.RemoveAll(snapPath)
c.Assert(err, IsNil)

err = os.RemoveAll(snapCreatePath)
c.Assert(err, IsNil)

err = os.RemoveAll(applyPath)
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-data")
os.RemoveAll(snapPath)
os.RemoveAll(snapCreatePath)
os.RemoveAll(applyPath)
}

func (s *testNemoDataSuite) TestRangeDelete(c *C) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/nemo_engine_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func (s *testNemoHashSuite) SetUpSuite(c *C) {
}

func (s *testNemoHashSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-hash")
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-hash")
}

func (s *testNemoHashSuite) TestHSet(c *C) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/nemo_engine_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func (s *testNemoKVSuite) SetUpSuite(c *C) {
}

func (s *testNemoKVSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-kv")
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-kv")
}

func (s *testNemoKVSuite) TestSet(c *C) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/nemo_engine_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func (s *testNemoListSuite) SetUpSuite(c *C) {
}

func (s *testNemoListSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-list")
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-list")
}

func (s *testNemoListSuite) TestLIndex(c *C) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/nemo_engine_meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func (s *testNemoMetaSuite) SetUpSuite(c *C) {
}

func (s *testNemoMetaSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-meta")
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-meta")
}

func (s *testNemoMetaSuite) TestSet(c *C) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/nemo_engine_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func (s *testNemoSetSuite) SetUpSuite(c *C) {
}

func (s *testNemoSetSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-set")
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-set")
}

func (s *testNemoSetSuite) TestSAdd(c *C) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/nemo_engine_zset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ func (s *testNemoZSetSuite) SetUpSuite(c *C) {
}

func (s *testNemoZSetSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-zset")
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-zset")
}

func (s *testNemoZSetSuite) TestZAdd(c *C) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/nemo_writebatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func (s *testNemoWBSuite) SetUpSuite(c *C) {
}

func (s *testNemoWBSuite) TearDownSuite(c *C) {
err := os.RemoveAll("/tmp/nemo-wb")
c.Assert(err, IsNil)
os.RemoveAll("/tmp/nemo-wb")
}

func (s *testNemoWBSuite) TestWB(c *C) {
Expand Down

0 comments on commit 2637359

Please sign in to comment.