ci: add docker release workflow (#2985)

This commit is contained in:
Bjerg
2023-06-05 19:22:31 +02:00
committed by GitHub
parent e1148c81a7
commit 643b3811c2
3 changed files with 96 additions and 1 deletions

44
.github/workflows/docker.yml vendored Normal file
View File

@ -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
Dockerfile.cross Normal file
View File

@ -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"]

View File

@ -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