diff --git a/.dockerignore b/.dockerignore index 24acb01f..dd7c1a72 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,18 +1,23 @@ -# Generated by Cargo, executables -target - # GitHub workflows/actions .github +# Folder containing files for bundler spec tests +bundler-spec-tests + # Documentation docs -# Dockerfile -Dockerfile +# Scripts +scripts -# Folder containing files for bundler spec tests -bundler-spec-tests +# Generated by Cargo, executables +target -# Third party dependencies -crates/contracts/thirdparty/account-abstraction/* -tests/thirdparty/bundler/* +# Other files +.gitignore +CODEOWNERS +CONTRIBUTING.md +docker-compose.yml +Dockerfile +rustfmt.toml +tomlfmt.toml diff --git a/.github/scripts/install_geth.sh b/.github/scripts/install_geth.sh new file mode 100755 index 00000000..9da7bd60 --- /dev/null +++ b/.github/scripts/install_geth.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -eo pipefail + +# install geth + +GETH_VERSION="1.12.0-e501b3b0" + +wget -c "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_VERSION.tar.gz" +tar -xf "geth-linux-amd64-$GETH_VERSION.tar.gz" +mv geth-linux-amd64-$GETH_VERSION/geth /usr/local/bin/ +chmod a+x /usr/local/bin/geth + +geth version diff --git a/.github/scripts/install_solc.sh b/.github/scripts/install_solc.sh new file mode 100755 index 00000000..da729f3c --- /dev/null +++ b/.github/scripts/install_solc.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eo pipefail + +# install solc + +SOLC_VERSION="v0.8.20" + +wget -c "https://github.com/ethereum/solidity/releases/download/$SOLC_VERSION/solc-static-linux" +mv solc-static-linux /usr/local/bin/solc +chmod a+x /usr/local/bin/solc + +solc --version diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cb81ac4..ae21482b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,11 +27,6 @@ jobs: with: components: clippy - - name: Setup Rust toolchain (nightly) - uses: dtolnay/rust-toolchain@nightly - with: - components: rustfmt - - name: Install cargo tools run: | curl -L https://github.com/DevinR528/cargo-sort/releases/download/v1.0.9/cargo-sort-x86_64-unknown-linux-gnu.tar.gz | tar -zxvf - -C ~/.cargo/bin/ @@ -62,16 +57,12 @@ jobs: - name: Setup third-party dependencies run: | make setup-thirdparty - - - name: Install Geth and solc - run: | - sudo add-apt-repository ppa:ethereum/ethereum - sudo apt-get update - sudo apt-get install solc - wget -c https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.12.0-e501b3b0.tar.gz - tar -xf geth-linux-amd64-1.12.0-e501b3b0.tar.gz - mv geth-linux-amd64-1.12.0-e501b3b0/geth /usr/local/bin/ - chmod a+x /usr/local/bin/geth + + - name: Install geth + run: .github/scripts/install_geth.sh + + - name: Install solc + run: .github/scripts/install_solc.sh - name: Build run: | @@ -82,10 +73,6 @@ jobs: with: name: silius path: target/debug/silius - - - name: Lint - run: | - make lint - name: Test run: | @@ -94,6 +81,15 @@ jobs: - name: Examples run: | make run-examples + + - name: Setup Rust toolchain (nightly) + uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + + - name: Lint + run: | + make lint bundler_spec_tests: name: Run bundler spec tests diff --git a/.github/workflows/publish_image.yml b/.github/workflows/publish_image.yml index c20f1f66..1e7660b9 100644 --- a/.github/workflows/publish_image.yml +++ b/.github/workflows/publish_image.yml @@ -44,10 +44,37 @@ jobs: run: | echo "IMAGE_NAME_LC=${IMAGE_NAME,,}" >>${GITHUB_ENV} + - name: Fetch third-party dependencies + run: | + make fetch-thirdparty + + - name: Setup Yarn cache - submodule "thirdparty/account-abstraction" + uses: actions/setup-node@v3 + with: + node-version: '16.17' + cache: 'yarn' + cache-dependency-path: crates/contracts/thirdparty/account-abstraction + + - name: Setup Yarn cache - submodule "thirdparty/bundler" + uses: actions/setup-node@v3 + with: + node-version: '16.17' + cache: 'yarn' + cache-dependency-path: tests/thirdparty/bundler + + - name: Setup third-party dependencies + run: | + make setup-thirdparty + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v5 with: context: . push: true + cache-from: type=gha + cache-to: type=gha,mode=max tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:${{ steps.tag.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index eaed4349..615b6a8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,55 @@ -# build -FROM ubuntu:18.04 AS builder +FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef +WORKDIR /app -RUN apt-get update && apt-get -y upgrade && apt-get install -y build-essential software-properties-common ca-certificates curl gnupg git clang pkg-config libclang-dev libssl-dev -RUN add-apt-repository ppa:ethereum/ethereum && apt-get update && apt-get install -y solc +LABEL org.opencontainers.image.source=https://github.com/silius-rs/silius +LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" + +# build cargo-chef plan +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json -RUN mkdir -p /etc/apt/keyrings -RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg -RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list -RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +# Set the build profile to be release +ARG BUILD_PROFILE=release +ENV BUILD_PROFILE $BUILD_PROFILE -RUN apt-get update && apt-get install -y nodejs yarn +# Install system dependencies +RUN apt-get update && apt-get -y upgrade && apt-get install -y pkg-config libclang-dev libssl-dev -WORKDIR /rust +# Install solc +RUN wget -c "https://github.com/ethereum/solidity/releases/download/v0.8.20/solc-static-linux" +RUN mv solc-static-linux /usr/local/bin/solc +RUN chmod a+x /usr/local/bin/solc -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -ENV PATH="/root/.cargo/bin:$PATH" +# Builds dependencies +RUN cargo chef cook --profile $BUILD_PROFILE --recipe-path recipe.json -WORKDIR /silius +# Build application COPY . . +RUN cargo build --profile $BUILD_PROFILE --locked -RUN make fetch-thirdparty -RUN make setup-thirdparty -RUN make build +# Copy application +RUN cp /app/target/$BUILD_PROFILE/silius /app/silius -# run -FROM frolvlad/alpine-glibc:alpine-3.17 +# Use alpine as a runtime image +FROM frolvlad/alpine-glibc:alpine-3.17 AS runtime +# Create data folder RUN mkdir -p /data/silius +# Install system dependencies RUN apk add openssl1.1-compat -COPY --from=builder /silius/target/release/silius /usr/local/bin/silius +# Copy silus binary +COPY --from=builder /app/silius /usr/local/bin/silius +# Copy licenses +COPY LICENSE-* ./ + +# Expose ports EXPOSE 3000 3001 ENTRYPOINT ["/usr/local/bin/silius"] - -LABEL org.opencontainers.image.source=https://github.com/silius-rs/silius