Skip to content

Commit

Permalink
ci: add docker release workflow (paradigmxyz#2985)
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg authored Jun 5, 2023
1 parent e1148c8 commit 643b381
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -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"]
41 changes: 40 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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`
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 643b381

Please sign in to comment.