Skip to content

Commit

Permalink
update dockerfile and scripts to switch all to cli based engine
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasMahe committed May 6, 2020
1 parent 901615d commit 4760af0
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 329 deletions.
26 changes: 13 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ run_on_machine: &run_on_machine

run_on_docker: &run_on_docker
docker:
- image: circleci/golang:1.13.0
- image: circleci/golang:1.13.10

go_path: &go_path /tmp/go/path

Expand Down Expand Up @@ -65,12 +65,12 @@ jobs:
name: "Install Go"
command: |
sudo rm -rf /usr/local/go
curl -sSL "https://dl.google.com/go/go1.13.linux-amd64.tar.gz" | sudo tar -xz -C /usr/local/
curl -sSL "https://dl.google.com/go/go1.13.10.linux-amd64.tar.gz" | sudo tar -xz -C /usr/local/
echo "export PATH=$PATH:/usr/local/go/bin" >> $BASH_ENV
- run: docker swarm init
- <<: *restore_go_cache
- <<: *restore_go_path
- run: make e2e version=`echo $CIRCLE_SHA1 | cut -c1-7`
- run: make e2e
- <<: *save_go_path
- <<: *save_go_cache

Expand All @@ -79,33 +79,33 @@ jobs:
- image: golangci/golangci-lint:v1.21
steps:
- checkout
- run: make lint
- run: golangci-lint

"publish_docker_dev":
"publish_docker_unstable":
<<: *run_on_machine
steps:
- checkout
- run: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run: make docker-publish-dev version=`echo $CIRCLE_SHA1 | cut -c1-7`
- run: make publish-docker-unstable version=`echo $CIRCLE_SHA1 | cut -c1-7`

"publish_docker_prod":
<<: *run_on_machine
steps:
- checkout
- run: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run: make docker-publish version=$CIRCLE_TAG
- run: make publish-docker-prod version=$CIRCLE_TAG

"release_cli_dev":
"release_cli_unstable":
<<: *run_on_docker
steps:
- checkout
- run: make publish-cmds version="dev build `echo $CIRCLE_SHA1 | cut -c1-7`" release-type=dev
- run: make publish version="`echo $CIRCLE_SHA1 | cut -c1-7`" release-type=unstable

"release_cli_prod":
<<: *run_on_docker
steps:
- checkout
- run: make publish-cmds version=$CIRCLE_TAG release-type=prod
- run: make publish version=$CIRCLE_TAG release-type=prod

workflows:
version: 2
Expand Down Expand Up @@ -133,7 +133,7 @@ workflows:
- "test"
- "lint"

release_dev:
release_unstable:
jobs:
- "lint":
filters:
Expand All @@ -151,10 +151,10 @@ workflows:
requires:
- "test"
- "lint"
- "publish_docker_dev":
- "publish_docker_unstable":
requires:
- "test_e2e"
- "release_cli_dev":
- "release_cli_unstable":
requires:
- "test_e2e"

Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ Dockerfile

# build
/bin
!/bin/engine

# repo files
README.md
Expand Down
28 changes: 17 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# base Go image version.
FROM golang:1.13.0-stretch AS build

WORKDIR /project
# base Go image version for building the binaries
FROM golang:1.13.10 AS build
WORKDIR /app

# install dependencies
COPY go.mod go.sum ./
RUN go mod download

COPY . .
ARG version
RUN go build -mod=readonly -o ./bin/engine -ldflags="-X 'github.com/mesg-foundation/engine/version.Version=$version'" core/main.go

RUN go build -mod=readonly -o ./bin/mesg-cli -ldflags="-s -w -X 'github.com/cosmos/cosmos-sdk/version.Name=mesg' -X 'github.com/cosmos/cosmos-sdk/version.ServerName=mesg-daemon' -X 'github.com/cosmos/cosmos-sdk/version.ClientName=mesg-cli' -X 'github.com/cosmos/cosmos-sdk/version.Version=$version'" ./cmd/mesg-cli/
RUN go build -mod=readonly -o ./bin/mesg-daemon -ldflags="-s -w -X 'github.com/cosmos/cosmos-sdk/version.Name=mesg' -X 'github.com/cosmos/cosmos-sdk/version.ServerName=mesg-daemon' -X 'github.com/cosmos/cosmos-sdk/version.ClientName=mesg-cli' -X 'github.com/cosmos/cosmos-sdk/version.Version=$version'" ./cmd/mesg-daemon/

