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 10 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
14 changes: 6 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ jobs:
- checkout
- setup_remote_docker
- run: docker swarm init
- <<: *restore_go_cache
- <<: *restore_go_mod_cache
- run: go mod download
- run: make test
- <<: *save_go_mod_cache
- run: mkdir -p ~/.mesg
- <<: *restore_go_cache
- run: go test -v -timeout 300s -coverprofile=coverage.txt ./...
- <<: *save_go_cache
- run: bash <(curl -s https://codecov.io/bash)

Expand All @@ -60,25 +58,25 @@ jobs:
steps:
- checkout
- <<: *restore_go_mod_cache
- run: go mod download
- run: golangci-lint run
- run: make lint

"publish_docker_dev":
<<: *run_on_machine
steps:
- checkout
- run: docker build -t mesg/engine:dev --build-arg version="dev build `echo $CIRCLE_SHA1 | cut -c1-7`" .
- run: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run: make docker-dev version="dev build `echo $CIRCLE_SHA1 | cut -c1-7`" .
- run: docker push mesg/engine:dev

"publish_docker_prod":
<<: *run_on_machine
steps:
- checkout
- run: docker build -t mesg/engine:$CIRCLE_TAG -t mesg/engine:latest -t `echo mesg/engine:$CIRCLE_TAG | cut -d'.' -f1-2` --build-arg version=$CIRCLE_TAG .
- run: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run: make docker version=$CIRCLE_TAG .
- run: docker push mesg/engine:$CIRCLE_TAG
- run: docker push `echo mesg/engine:$CIRCLE_TAG | cut -d'.' -f1-2`
- run: docker push `echo mesg/engine:$CIRCLE_TAG | cut -d'.' -f1`
- run: docker push mesg/engine:latest

workflows:
Expand Down
File renamed without changes.
39 changes: 28 additions & 11 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
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
coverage.txt

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

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
coverage.txt

.vscode
debug
Expand All @@ -28,3 +29,6 @@ tmp-systemservices

# gogo extension
gogo/

main
engine
12 changes: 3 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,13 @@ RUN go mod download

COPY . .
ARG version
ENV version=${version}
RUN ./scripts/build-engine.sh
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
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.PHONY: all check-env docker docker-dev docker-tools dev lint dep build test mock protobuf changelog clean

all: clean test build docker

MAJOR_VERSION := $(shell echo $(version) | cut -d . -f 1)
MINOR_VERSION := $(shell echo $(version) | cut -d . -f 1-2)
PATCH_VERSION := $(version)

check-env:
ifndef version
$(error version is undefined)
endif

docker: check-env
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=$(version) .
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved

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=$(version)'" core/main.go
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved

test: dep
go test -mod=readonly -v -coverprofile=coverage.txt ./...

lint: dep
golangci-lint run

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 $(milestone)

clean:
- rm -rf bin/*
- docker image rm \
mesg/engine:$(MAJOR_VERSION) \
mesg/engine:$(MINOR_VERSION) \
mesg/engine:$(PATCH_VERSION) \
mesg/engine:$(version) \
mesg/engine:latest \
mesg/engine:dev 2>/dev/null
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.

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

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

# generate mocks
mockery -name ExecutionSDK -dir ./orchestrator -output ./orchestrator/mocks
mockery -name EventSDK -dir ./orchestrator -output ./orchestrator/mocks
Expand Down
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.