From 643b3811c2ee6c9fdaa8d20459c393fb08ce2b04 Mon Sep 17 00:00:00 2001 From: Bjerg Date: Mon, 5 Jun 2023 19:22:31 +0200 Subject: [PATCH] ci: add docker release workflow (#2985) --- .github/workflows/docker.yml | 44 ++++++++++++++++++++++++++++++++++++ Dockerfile.cross | 12 ++++++++++ Makefile | 41 ++++++++++++++++++++++++++++++++- 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile.cross diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000000..bb3809dc19 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,44 @@ +name: docker + +on: + push: + tags: + - v* + +env: + REPO_NAME: ${{ github.repository_owner }}/reth + IMAGE_NAME: ${{ github.repository_owner }}/reth + RUSTFLAGS: -D warnings + CARGO_TERM_COLOR: always + DOCKER_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/reth + DOCKER_USERNAME: ${{ github.actor }} + +jobs: + build: + name: build and push + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Get latest version of stable Rust + run: rustup update 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 run --privileged --rm tonistiigi/binfmt --install arm64,amd64 + docker buildx create --use --name cross-builder + + - name: Build and push image + run: | + cargo install cross + env PROFILE=maxperf make docker-build-latest diff --git a/Dockerfile.cross b/Dockerfile.cross new file mode 100644 index 0000000000..1c34aa01f6 --- /dev/null +++ b/Dockerfile.cross @@ -0,0 +1,12 @@ +# This image is meant to enable cross-architecture builds. +# It assumes the reth binary has already been compiled for `$TARGETPLATFORM` and is +# locatable in `./dist/bin/$TARGETARCH` +FROM --platform=$TARGETPLATFORM ubuntu:22.04 + +# Filled by docker buildx +ARG TARGETARCH + +COPY ./dist/bin/$TARGETARCH/reth /usr/local/bin/reth + +EXPOSE 30303 30303/udp 9000 8545 8546 +ENTRYPOINT ["/usr/local/bin/reth", "node"] \ No newline at end of file diff --git a/Makefile b/Makefile index cea89a5aa7..69bb5482b2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Heavily inspired by Lighthouse: https://github.com/sigp/lighthouse/blob/693886b94176faa4cb450f024696cb69cda2fe58/Makefile -GIT_TAG := $(shell git describe --tags --candidates 1) +GIT_TAG := $(shell git describe --tags --abbrev=0) BIN_DIR = "dist/bin" BUILD_PATH = "target" @@ -24,6 +24,9 @@ EF_TESTS_TAG := v12.2 EF_TESTS_URL := https://github.com/ethereum/tests/archive/refs/tags/$(EF_TESTS_TAG).tar.gz EF_TESTS_DIR := ./testing/ef-tests/ethereum-tests +# The docker image name +DOCKER_IMAGE_NAME ?= ghcr.io/paradigmxyz/reth + # Builds and installs the reth binary. # # The binary will most likely be in `~/.cargo/bin` @@ -104,6 +107,42 @@ $(EF_TESTS_DIR): ef-tests: $(EF_TESTS_DIR) cargo nextest run -p ef-tests --features ef-tests +# Builds and pushes a cross-arch Docker image tagged with the latest git tag and `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 --driver docker-container --name cross-builder` +docker-build-latest: + $(call build_docker_image,$(GIT_TAG),latest) + +# Builds and pushes cross-arch Docker image tagged with the latest git tag with a `-nightly` suffix, and `latest-nightly` +# +# 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` +docker-build-nightly: + $(call build_docker_image,$(GIT_TAG)-nightly,latest-nightly) + +# Create a cross-arch Docker image with the given tags and push it +define build_docker_image + $(MAKE) build-x86_64-unknown-linux-gnu + mkdir -p $(BIN_DIR)/amd64 + cp $(BUILD_PATH)/x86_64-unknown-linux-gnu/$(PROFILE)/reth $(BIN_DIR)/amd64/reth + + $(MAKE) build-aarch64-unknown-linux-gnu + mkdir -p $(BIN_DIR)/arm64 + cp $(BUILD_PATH)/aarch64-unknown-linux-gnu/$(PROFILE)/reth $(BIN_DIR)/arm64/reth + + docker buildx build --file ./Dockerfile.cross . \ + --platform linux/amd64,linux/arm64 \ + --tag $(DOCKER_IMAGE_NAME):$(1) \ + --tag $(DOCKER_IMAGE_NAME):$(2) \ + --provenance=false \ + --push +endef + # Performs a `cargo` clean and removes the binary and test vectors directories clean: cargo clean