From 879cf1b43e752fd374e70ff203d99d710b0d4d9b Mon Sep 17 00:00:00 2001 From: Akosh Farkash Date: Wed, 20 Dec 2023 13:43:32 +0000 Subject: [PATCH] FIX: Fix paths in docker builds (#491) * FIX: Fix paths in docker builds * CI: Why is the job skipped... * FIX: Remove .filter * FIX: Filter non-crates * BUILD: Enable binding build by default. Move source trigger to fendermint --- .dockerignore | 4 ++++ .github/workflows/ci.yaml | 18 +++++++++--------- contracts/.gitignore | 1 - contracts/Makefile | 4 +--- contracts/binding/build.rs | 7 ++++--- fendermint/.dockerignore | 2 -- fendermint/.gitignore | 1 + fendermint/Makefile | 18 +++++++++--------- fendermint/docker/builder.ci.Dockerfile | 14 +++++++------- fendermint/docker/builder.local.Dockerfile | 2 +- fendermint/docker/runner.Dockerfile | 4 ++-- 11 files changed, 38 insertions(+), 37 deletions(-) create mode 100644 .dockerignore delete mode 100644 fendermint/.dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..c340af7ad --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +target +fendermint/builtin-actors +contracts/cache +contracts/node-modules diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2e7c92f30..21a017b23 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -56,7 +56,7 @@ jobs: uses: ./.github/workflows/contracts-prettier.yaml needs: [changes] if: >- - needs.changes.filter.outputs.contracts == 'true' || + needs.changes.outputs.contracts == 'true' || github.ref == 'refs/heads/main' contracts-test: @@ -79,32 +79,32 @@ jobs: uses: ./.github/workflows/fvm-utils.yaml needs: [changes, license] if: >- - needs.changes.filter.outputs.fvm-utils == 'true' || + needs.changes.outputs.fvm-utils == 'true' || github.ref == 'refs/heads/main' ipc: uses: ./.github/workflows/ipc.yaml needs: [changes, license] if: >- - needs.changes.filter.outputs.contracts == 'true' || - needs.changes.filter.outputs.ipc == 'true' || + needs.changes.outputs.contracts == 'true' || + needs.changes.outputs.ipc == 'true' || github.ref == 'refs/heads/main' ipld-resolver: uses: ./.github/workflows/ipld-resolver.yaml needs: [changes, license] if: >- - needs.changes.filter.outputs.ipld-resolver == 'true' || + needs.changes.outputs.ipld-resolver == 'true' || github.ref == 'refs/heads/main' fendermint-test: uses: ./.github/workflows/fendermint-test.yaml needs: [changes, license] if: >- - needs.changes.filter.outputs.contracts == 'true' || - needs.changes.filter.outputs.ipc == 'true' || - needs.changes.filter.outputs.ipld-resolver == 'true' || - needs.changes.filter.outputs.fendermint == 'true' || + needs.changes.outputs.contracts == 'true' || + needs.changes.outputs.ipc == 'true' || + needs.changes.outputs.ipld-resolver == 'true' || + needs.changes.outputs.fendermint == 'true' || github.ref == 'refs/heads/main' fendermint-publish: diff --git a/contracts/.gitignore b/contracts/.gitignore index c50da589f..269cf7121 100644 --- a/contracts/.gitignore +++ b/contracts/.gitignore @@ -4,7 +4,6 @@ crytic-export/ .vscode .idea .env -.gen broadcast/ out/ diff --git a/contracts/Makefile b/contracts/Makefile index 70df3fcc7..0876fca80 100644 --- a/contracts/Makefile +++ b/contracts/Makefile @@ -7,8 +7,6 @@ NETWORK ?= auto # It is required by docker builds, but shouldn't be checked into git. OUTPUT ?= out -IPC_ACTORS_CODE := $(shell find . -type f \( -name "*.sol" \)) - deploy-ipc: ./ops/deploy.sh $(NETWORK) @@ -36,7 +34,7 @@ compile-abi: | forge ./ops/compile-abi.sh $(OUTPUT) rust-binding: - OUTPUT=$(OUTPUT) BUILD_BINDINGS=1 cargo build --locked --release --manifest-path ./binding/Cargo.toml -p ipc_actors_abis + OUTPUT=$(OUTPUT) cargo build --locked --release --manifest-path ./binding/Cargo.toml -p ipc_actors_abis # commit-abi: # ./ops/commit-abi.sh $(OUTPUT) diff --git a/contracts/binding/build.rs b/contracts/binding/build.rs index 7e2341b13..fb230b06f 100644 --- a/contracts/binding/build.rs +++ b/contracts/binding/build.rs @@ -11,13 +11,14 @@ use std::path::{Path, PathBuf}; fn main() { // Run with `cargo build -vv` to see output from any `eprintln!` or `println!`. - // We are not building anything, could be imported as crate. - if std::env::var("BUILD_BINDINGS").ok().is_none() { + // Maybe we want to skip the build and use the files as-is, could be imported as crate. + // Enabled by default so that in the monorepo we don't have to worry about stale code. + if std::env::var("BUILD_BINDINGS").unwrap_or("1".to_string()) == "0" { return; } // Where are the Solidity artifacts. - let output_dir = std::env::var("OUTPUT").expect("OUTPUT env var missing"); + let output_dir = std::env::var("OUTPUT").unwrap_or("out".to_string()); let ipc_actors_dir = workspace_dir() .join("contracts") diff --git a/fendermint/.dockerignore b/fendermint/.dockerignore deleted file mode 100644 index b86c612a2..000000000 --- a/fendermint/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -target -builtin-actors diff --git a/fendermint/.gitignore b/fendermint/.gitignore index d85e8734e..f2d32d68b 100644 --- a/fendermint/.gitignore +++ b/fendermint/.gitignore @@ -6,3 +6,4 @@ cometbft test-network .idea .make +.contracts-gen diff --git a/fendermint/Makefile b/fendermint/Makefile index 94d3fce68..a01cfdcb9 100644 --- a/fendermint/Makefile +++ b/fendermint/Makefile @@ -5,7 +5,8 @@ BUILTIN_ACTORS_BUNDLE := $(PWD)/builtin-actors/output/bundle.car IPC_ACTORS_DIR := $(PWD)/../contracts IPC_ACTORS_OUT := $(IPC_ACTORS_DIR)/out -IPC_ACTORS_GEN := $(IPC_ACTORS_DIR)/.gen +IPC_ACTORS_CODE := $(shell find $(IPC_ACTORS_DIR) -type f \( -name "*.sol" \)) +IPC_ACTORS_GEN := .contracts-gen FENDERMINT_CODE := $(shell find . -type f \( -name "*.rs" -o -name "Cargo.toml" \) | grep -v target) @@ -33,7 +34,7 @@ install: $(IPC_ACTORS_GEN) cargo install --locked --path fendermint/app # Using --release for testing because wasm can otherwise be slow. -test: $(BUILTIN_ACTORS_BUNDLE) $(IPC_ACTORS_OUT) $(IPC_ACTORS_GEN) +test: $(BUILTIN_ACTORS_BUNDLE) $(IPC_ACTORS_GEN) FM_BUILTIN_ACTORS_BUNDLE=$(BUILTIN_ACTORS_BUNDLE) \ FM_CONTRACTS_DIR=$(IPC_ACTORS_OUT) \ cargo test --release --package 'fendermint_*' @@ -73,14 +74,14 @@ docker-build: docker-deps $(FENDERMINT_CODE) $(BUILDX_STORE) \ $(BUILDX_FLAGS) \ -f docker/Dockerfile \ - -t $(BUILDX_TAG) $(PWD); \ + -t $(BUILDX_TAG) $(PWD)/..; \ else \ cat docker/builder.local.Dockerfile docker/runner.Dockerfile > docker/Dockerfile ; \ DOCKER_BUILDKIT=1 \ docker build \ $(BUILDX_STORE) \ -f docker/Dockerfile \ - -t fendermint:latest $(PWD); \ + -t fendermint:latest $(PWD)/..; \ fi @@ -94,11 +95,10 @@ $(BUILTIN_ACTORS_BUNDLE): mkdir -p $(dir $@) curl -L -o $@ https://github.com/filecoin-project/builtin-actors/releases/download/$(BUILTIN_ACTORS_TAG)/builtin-actors-mainnet.car -# Generate the ABI artifacts if we don't have them already. -$(IPC_ACTORS_GEN): - cd $(IPC_ACTORS_DIR) && make .gen - -$(IPC_ACTORS_OUT): $(IPC_ACTORS_GEN) +# Regenerate the ABI artifacts if we don't have them already, or they changed. +$(IPC_ACTORS_GEN): $(IPC_ACTORS_CODE) + cd $(IPC_ACTORS_DIR) && make compile-abi + touch $@ .PHONY: protoc protoc: diff --git a/fendermint/docker/builder.ci.Dockerfile b/fendermint/docker/builder.ci.Dockerfile index 0db6b9e39..715fa2121 100644 --- a/fendermint/docker/builder.ci.Dockerfile +++ b/fendermint/docker/builder.ci.Dockerfile @@ -12,16 +12,16 @@ FROM --platform=$BUILDPLATFORM ubuntu:latest as stripper WORKDIR /app -# Copy the Cargo artifacts and Rust sources. +# Copy the Cargo artifacts and Rust sources everything; even though we only need Cargo.* artifacts and Rust sources. COPY Cargo.toml Cargo.lock ./ -COPY fendermint fendermint/ +COPY . . # Delete anything other than cargo files: Rust sources, config files, Markdown, etc. -RUN find fendermint -type f \! -name "Cargo.*" | xargs rm -rf +RUN find . -type f \! -name "Cargo.*" | xargs rm -rf # Construct dummy sources. Add a print to help debug the case if we failed to properly replace the file. -RUN echo "fn main() { println!(\"I'm the dummy.\"); }" > fendermint/app/src/main.rs && \ - for crate in $(find fendermint -name "Cargo.toml" | xargs dirname); do \ +RUN echo "fn main() { println!(\"I'm the dummy.\"); }" > fendermint/fendermint/app/src/main.rs && \ + for crate in $(find . -name "Cargo.toml" | xargs dirname | grep -v infra | grep -v node_modules | grep /); do \ touch $crate/src/lib.rs; \ done @@ -76,7 +76,7 @@ RUN set -eux; \ COPY . . # Need to invalidate build caches otherwise they won't be recompiled with the real code. -RUN find fendermint -type f \( -wholename "**/src/lib.rs" -o -wholename "**/src/main.rs" \) | xargs touch +RUN find . -type f \( -wholename "**/src/lib.rs" -o -wholename "**/src/main.rs" \) | xargs touch # Do the final build. RUN set -eux; \ @@ -84,4 +84,4 @@ RUN set -eux; \ amd64) ARCH='x86_64' ;; \ arm64) ARCH='aarch64' ;; \ esac; \ - cargo install --locked --root output --path fendermint/app --target ${ARCH}-unknown-linux-gnu + cargo install --locked --root output --path fendermint/fendermint/app --target ${ARCH}-unknown-linux-gnu diff --git a/fendermint/docker/builder.local.Dockerfile b/fendermint/docker/builder.local.Dockerfile index cab6aa990..ca20b55f8 100644 --- a/fendermint/docker/builder.local.Dockerfile +++ b/fendermint/docker/builder.local.Dockerfile @@ -17,4 +17,4 @@ COPY . . RUN --mount=type=cache,target=target \ --mount=type=cache,target=$RUSTUP_HOME,from=rust,source=$RUSTUP_HOME \ --mount=type=cache,target=$CARGO_HOME,from=rust,source=$CARGO_HOME \ - cargo install --locked --root output --path fendermint/app + cargo install --locked --root output --path fendermint/fendermint/app diff --git a/fendermint/docker/runner.Dockerfile b/fendermint/docker/runner.Dockerfile index d4db73ccd..44a096903 100644 --- a/fendermint/docker/runner.Dockerfile +++ b/fendermint/docker/runner.Dockerfile @@ -24,7 +24,7 @@ STOPSIGNAL SIGTERM ENV FM_ABCI__LISTEN__HOST=0.0.0.0 ENV FM_ETH__LISTEN__HOST=0.0.0.0 -COPY docker/.artifacts/bundle.car $FM_HOME_DIR/bundle.car -COPY docker/.artifacts/contracts $FM_HOME_DIR/contracts +COPY fendermint/docker/.artifacts/bundle.car $FM_HOME_DIR/bundle.car +COPY fendermint/docker/.artifacts/contracts $FM_HOME_DIR/contracts COPY --from=builder /app/fendermint/app/config $FM_HOME_DIR/config COPY --from=builder /app/output/bin/fendermint /usr/local/bin/fendermint