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

Docker updates to build and run #696

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c0bf024
Changes to simplify first time setup and docker usage
franklywatson Dec 5, 2024
bfab77e
Not needed
franklywatson Dec 5, 2024
3b517a0
Enable override
franklywatson Dec 5, 2024
d82dd34
Variable use consistency
franklywatson Dec 5, 2024
8d63c9f
nit
franklywatson Dec 5, 2024
968f54a
Correct image name
franklywatson Dec 5, 2024
1eeb2bf
Detach container by default
franklywatson Dec 5, 2024
dfb48e3
Update README
franklywatson Dec 6, 2024
21ab682
Split guidance into two lines
franklywatson Dec 6, 2024
334a45f
Account for change made in Dockerfile to add $VERSION
franklywatson Dec 7, 2024
0679ffc
Improve usability and code
franklywatson Dec 7, 2024
3d0973f
Tidyup
franklywatson Dec 7, 2024
40b24a1
Fix mount issue
franklywatson Dec 7, 2024
aa76d88
Fix mount issue
franklywatson Dec 7, 2024
46bbe75
Fix mount issue
franklywatson Dec 7, 2024
61b0977
More troubleshooting mount
franklywatson Dec 7, 2024
a2d1792
More troubleshooting mount
franklywatson Dec 7, 2024
ea3e5cd
Fix for mount
franklywatson Dec 7, 2024
dc9daf2
Fix for mount
franklywatson Dec 7, 2024
7082eec
Resolved mount issue
franklywatson Dec 7, 2024
fdad063
Resolved mount issue
franklywatson Dec 7, 2024
b0207f1
Fix port access from other sources
franklywatson Dec 7, 2024
7e6c63e
Minimize heavy logging
franklywatson Dec 7, 2024
a8fbdde
WIP updates to README
franklywatson Dec 8, 2024
c52d874
Additions for local docker build docker pull version
franklywatson Dec 8, 2024
03718df
No caching when local build
franklywatson Dec 8, 2024
29bebe3
Couple of changes to test local build
franklywatson Dec 8, 2024
1cc6775
Last tweaks and add redirect to main docs
franklywatson Dec 8, 2024
eb68bfa
Nits and remove traces-gcp-bucket config from options
franklywatson Dec 9, 2024
839e5d3
Added missing metrics-port config
franklywatson Dec 9, 2024
d82f71e
remove dupe
franklywatson Dec 9, 2024
d5b4c75
Fix docker-build-local and docker-run-local targets
franklywatson Dec 9, 2024
756a31b
Handle missing GOARCH for macs
franklywatson Dec 9, 2024
6188ee1
Add OS specific flags to go build
franklywatson Dec 9, 2024
76989f8
Enable GOARCH override if ENV var set
franklywatson Dec 10, 2024
3ed2b21
Support GAS_PRICE configuration and default amount
franklywatson Dec 10, 2024
36afe82
Fixed to make docker-run-local work
franklywatson Dec 10, 2024
9ec01a8
Open access to the right port for emulator
franklywatson Dec 10, 2024
a428439
Revert incorrect config
franklywatson Dec 10, 2024
8a515a3
Simplify variable assignment
franklywatson Dec 10, 2024
9df4d7d
Fix broken make targets for local compilation
franklywatson Dec 10, 2024
3cbe37c
Merge remote-tracking branch 'origin/jp/docker-fixes' into jp/docker-…
franklywatson Dec 10, 2024
ade4766
Fix missing compiler arg for Mac
franklywatson Dec 10, 2024
2425298
Remove duplicate variable setting and add ARCH flag
franklywatson Dec 10, 2024
a5a688d
Remove duplicate entries
franklywatson Dec 10, 2024
b5d6462
Specify host.docker.internal:3569 explicitly for the docker-run-local…
franklywatson Dec 10, 2024
1b2d9a1
Fix emulator startup warning message
franklywatson Dec 10, 2024
272ef11
Not needed
franklywatson Dec 11, 2024
56867b8
Image update to highlight cadence transaction arrow
franklywatson Dec 11, 2024
69770c9
Kill background emulator process before restart
franklywatson Dec 11, 2024
874be8a
Merged changes from feature/local-tx-reexecution branch
franklywatson Dec 11, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ jobs:
- name: Docker Auth
run: |-
gcloud auth configure-docker ${{ vars.GAR_LOCATION }}-docker.pkg.dev
docker build -t ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }} --build-arg GATEWAY_VERSION=${{ steps.set_version.outputs.GATEWAY_VERSION }} --file Dockerfile .
docker build --build-arg VERSION="${{ steps.set_version.outputs.GATEWAY_VERSION }}" --build-arg ARCH=amd64 -t ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }} --file Dockerfile .
docker push ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ tests/e2e-network/node_modules
tests/e2e-network/package-lock.json
db
flow.json
flow*.json
.idea
metrics/data/
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

FROM golang:1.22.0 as app-builder

ARG GATEWAY_VERSION="v0.1.0"

# Build the app binary in /app
WORKDIR /app

