Skip to content

Commit

Permalink
add Dockerfile.cross
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa committed Jan 2, 2025
1 parent c4ad4e8 commit b173e6f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,5 @@ jobs:
echo "TAGS -> ${{ steps.docker_tagging.outputs.docker_tags }}"
echo "LABELS -> ${{ steps.meta.outputs.labels }}"
- 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 reth image, tag as "latest"
run: make DOCKER_IMAGE_NAME=${{ steps.docker_tagging.outputs.docker_tags }} PROFILE=maxperf docker-build-push
21 changes: 21 additions & 0 deletions Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This image is meant to enable cross-architecture builds.
# It assumes the foundry binaries have already been compiled for `$TARGETPLATFORM` and are
# locatable in `./dist/bin/$TARGETARCH`
FROM ubuntu:22.04

# Filled by docker buildx
ARG TARGETARCH

COPY ./dist/bin/$TARGETARCH/* /usr/local/bin/

ENTRYPOINT ["/bin/sh", "-c"]

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="Foundry" \
org.label-schema.description="Foundry" \
org.label-schema.url="https://getfoundry.sh" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/foundry-rs/foundry.git" \
org.label-schema.vendor="Foundry-rs" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0"
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
PROFILE ?= dev
# The docker image name
DOCKER_IMAGE_NAME ?= ghcr.io/foundry-rs/foundry:latest
BIN_DIR = dist/bin
CARGO_TARGET_DIR ?= target

# List of features to use when building. Can be overridden via the environment.
# No jemalloc on Windows
Expand Down Expand Up @@ -40,26 +42,31 @@ build: ## Build the project.
build-%:
cross build --target $* --features "$(FEATURES)" --profile "$(PROFILE)"

# 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 DOCKER_IMAGE_NAME.
docker-build-push: docker-build-prepare ## Build and push a cross-arch Docker image tagged with DOCKER_IMAGE_NAME.
$(MAKE) build-x86_64-unknown-linux-gnu
mkdir -p $(BIN_DIR)/amd64
cp $(CARGO_TARGET_DIR)/x86_64-unknown-linux-gnu/$(PROFILE)/{anvil,cast,chisel,forge} $(BIN_DIR)/amd64/
for bin in anvil cast chisel forge; do \
cp $(CARGO_TARGET_DIR)/x86_64-unknown-linux-gnu/$(PROFILE)/$$bin $(BIN_DIR)/amd64/; \
done

$(MAKE) build-aarch64-unknown-linux-gnu
mkdir -p $(BIN_DIR)/arm64
cp $(CARGO_TARGET_DIR)/aarch64-unknown-linux-gnu/$(PROFILE)/{anvil,cast,chisel,forge} $(BIN_DIR)/arm64/
for bin in anvil cast chisel forge; do \
cp $(CARGO_TARGET_DIR)/aarch64-unknown-linux-gnu/$(PROFILE)/$$bin $(BIN_DIR)/arm64/; \
done

docker buildx build --file ./Dockerfile.cross . \
--platform linux/amd64,linux/arm64 \
$(foreach tag,$(subst $(comma), ,$(DOCKER_IMAGE_NAME)),--tag $(tag)) \
$(foreach tag,$(shell echo $(DOCKER_IMAGE_NAME) | tr ',' ' '),--tag $(tag))
--provenance=false \
--push

.PHONY: docker-build-prepare
docker-build-prepare: ## Prepare the Docker build environment.
docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64
docker buildx create --use --driver docker-container --name cross-builder

##@ Other

.PHONY: clean
Expand Down

0 comments on commit b173e6f

Please sign in to comment.