Skip to content

Commit

Permalink
Build engine outside docker
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Oct 22, 2019
1 parent da81300 commit cb674d0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:18.04
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates=20180409 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY ./bin/engine .
CMD [ "./engine" ]
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAJOR_VERSION := $(shell echo $(version) | cut -d . -f 1)
MINOR_VERSION := $(shell echo $(version) | cut -d . -f 1-2)
PATCH_VERSION := $(version)

all: clean test dev
all: clean lint test build

check-version:
ifndef version
Expand All @@ -20,6 +20,10 @@ docker-build: check-version
-t mesg/engine:latest \
.

docker-dev:
./scripts/build-engine.sh


docker-publish: docker-build
docker push mesg/engine:$(MAJOR_VERSION)
docker push mesg/engine:$(MINOR_VERSION)
Expand All @@ -33,8 +37,8 @@ docker-publish-dev: check-version
docker-tools:
docker build -t mesg/tools:local -f Dockerfile.tools .

dev:
docker build -t mesg/engine:local --build-arg version=local .

dev: docker-dev
- ./scripts/dev.sh

dep:
Expand Down
39 changes: 39 additions & 0 deletions scripts/build-engine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# script is use to use local go cache to speed up build
# docker dosen't allow to mount volume during build,
# so it always rebuild whole project. Use go build cache to
# make docker build faster.

set -e

ENGINE_SUM_PATH="./bin/.engine.sum"
DOCKER_SUM_PATH="./bin/.Dockerfile.dev.sum"

echo "compile engine"
GOOS=linux GOARCH=amd64 go build -o ./bin/engine core/main.go

touch "$ENGINE_SUM_PATH" "$DOCKER_SUM_PATH"

# check if engine bin was cached
ENGINE_SUM="$(openssl md5 ./bin/engine)"
ENGINE_SUM_PREV="$(cat $ENGINE_SUM_PATH)"
if [[ "$ENGINE_SUM" == "$ENGINE_SUM_PREV" ]]; then
BINCACHED=true
else
echo "$ENGINE_SUM" > "$ENGINE_SUM_PATH"
fi

# check if dockerfile was cached
DOCKER_SUM="$(openssl md5 ./Dockerfile.dev)"
DOCKER_SUM_PREV="$(cat $DOCKER_SUM_PATH)"
if [[ "$DOCKER_SUM" == "$DOCKER_SUM_PREV" ]]; then
DOCKERCACHED=true
else
echo "$DOCKER_SUM" > "$DOCKER_SUM_PATH"
fi

if [[ ! $BINCACHED ]] || [[ ! $DOCKERCACHED ]]; then
echo "build mesg/engine image"
docker build -f Dockerfile.dev -t "mesg/engine:local" .
fi
2 changes: 2 additions & 0 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ if ! docker_network_exist "$MESG_TENDERMINT_NETWORK"; then
docker_network_create "$MESG_TENDERMINT_NETWORK"
fi

mkdir -p $MESG_PATH

echo "create docker service: "
docker service create \
--name $MESG_NAME \
Expand Down

0 comments on commit cb674d0

Please sign in to comment.