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

build: rearrange Dockerfile and Makefile commands #237

Merged
merged 11 commits into from
Jul 18, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (ci) [\#185](https://github.com/Finschia/finschia/pull/185) update `tag.yml` github action
* (ci) [\#189](https://github.com/Finschia/finschia/pull/189) add dependabot github action
* (ci) [\#213](https://github.com/Finschia/finschia/pull/213) add mergify ci
* (build) [\#237](https://github.com/Finschia/finschia/pull/237) rearrange Dockerfile and Makefile commands

### Docs

Expand Down
60 changes: 7 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
OST_VERSION := $(shell go list -m github.com/Finschia/ostracon | sed 's:.* ::') # grab everything after the space in "github.com/Finschia/ostracon v0.34.7"
DOCKER := $(shell which docker)
BUILDDIR ?= $(CURDIR)/build
TEST_DOCKER_REPO=jackzampolin/linktest
CGO_ENABLED ?= 1
ARCH ?= x86_64
TARGET_PLATFORM ?= linux/amd64
Expand Down Expand Up @@ -149,10 +148,6 @@ else
endif
endif

#$(info $$BUILD_FLAGS is [$(BUILD_FLAGS)])

# The below include contains the tools target.
include contrib/devtools/Makefile

###############################################################################
### Documentation ###
Expand All @@ -165,29 +160,6 @@ build: BUILD_ARGS=-o $(BUILDDIR)/
build: go.sum $(BUILDDIR)/ dbbackend $(LIBSODIUM_TARGET)
CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_ENABLED=$(CGO_ENABLED) go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

# USAGE: go env -w GOARCH={amd64|arm64} && make clean build-release-bundle VERSION=v0.0.0
RELEASE_BUNDLE=finschia-$(VERSION)-$(shell go env GOOS)-$(shell go env GOARCH)
LIBWASMVM_VERSION=$(shell go list -m github.com/Finschia/wasmvm | awk '{print $$2}')
LIBWASMVM_PATH=$(shell find $(shell go env GOMODCACHE) -name $(LIBWASMVM) -type f | grep "$(LIBWASMVM_VERSION)")
build-release-bundle: build
@if [ "$(shell go env GOOS)" != "$(shell go env GOHOSTOS)" ]; then echo "ERROR: OS not match"; exit 1; fi
@if [ -z "${LIBWASMVM_PATH}" ]; then echo "ERROR: $(LIBWASMVM) $(LIBWASMVM_VERSION) not found: $(shell go env GOMODCACHE)"; exit 1; fi
@if [ ! -f "${LIBWASMVM_PATH}" ]; then echo "ERROR: Multiple version of $(LIBWASMVM) found: ${LIBWASMVM_PATH}"; exit 1; fi
@mkdir -p $(BUILDDIR)/$(RELEASE_BUNDLE)
@cp $(BUILDDIR)/fnsad $(BUILDDIR)/$(RELEASE_BUNDLE)/$(RELEASE_BUNDLE)
@cp "$(LIBWASMVM_PATH)" $(BUILDDIR)/$(RELEASE_BUNDLE)/
@case "$(shell go env GOHOSTOS),$(shell go env GOHOSTARCH),$(shell go env GOARCH)" in \
*,amd64,amd64 | *,arm64,arm64 | darwin,arm64,*) \
LD_LIBRARY_PATH=$(BUILDDIR)/$(RELEASE_BUNDLE) $(BUILDDIR)/$(RELEASE_BUNDLE)/$(RELEASE_BUNDLE) version; \
if [ $$? -ne 0 ]; then echo "ERROR: Test execution failed."; printenv; go env; exit 1; fi; \
echo "OK: Test execution confirmed.";; \
*) \
echo "SKIP: Test execution unconfirmed.";; \
esac
@cd $(BUILDDIR) && tar zcvf ./$(RELEASE_BUNDLE).tgz $(RELEASE_BUNDLE)/ > /dev/null 2>&1
@rm -rf $(BUILDDIR)/$(RELEASE_BUNDLE)/
@echo "Built: $(BUILDDIR)/$(RELEASE_BUNDLE).tgz"

install: go.sum $(BUILDDIR)/ dbbackend $(LIBSODIUM_TARGET)
CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) $(BUILD_ARGS) ./cmd/fnsad

Expand Down Expand Up @@ -270,11 +242,6 @@ build-reproducible-arm64: go.sum
$(DOCKER) cp finschiabinary:/usr/bin/fnsad $(BUILDDIR)/fnsad-linux-arm64
$(DOCKER) rm -f finschiabinary


build-contract-tests-hooks:
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/ ./cmd/contract_tests

go-mod-cache: go.sum
@echo "--> Download go modules to local cache"
@go mod download
Expand Down Expand Up @@ -328,7 +295,7 @@ sync-docs:

include sims.mk

test: test-unit test-build
test: test-unit

test-all: test-race test-cover

Expand Down Expand Up @@ -368,6 +335,7 @@ docker-build:
--build-arg OST_VERSION=$(OST_VERSION) \
--platform=$(TARGET_PLATFORM) \
-f Dockerfile .
.PHONY: docker-build

###############################################################################
### Linting ###
Expand All @@ -386,9 +354,6 @@ format:
### Localnet ###
###############################################################################

build-docker-finschianode:
$(MAKE) -C networks/local

localnet-docker-build:
@DOCKER_BUILDKIT=1 docker build \
-t finschia/finschianode:localnet \
Expand All @@ -398,7 +363,7 @@ localnet-docker-build:
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg OST_VERSION=$(OST_VERSION) \
--platform=$(TARGET_PLATFORM) \
-f builders/Dockerfile.static .
-f networks/local/finschianode/Dockerfile .

# Run a 4-node testnet locally
localnet-start: localnet-stop localnet-docker-build localnet-build-nodes
Expand All @@ -412,23 +377,11 @@ localnet-build-nodes:
localnet-stop:
docker-compose down

test-docker:
@docker build -f contrib/Dockerfile.test -t ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) .
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:latest

test-docker-push: test-docker
@docker push ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD)
@docker push ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker push ${TEST_DOCKER_REPO}:latest

.PHONY: all install format lint \
go-mod-cache draw-deps clean build \
setup-transactions setup-contract-tests-data start-link run-lcd-contract-tests contract-tests \
test test-all test-build test-cover test-unit test-race \
test test-all test-cover test-unit test-race \
benchmark \
build-docker-finschianode localnet-start localnet-stop \
docker-single-node
localnet-start localnet-stop

###############################################################################
### tools ###
Expand Down Expand Up @@ -461,4 +414,5 @@ libsodium:
proto-swagger-gen:
@echo "Generating Protobuf Swagger"
./scripts/generate-docs.sh
$(GOPATH)/bin/statik -src=client/docs/swagger-ui -dest=client/docs -f -m
statik -src=client/docs/swagger-ui -dest=client/docs -f -m
.PHONY: proto-swagger-gen
79 changes: 0 additions & 79 deletions builders/Dockerfile.static

This file was deleted.

64 changes: 0 additions & 64 deletions builders/Dockerfile.static_centos7

This file was deleted.

35 changes: 0 additions & 35 deletions contrib/Dockerfile.test

This file was deleted.

Loading