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
Merged
2 changes: 1 addition & 1 deletion .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

- name: Compile finschia
run: |
make build-reproducible-${{ matrix.arch }}
make build-reproducible ARCH=${{ matrix.arch }}
cd ./build
mv fnsad-linux-${{ matrix.arch }} fnsad-${{ env.ID }}

Expand Down
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
99 changes: 17 additions & 82 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ 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
ARCH ?= amd64
TARGET_PLATFORM ?= linux/amd64
TARGET_ARCH ?= x86_64
0Tech marked this conversation as resolved.
Show resolved Hide resolved

export GO111MODULE = on

ifeq ($(ARCH), aarch64)
ifeq ($(ARCH), arm64)
TARGET_PLATFORM=linux/arm64
TARGET_ARCH = aarch64
endif

# process build tags
Expand Down Expand Up @@ -142,17 +143,13 @@ ifeq (darwin, $(shell go env GOOS))
LIBWASMVM ?= libwasmvm.dylib
else
ifeq (linux, $(shell go env GOOS))
LIBWASMVM ?= libwasmvm.$(ARCH).so
LIBWASMVM ?= libwasmvm.$(TARGET_ARCH).so
else
echo "ERROR: unsupported platform: $(shell go env GOOS)"
exit 1
endif
endif

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

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

###############################################################################
### Documentation ###
Expand All @@ -165,29 +162,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 @@ -230,9 +204,7 @@ else
dbbackend:
endif

build-reproducible: build-reproducible-amd64 build-reproducible-arm64

build-reproducible-amd64: go.sum
build-reproducible: go.sum
mkdir -p $(BUILDDIR)
$(DOCKER) buildx create --name finschiabuilder || true
$(DOCKER) buildx use finschiabuilder
Expand All @@ -242,39 +214,15 @@ build-reproducible-amd64: go.sum
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg OST_VERSION=$(OST_VERSION) \
--build-arg RUNNER_IMAGE=alpine:3.17 \
--platform linux/amd64 \
-t finschia/finschianode:local-amd64 \
--platform $(TARGET_PLATFORM) \
-t finschia/finschianode:local-$(ARCH) \
--load \
-f Dockerfile .
$(DOCKER) rm -f finschiabinary || true
$(DOCKER) create -ti --name finschiabinary finschia/finschianode:local-amd64
$(DOCKER) cp finschiabinary:/usr/bin/fnsad $(BUILDDIR)/fnsad-linux-amd64
$(DOCKER) create -ti --name finschiabinary finschia/finschianode:local-$(ARCH)
$(DOCKER) cp finschiabinary:/usr/bin/fnsad $(BUILDDIR)/fnsad-linux-$(ARCH)
$(DOCKER) rm -f finschiabinary

build-reproducible-arm64: go.sum
mkdir -p $(BUILDDIR)
$(DOCKER) buildx create --name finschiabuilder || true
$(DOCKER) buildx use finschiabuilder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg OST_VERSION=$(OST_VERSION) \
--build-arg RUNNER_IMAGE=alpine:3.17 \
--platform linux/arm64 \
-t finschia/finschianode:local-arm64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f finschiabinary || true
$(DOCKER) create -ti --name finschiabinary finschia/finschianode:local-arm64
$(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 +276,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 +316,7 @@ docker-build:
--build-arg OST_VERSION=$(OST_VERSION) \
--platform=$(TARGET_PLATFORM) \
-f Dockerfile .
.PHONY: docker-build

###############################################################################
### Linting ###
Expand All @@ -386,9 +335,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 +344,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 +358,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 +395,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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _Note1_

If you are using M1 mac, you need to specify build args like this:
```
make docker-build ARCH=aarch64
make docker-build ARCH=arm64
```

**Configure**
Expand Down
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.

Loading
Loading