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

Run scripts from Makefile #1402

Merged
merged 19 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
38 changes: 27 additions & 11 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
Dockerfile
Dockerfile-dev
.circleci
.vscode

# repo files
README.md
CHANGELOG.md
CONTRIBUTING.md
schema1.svg
.github

/scripts
/examples
/test
dev
mesg-dev
.git

# test & debug files
**/*_test.go
**/*.test
**/debug
**/node_modules
bin/cli
docs/
docker-images/
.tendermint-validator/
/docker-images
krhubert marked this conversation as resolved.
Show resolved Hide resolved
/test
/vendor

# configuration & repo files
Makefile
.circleci
.codacy.yml
.codeclimate.yml
.codecov.yml
.git
.gitignore
.golangci.yml
.genesis
.vscode
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ tmp-systemservices

# gogo extension
gogo/

main
engine
13 changes: 4 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# base Go image version.
FROM golang:1.13.0-stretch AS build

RUN apt-get update && \
apt-get install -y jq && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /project

# install dependencies
Expand All @@ -14,14 +9,14 @@ RUN go mod download

COPY . .
ARG version
ENV version=${version}
RUN ./scripts/build-engine.sh
ENV PATCH_VERSION=${version}
krhubert marked this conversation as resolved.
Show resolved Hide resolved
RUN go build -mod=readonly -o ./bin/engine -ldflags="-X 'github.com/mesg-foundation/engine/version.Version=$version'" core/main.go

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/*
WORKDIR /app
COPY --from=build /project/engine .
CMD ["./engine"]
COPY --from=build /project/bin/engine .
CMD ["./bin/engine"]
krhubert marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 0 additions & 7 deletions Dockerfile.dev

This file was deleted.

1 change: 0 additions & 1 deletion Dockerfile.tools
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ RUN mkdir -p /usr/local/include/gogo/protobuf/ && \
COPY go.mod go.sum ./
RUN go mod download

RUN go install github.com/go-bindata/go-bindata/go-bindata
RUN go install github.com/golang/protobuf/protoc-gen-go
RUN go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
RUN go install github.com/vektra/mockery/.../
Expand Down
52 changes: 52 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.PHONY: all docker docker-dev docker-tools dev dep build test mock protobuf changelog clean

all: clean test build docker

MAJOR_VERSION := $(shell git describe --abbrev=0 | cut -d . -f 1)
MINOR_VERSION := $(shell git describe --abbrev=0 | cut -d . -f 1-2)
PATCH_VERSION := $(shell git describe --abbrev=0)
DEV_VERSION := $(shell git describe)
antho1404 marked this conversation as resolved.
Show resolved Hide resolved

docker:
docker build \
--build-arg version=$(PATCH_VERSION) \
-t mesg/engine:$(MAJOR_VERSION) \
-t mesg/engine:$(MINOR_VERSION) \
-t mesg/engine:$(PATCH_VERSION) \
-t mesg/engine:latest \
.
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved

docker-dev:
docker build -t mesg/engine:dev --build-arg version=$(DEV_VERSION) -f Dockerfile .

docker-tools:
docker build -t mesg/tools:local -f Dockerfile.tools .

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

dep:
go mod download

build: dep
go build -mod=readonly -o ./bin/engine -ldflags="-X 'github.com/mesg-foundation/engine/version.Version=$(PATCH_VERSION)'" core/main.go
krhubert marked this conversation as resolved.
Show resolved Hide resolved

test:
go test ./...

mock: docker-tools
docker run --rm -v $(PWD):/project mesg/tools:local ./scripts/build-mocks.sh

protobuf: docker-tools
docker run --rm -v $(PWD):/project mesg/tools:local ./scripts/build-proto.sh

changelog:
./scripts/changelog.sh
krhubert marked this conversation as resolved.
Show resolved Hide resolved

clean:
- rm -rf bin/*
- docker image rm \
mesg/engine:$(MAJOR_VERSION) \
mesg/engine:$(MINOR_VERSION) \
mesg/engine:$(PATCH_VERSION) \
mesg/engine:latest
10 changes: 0 additions & 10 deletions mesg-tools

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/build-engine.sh

This file was deleted.

5 changes: 1 addition & 4 deletions scripts/build-mocks.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/bash -e

# make sure script is running inside mesg/tools container.
source $(dirname $0)/require-mesg-tools.sh

# generate mocks
mockery -name Container -dir ./container -output ./container/mocks
mockery -name CommonAPIClient -dir ./internal/mocks -output ./utils/docker/mocks
mockery -name ExecutionSDK -dir ./orchestrator -output ./orchestrator/mocks
mockery -name EventSDK -dir ./orchestrator -output ./orchestrator/mocks
mockery -name ProcessSDK -dir ./orchestrator -output ./orchestrator/mocks
mockery -name ProcessSDK -dir ./orchestrator -output ./orchestrator/mocks
3 changes: 0 additions & 3 deletions scripts/build-proto.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash

# make sure script is running inside mesg/tools container.
source $(dirname $0)/require-mesg-tools.sh

TYPES_PATH=protobuf/types
APIS_PATH=protobuf/api

Expand Down
2 changes: 2 additions & 0 deletions scripts/changelog.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

[ -z "$1" ] && echo "milestone required" && exit

MILESTONE="$1"

LABELS=("breaking change" "experimental" "release:add" "release:change" "release:fix" "release:remove")
Expand Down
46 changes: 2 additions & 44 deletions dev → scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ if [[ $* == *--genesis_account ]]; then
rsync -a $MESG_COSMOS_KEYBASE_PATH/ $MESG_COSMOS_HOME_CONFIG
fi

VERSION=local
LDFLAGS="-X 'github.com/mesg-foundation/engine/version.Version=$VERSION'"

function onexit {
set +e
echo -e "\nshutting down, please wait..."
Expand Down Expand Up @@ -78,42 +75,6 @@ function docker_network_remove {
docker network remove "$1"
}

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

ENGINE_SUM_PATH="./bin/.engine.sum"
touch "$ENGINE_SUM_PATH"

DOCKER_SUM_PATH="./bin/.Dockerfile.dev.sum"
touch "$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

# create mesg data folder on host machine
mkdir -p $MESG_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still important!


if [[ ! $BINCACHED ]] || [[ ! $DOCKERCACHED ]]; then
echo "build mesg/engine image"
docker build -f Dockerfile.dev -t "mesg/engine:$VERSION" .
fi


trap onexit EXIT

if ! docker_network_exist "$MESG_NAME"; then
Expand All @@ -124,14 +85,12 @@ if ! docker_network_exist "$MESG_TENDERMINT_NETWORK"; then
docker_network_create "$MESG_TENDERMINT_NETWORK"
fi



echo "create docker service: "
docker service create \
--name $MESG_NAME \
--tty \
--label com.docker.stack.namespace=$MESG_NAME \
--label com.docker.stack.image=mesg/engine:$VERSION \
--label com.docker.stack.image=mesg/engine:dev \
--env MESG_NAME=$MESG_NAME \
--env MESG_LOG_FORMAT=$MESG_LOG_FORMAT \
--env MESG_LOG_FORCECOLORS=$MESG_LOG_FORCECOLORS \
Expand All @@ -147,7 +106,6 @@ docker service create \
--network name=$MESG_TENDERMINT_NETWORK \
--publish $MESG_SERVER_PORT:50052 \
$MESG_TENDERMINT_VALIDATOR_PORT_PUBLISH \
mesg/engine:$VERSION ./engine $EXPERIMENTAL_FLAGS

mesg/engine:dev

docker service logs --follow --raw $MESG_NAME
15 changes: 0 additions & 15 deletions scripts/require-mesg-tools.sh

This file was deleted.