# ubuntu image with binaries for distribution
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/*
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/bin/engine .
CMD ["./engine"]
ENV PATH="/app:${PATH}"

COPY --from=build /app/bin/mesg-cli .
COPY --from=build /app/bin/mesg-daemon .

CMD ["mesg-daemon", "start"]
27 changes: 0 additions & 27 deletions Dockerfile.cli

This file was deleted.

8 changes: 0 additions & 8 deletions Dockerfile.cli.dev

This file was deleted.

15 changes: 8 additions & 7 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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" ]
ARG from
FROM $from

COPY ./dev-chain/cli /root/.mesg-cli
COPY ./dev-chain/validator /root/.mesg-node
COPY ./scripts/dev-starter.sh .

CMD ["bash", "dev-starter.sh"]
121 changes: 55 additions & 66 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,98 +1,87 @@
.PHONY: all build build-cmd-cosmos changelog check-version clean clean-build clean-docker dep dev dev-mon dev-start dev-stop docker-build docker-dev docker-publish docker-publish-dev docker-tools genesis lint protobuf test publish-cmds build-docker-cli build-docker-cli-dev
.PHONY: build build-docker publish publish-docker-prod publish-docker-unstable test e2e dep lint build-tools protobuf changelog clean dev dev-mon

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

all: clean lint build test e2e
# Build

check-version:
ifndef version
$(error version is undefined)
endif
build: dep
./scripts/build-cli.sh "$(version)"

docker-build: check-version
build-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 \
--build-arg version=$(version) \
-t mesg/engine:$(version) \
.
docker build \
-f ./Dockerfile.dev \
--build-arg from=mesg/engine:$(version) \
-t mesg/engine:$(version)-dev \
.

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

docker-publish: docker-build
docker push mesg/engine:$(MAJOR_VERSION)
docker push mesg/engine:$(MINOR_VERSION)
docker push mesg/engine:$(PATCH_VERSION)
docker push mesg/engine:latest
# Publish

docker-publish-dev: check-version
docker build -t mesg/engine:dev --build-arg version=$(version) .
docker push mesg/engine:dev
publish: build
./scripts/publish-cli.sh "$(version)" "$(release-type)"

docker-tools:
docker build -t mesg/tools:local -f Dockerfile.tools .
publish-docker-prod: build-docker
docker tag mesg/engine:$(version) mesg/engine:$(MINOR_VERSION)
docker tag mesg/engine:$(version) mesg/engine:$(MAJOR_VERSION)
docker tag mesg/engine:$(version) mesg/engine:latest

dev: docker-dev
- ./scripts/dev.sh
docker push mesg/engine:$(version)
docker push mesg/engine:$(MINOR_VERSION)
docker push mesg/engine:$(MAJOR_VERSION)
docker push mesg/engine:latest

dev-mon: docker-dev
- ./scripts/dev.sh -m
docker tag mesg/engine:$(version)-dev mesg/engine:$(MINOR_VERSION)-dev
docker tag mesg/engine:$(version)-dev mesg/engine:$(MAJOR_VERSION)-dev
docker tag mesg/engine:$(version)-dev mesg/engine:latest-dev

dev-start: docker-dev
./scripts/dev.sh -q
docker push mesg/engine:$(version)-dev
docker push mesg/engine:$(MINOR_VERSION)-dev
docker push mesg/engine:$(MAJOR_VERSION)-dev
docker push mesg/engine:latest-dev

dev-stop: docker-dev
./scripts/dev.sh -m stop
publish-docker-unstable: build-docker
docker tag mesg/engine:$(version) mesg/engine:unstable
docker push mesg/engine:unstable

dep:
go mod download
docker tag mesg/engine:$(version)-dev mesg/engine:unstable-dev
docker push mesg/engine:unstable-dev

build: check-version dep
go build -mod=readonly -o ./bin/engine -ldflags="-X 'github.com/mesg-foundation/engine/version.Version=$(version)'" core/main.go
# Test

publish-cmds: check-version dep
./scripts/publish-cmds.sh "$(version)" "$(release-type)"
test: dep
go test -short -mod=readonly -v -coverprofile=coverage.txt ./...

build-cmd: dep
go build -mod=readonly -o ./bin/mesg-cli ./cmd/mesg-cli/
go build -mod=readonly -o ./bin/mesg-daemon ./cmd/mesg-daemon/
e2e: build-docker
./scripts/run-e2e.sh "$(version)"

build-docker-cli: check-version
docker build -t mesg/engine:cli -f ./Dockerfile.cli --build-arg version=$(version) .
dev: build-docker
./scripts/dev.sh "$(version)"

build-docker-cli-dev: build-docker-cli
docker build -t mesg/engine:cli-dev -f ./Dockerfile.cli.dev --build-arg from=mesg/engine:cli .
dev-mon: build-docker
./scripts/dev.sh "$(version)" "monitoring"

e2e: build-docker-cli-dev
./scripts/run-e2e.sh
# MISC

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

lint:
golangci-lint run
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.21 golangci-lint run

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

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

changelog:
./scripts/changelog.sh $(milestone)

clean-build:
clean:
- rm -rf bin

clean-docker:
- docker image rm \
mesg/engine:$(version) \
mesg/engine:latest \
mesg/engine:local \
mesg/engine:dev 2>/dev/null

clean: clean-build clean-docker

genesis:
go run internal/tools/gen-genesis/main.go --path $(path) --chain-id $(chain-id) --validators $(validators)
- docker image rm $(docker images | grep 'mesg')
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
github.com/huandu/xstrings v1.2.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/morikuni/aec v1.0.0 // indirect
github.com/mr-tron/base58 v1.1.3
github.com/mwitkow/go-proto-validators v0.0.0-20190212092829-1f388280e944 // indirect
Expand All @@ -55,7 +54,6 @@ require (
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect
google.golang.org/grpc v1.29.1
gopkg.in/yaml.v2 v2.2.8
gotest.tools v2.2.0+incompatible // indirect
)

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

if [[ -z "$1" ]]; then
echo -e "version is not set, run:\n"
echo "$0 vX.X.X"
exit 1
fi

LDFLAGS="-s -w -X 'github.com/cosmos/cosmos-sdk/version.Name=mesg' -X 'github.com/cosmos/cosmos-sdk/version.ServerName=mesg-daemon' -X 'github.com/cosmos/cosmos-sdk/version.ClientName=mesg-cli' -X 'github.com/cosmos/cosmos-sdk/version.Version=$1'"
oss=(linux darwin)
archs=(amd64 386)

for os in ${oss[*]}; do
for arch in ${archs[*]}; do
echo "Building $os $arch..."
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -mod=readonly -o "./bin/mesg-daemon-$os-$arch" -ldflags="$LDFLAGS" ./cmd/mesg-daemon/
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -mod=readonly -o "./bin/mesg-cli-$os-$arch" -ldflags="$LDFLAGS" ./cmd/mesg-cli/
done
done
Loading

0 comments on commit 4760af0

Please sign in to comment.