From 51c43d6dbdf71e277da67bf618a71fe304aae372 Mon Sep 17 00:00:00 2001 From: Fuyao Zhao Date: Mon, 8 Sep 2025 22:26:20 +0800 Subject: [PATCH] Create a docker release github action (#54) * create docker release action * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . --- .github/workflows/docker.yml | 37 +++++++++++++++++++++++++ Makefile | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..f4c58b818 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,37 @@ +# Publishes the Docker image. + +name: docker + +on: + push: + tags: + - v* + +env: + IMAGE_NAME: ${{ github.repository_owner }}/nanoreth + CARGO_TERM_COLOR: always + DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/nanoreth + DOCKER_USERNAME: ${{ github.actor }} + +jobs: + build: + name: build and push as latest + runs-on: ubuntu-24.04 + permissions: + packages: write + contents: read + steps: + - uses: actions/checkout@v5 + - uses: rui314/setup-mold@v1 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + - name: Log in to Docker + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io --username ${DOCKER_USERNAME} --password-stdin + - name: Set up Docker builder + run: | + docker buildx create --use --name builder + - name: Build and push nanoreth image + run: make IMAGE_NAME=$IMAGE_NAME DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME PROFILE=maxperf docker-build-push-latest \ No newline at end of file diff --git a/Makefile b/Makefile index e67aa711e..a02040c31 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ # Modifed from reth Makefile .DEFAULT_GOAL := help +GIT_SHA ?= $(shell git rev-parse HEAD) +GIT_TAG ?= $(shell git describe --tags --abbrev=0 2>/dev/null) BIN_DIR = "dist/bin" # List of features to use when building. Can be overridden via the environment. @@ -17,6 +19,9 @@ PROFILE ?= release # Extra flags for Cargo CARGO_INSTALL_EXTRA_FLAGS ?= +# The docker image name +DOCKER_IMAGE_NAME ?= ghcr.io/hl-archive-node/nanoreth + ##@ Help .PHONY: help @@ -207,3 +212,50 @@ check-features: --package reth-primitives-traits \ --package reth-primitives \ --feature-powerset + +##@ Docker + +# Note: This requires a buildx builder with emulation support. For example: +# +# `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` +# `docker buildx create --use --driver docker-container --name cross-builder` +.PHONY: docker-build-push +docker-build-push: ## Build and push a cross-arch Docker image tagged with the latest git tag. + $(call docker_build_push,$(GIT_TAG),$(GIT_TAG)) + +# Note: This requires a buildx builder with emulation support. For example: +# +# `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` +# `docker buildx create --use --driver docker-container --name cross-builder` +.PHONY: docker-build-push-git-sha +docker-build-push-git-sha: ## Build and push a cross-arch Docker image tagged with the latest git sha. + $(call docker_build_push,$(GIT_SHA),$(GIT_SHA)) + +# Note: This requires a buildx builder with emulation support. For example: +# +# `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` +# `docker buildx create --use --driver docker-container --name cross-builder` +.PHONY: docker-build-push-latest +docker-build-push-latest: ## Build and push a cross-arch Docker image tagged with the latest git tag and `latest`. + $(call docker_build_push,$(GIT_TAG),latest) + +# Note: This requires a buildx builder with emulation support. For example: +# +# `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` +# `docker buildx create --use --name cross-builder` +.PHONY: docker-build-push-nightly +docker-build-push-nightly: ## Build and push cross-arch Docker image tagged with the latest git tag with a `-nightly` suffix, and `latest-nightly`. + $(call docker_build_push,nightly,nightly) + +# Create a Docker image using the main Dockerfile +define docker_build_push + docker buildx build --file ./Dockerfile . \ + --platform linux/amd64 \ + --tag $(DOCKER_IMAGE_NAME):$(1) \ + --tag $(DOCKER_IMAGE_NAME):$(2) \ + --build-arg BUILD_PROFILE="$(PROFILE)" \ + --build-arg FEATURES="jemalloc,asm-keccak" \ + --build-arg RUSTFLAGS="-C target-cpu=native" \ + --provenance=false \ + --push +endef