Expand All @@ -14,8 +12,11 @@ COPY . ./
RUN go mod download
RUN go mod verify

ARG VERSION
ARG ARCH

# Build binary
RUN CGO_ENABLED=1 go build -o bin -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=${GATEWAY_VERSION}" cmd/main.go
RUN CGO_ENABLED=1 GOOS=linux GOARCH=$ARCH build -o bin -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=$VERSION" -trimpath cmd/main.go
RUN chmod a+x bin

# RUN APP
Expand Down
174 changes: 150 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
# The short Git commit hash
SHORT_COMMIT := $(shell git rev-parse --short HEAD)
BRANCH_NAME:=$(shell git rev-parse --abbrev-ref HEAD | tr '/' '-')
# The Git commit hash
COMMIT := $(shell git rev-parse HEAD)
# The tag of the current commit, otherwise empty
GIT_VERSION := $(shell git describe --tags --abbrev=2 2>/dev/null)
franklywatson marked this conversation as resolved.
Show resolved Hide resolved
CMD_ARGS :=
# ACCESS_NODE_SPORK_HOSTS are comma separated
ACCESS_NODE_SPORK_HOSTS := access-001.devnet51.nodes.onflow.org:9000
EMULATOR_COINBASE := FACF71692421039876a5BB4F10EF7A439D8ef61E
EMULATOR_COA_ADDRESS := f8d6e0586b0a20c7
EMULATOR_COA_KEY := 2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21
franklywatson marked this conversation as resolved.
Show resolved Hide resolved
UNAME_S := $(shell uname -s)
# Set default values
ARCH :=
OS :=
COMPILER_FLAGS := CGO_ENABLED=1

EMULATOR_ARGS := --flow-network-id=flow-emulator \
--coinbase=$(EMULATOR_COINBASE) \
--coa-address=$(EMULATOR_COA_ADDRESS) \
--coa-key=$(EMULATOR_COA_KEY) \
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--gas-price=0 \
--log-writer=console \
--profiler-enabled=true \
--profiler-port=6060
franklywatson marked this conversation as resolved.
Show resolved Hide resolved

# Set VERSION from command line, environment, or default to SHORT_COMMIT
VERSION ?= ${SHORT_COMMIT}

# Set IMAGE_TAG from VERSION if not explicitly set
IMAGE_TAG ?= ${VERSION}
franklywatson marked this conversation as resolved.
Show resolved Hide resolved

# Function to check and append required arguments
define check_and_append
$(if $($(2)),\
$(eval CMD_ARGS += --$(1)=$($(2))),\
$(error ERROR: $(2) ENV variable is required))
endef

# Determine OS and set ARCH
ifeq ($(UNAME_S),Darwin)
OS := macos
ARCH := arm64
$(eval COMPILER_FLAGS += CGO_CFLAGS="-O2 -D__BLST_PORTABLE__")
else ifeq ($(UNAME_S),Linux)
OS := linux
ARCH := amd64
else
$(error Unsupported operating system: $(UNAME_S))
endif

# docker container registry
export CONTAINER_REGISTRY := us-west1-docker.pkg.dev/dl-flow-devex-production/development
export DOCKER_BUILDKIT := 1
franklywatson marked this conversation as resolved.
Show resolved Hide resolved
export DATADIR := /data

.PHONY: test
test:
# test all packages
Expand All @@ -20,7 +79,7 @@ check-tidy:

.PHONY: build
build:
CGO_ENABLED=1 go build -o flow-evm-gateway -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=$(shell git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" cmd/main.go
$(COMPILER_FLAGS) go build -o flow-evm-gateway -ldflags="-X github.com/onflow/flow-evm-gateway/api.Version=$(IMAGE_TAG)" cmd/main.go
chmod a+x flow-evm-gateway

.PHONY: fix-lint
Expand All @@ -44,37 +103,104 @@ ci: check-tidy test e2e-test

.PHONY: start
start:
go run ./cmd/server/main.go
$(COMPILER_FLAGS) go run ./cmd/main.go

.PHONY: start-local
start-local:
rm -rf db/
rm -rf metrics/data/
go run cmd/main.go run \
--flow-network-id=flow-emulator \
--coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \
--coa-address=f8d6e0586b0a20c7 \
--coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--coa-resource-create=true \
--gas-price=0 \
--log-writer=console \
--profiler-enabled=true \
--profiler-port=6060
$(COMPILER_FLAGS) go run cmd/main.go run $(EMULATOR_ARGS)
franklywatson marked this conversation as resolved.
Show resolved Hide resolved

# Use this after running `make build`, to test out the binary
.PHONY: start-local-bin
start-local-bin:
rm -rf db/
rm -rf metrics/data/
./flow-evm-gateway run \
--flow-network-id=flow-emulator \
--coinbase=FACF71692421039876a5BB4F10EF7A439D8ef61E \
--coa-address=f8d6e0586b0a20c7 \
--coa-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--wallet-api-key=2619878f0e2ff438d17835c2a4561cb87b4d24d72d12ec34569acd0dd4af7c21 \
--coa-resource-create=true \
--gas-price=0 \
--log-writer=console \
--profiler-enabled=true \
--profiler-port=6060
$(COMPILER_FLAGS) go run cmd/main.go run $(EMULATOR_ARGS)

# Build docker image from local sources
.PHONY: docker-build-local
docker-build-local:
ifdef GOARCH
$(eval ARCH=$(GOARCH))
endif
docker build --build-arg ARCH=$(ARCH) --no-cache -f dev/Dockerfile -t "$(CONTAINER_REGISTRY)/evm-gateway:$(COMMIT)" .

# Docker run for local development
.PHONY: docker-run-local
docker-run-local:
flow emulator &
sleep 3

$(call check_and_append,coinbase,EMULATOR_COINBASE)
$(call check_and_append,coa-address,EMULATOR_COA_ADDRESS)
$(call check_and_append,coa-key,EMULATOR_COA_KEY)

$(eval CMD_ARGS += --flow-network-id=flow-emulator --log-level=debug --gas-price=0 --log-writer=console --profiler-enabled=true --access-node-grpc-host=host.docker.internal:3569)

docker run -p 8545:8545 --add-host=host.docker.internal:host-gateway "$(CONTAINER_REGISTRY)/evm-gateway:$(COMMIT)" $(CMD_ARGS)


# Build docker image for release
.PHONY: docker-build
docker-build:
ifdef GOARCH
$(eval ARCH=$(GOARCH))
endif
docker build --build-arg VERSION="$(VERSION)" --build-arg ARCH=$(ARCH) -f Dockerfile -t "$(CONTAINER_REGISTRY)/evm-gateway:$(IMAGE_TAG)" \
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vishalchangrani - let me know what should be done for tags - i copied what we do for other Flow nodes, but not sure that is what you need

--label "git_commit=$(COMMIT)" --label "git_tag=$(IMAGE_TAG)" .

# Install image version from container registry
.PHONY: docker-pull-version
docker-pull-version:
docker pull "$(CONTAINER_REGISTRY)/evm-gateway:$(IMAGE_VERSION)"

# Run GW image
# https://github.com/onflow/flow-evm-gateway?tab=readme-ov-file#configuration-flags
# Requires the following ENV variables:
# - ACCESS_NODE_GRPC_HOST: [access.devnet.nodes.onflow.org:9000 | access.mainnet.nodes.onflow.org:9000]
# - FLOW_NETWORK_ID: [flow-testnet, flow-mainnet]
# - INIT_CADENCE_HEIGHT: [testnet: 211176670, mainnet: 88226267]
# - COINBASE: To be set by the operator. This is an EVM EOA or COA address which is set as the receiver of GW transaction fees (remove 0x prefix)
# - COA_ADDRESS: To be set by the operator. This is a Cadence address which funds gateway operations (remove 0x prefix)
# - COA_KEY: A full weight, private key belonging to operator COA_ADDRESS (remove 0x prefix). NB: For development use only. We recommend using cloud KMS configuration on mainnet
#
# Optional
# - GAS_PRICE: the attoFlow amount
#
# Optional make arguments:
# - DOCKER_RUN_DETACHED: Runs container in detached mode when true
# - DOCKER_HOST_PORT: Sets the exposed container port for the gateway JSON-RPC
# - DOCKER_MOUNT: Sets the host mount point for the EVM data dir
.PHONY: docker-run
docker-run:
$(eval CMD_ARGS :=)
ifdef DOCKER_RUN_DETACHED
$(eval MODE=-d)
endif
ifdef DOCKER_HOST_PORT
$(eval HOST_PORT=$(DOCKER_HOST_PORT))
else
$(eval HOST_PORT=8545)
endif
ifndef GAS_PRICE
$(eval GAS_PRICE=100)
endif
ifdef DOCKER_MOUNT
$(eval MOUNT=--mount type=bind,src="$(DOCKER_MOUNT)",target=$(DATADIR))
$(call check_and_append,database-dir,DATADIR)
endif

$(call check_and_append,access-node-grpc-host,ACCESS_NODE_GRPC_HOST)
$(call check_and_append,flow-network-id,FLOW_NETWORK_ID)
$(call check_and_append,init-cadence-height,INIT_CADENCE_HEIGHT)
$(call check_and_append,coinbase,COINBASE)
$(call check_and_append,coa-address,COA_ADDRESS)
$(call check_and_append,coa-key,COA_KEY)
$(call check_and_append,gas-price,GAS_PRICE)

$(eval CMD_ARGS += --ws-enabled=true --rate-limit=9999999 --rpc-host=0.0.0.0 --log-level=info)
$(call check_and_append,access-node-spork-hosts,ACCESS_NODE_SPORK_HOSTS)

docker run $(MODE) -p $(HOST_PORT):8545 -p 8080:8080 $(MOUNT) "$(CONTAINER_REGISTRY)/evm-gateway:$(IMAGE_TAG)" $(CMD_ARGS)

Loading
Loading