From bd03e9828187a98f34f78beae4cb88b64279b598 Mon Sep 17 00:00:00 2001 From: Amin Moghaddam Date: Mon, 5 Feb 2024 11:39:27 +0100 Subject: [PATCH] Add workflow and Dockerfile necessary to build the rust services --- .github/workflows/push-rust-services.yaml | 41 +++++++++ Dockerfile | 44 ++++++++++ auction-server/Cargo.lock | 101 ++++------------------ auction-server/Cargo.toml | 1 - per_multicall/README.md | 2 +- 5 files changed, 103 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/push-rust-services.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/push-rust-services.yaml b/.github/workflows/push-rust-services.yaml new file mode 100644 index 00000000..e2f74953 --- /dev/null +++ b/.github/workflows/push-rust-services.yaml @@ -0,0 +1,41 @@ +name: Build and Push Rust Services Image +on: + push: + tags: + - server-v* + workflow_dispatch: + inputs: + dispatch_description: + description: "Dispatch description" + required: true + type: string +permissions: + contents: read + id-token: write +jobs: + server-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set image tag to version of the git tag + if: ${{ startsWith(github.ref, 'refs/tags/server-v') }} + run: | + PREFIX="refs/tags/server-" + VERSION="${GITHUB_REF:${#PREFIX}}" + echo "IMAGE_TAG=${VERSION}" >> "${GITHUB_ENV}" + - name: Set image tag to the git commit hash + if: ${{ !startsWith(github.ref, 'refs/tags/server-v') }} + run: | + echo "IMAGE_TAG=${{ github.sha }}" >> "${GITHUB_ENV}" + - uses: aws-actions/configure-aws-credentials@8a84b07f2009032ade05a88a28750d733cc30db1 + with: + role-to-assume: arn:aws:iam::192824654885:role/github-actions-ecr + aws-region: eu-west-2 + - uses: aws-actions/amazon-ecr-login@v1 + id: ecr_login + - run: | + DOCKER_BUILDKIT=1 docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + env: + ECR_REGISTRY: ${{ steps.ecr_login.outputs.registry }} + ECR_REPOSITORY: ${{ github.event.repository.name }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7f670ab6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +ARG RUST_VERSION=1.66.1 + +# Get the solidity dependencies using npm +FROM node:21-alpine3.18 AS npm_build +WORKDIR /src +COPY per_multicall per_multicall +WORKDIR /src/per_multicall +RUN npm install + + +FROM rust:${RUST_VERSION} AS build +# Set default toolchain +RUN rustup default nightly-2023-07-23 + +# Install dependencies +RUN curl -L https://foundry.paradigm.xyz | bash +ENV PATH="${PATH}:/root/.foundry/bin/" +RUN foundryup + +# Add solidity dependencies +WORKDIR /src +COPY per_multicall per_multicall +COPY --from=npm_build /src/per_multicall/node_modules/ /src/per_multicall/node_modules/ +WORKDIR /src/per_multicall +RUN forge install foundry-rs/forge-std --no-git --no-commit +RUN forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit + +# Build auction-server +WORKDIR /src +COPY auction-server auction-server +WORKDIR /src/auction-server +RUN --mount=type=cache,target=/root/.cargo/registry cargo build --release + +# Build vault-simulator +WORKDIR /src +COPY vault-simulator vault-simulator +WORKDIR /src/vault-simulator +RUN --mount=type=cache,target=/root/.cargo/registry cargo build --release + + +FROM rust:${RUST_VERSION} +# Copy artifacts from other images +COPY --from=build /src/auction-server/target/release/auction-server /usr/local/bin/ +COPY --from=build /src/vault-simulator/target/release/vault-simulator /usr/local/bin/ diff --git a/auction-server/Cargo.lock b/auction-server/Cargo.lock index c43fcf7c..a814317c 100644 --- a/auction-server/Cargo.lock +++ b/auction-server/Cargo.lock @@ -167,7 +167,6 @@ dependencies = [ "anyhow", "async-stream", "axum", - "axum-auth", "axum-macros", "axum-streams", "clap", @@ -211,13 +210,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core 0.3.4", + "axum-core", "base64 0.21.5", "bitflags 1.3.2", "bytes", "futures-util", - "http 0.2.11", - "http-body 0.4.6", + "http", + "http-body", "hyper", "itoa", "matchit", @@ -240,18 +239,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "axum-auth" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8169113a185f54f68614fcfc3581df585d30bf8542bcb99496990e1025e4120a" -dependencies = [ - "async-trait", - "axum-core 0.4.2", - "base64 0.21.5", - "http 1.0.0", -] - [[package]] name = "axum-core" version = "0.3.4" @@ -261,8 +248,8 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 0.2.11", - "http-body 0.4.6", + "http", + "http-body", "mime", "rustversion", "tower-layer", @@ -270,26 +257,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "axum-core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87c8503f93e6d144ee5690907ba22db7ba79ab001a932ab99034f0fe836b3df" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http 1.0.0", - "http-body 1.0.0", - "http-body-util", - "mime", - "pin-project-lite", - "rustversion", - "sync_wrapper", - "tower-layer", - "tower-service", -] - [[package]] name = "axum-macros" version = "0.4.0" @@ -313,7 +280,7 @@ dependencies = [ "cargo-husky", "futures", "futures-util", - "http 0.2.11", + "http", "mime", "serde", "serde_json", @@ -1232,7 +1199,7 @@ dependencies = [ "futures-timer", "futures-util", "hashers", - "http 0.2.11", + "http", "instant", "jsonwebtoken", "once_cell", @@ -1574,7 +1541,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http 0.2.11", + "http", "indexmap", "slab", "tokio", @@ -1644,17 +1611,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "http-body" version = "0.4.6" @@ -1662,30 +1618,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http 0.2.11", - "pin-project-lite", -] - -[[package]] -name = "http-body" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" -dependencies = [ - "bytes", - "http 1.0.0", -] - -[[package]] -name = "http-body-util" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" -dependencies = [ - "bytes", - "futures-util", - "http 1.0.0", - "http-body 1.0.0", + "http", "pin-project-lite", ] @@ -1718,8 +1651,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http 0.2.11", - "http-body 0.4.6", + "http", + "http-body", "httparse", "httpdate", "itoa", @@ -1738,7 +1671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http 0.2.11", + "http", "hyper", "rustls", "tokio", @@ -2698,8 +2631,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http 0.2.11", - "http-body 0.4.6", + "http", + "http-body", "hyper", "hyper-rustls", "ipnet", @@ -3631,8 +3564,8 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http 0.2.11", - "http-body 0.4.6", + "http", + "http-body", "http-range-header", "pin-project-lite", "tower-layer", @@ -3751,7 +3684,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http 0.2.11", + "http", "httparse", "log", "rand", diff --git a/auction-server/Cargo.toml b/auction-server/Cargo.toml index f572b198..ffd304f8 100644 --- a/auction-server/Cargo.toml +++ b/auction-server/Cargo.toml @@ -25,4 +25,3 @@ utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] } serde_yaml = "0.9.25" ethers = "2.0.10" axum-macros = "0.4.0" -axum-auth = "0.7.0" diff --git a/per_multicall/README.md b/per_multicall/README.md index 03825d1d..45e41aa7 100644 --- a/per_multicall/README.md +++ b/per_multicall/README.md @@ -5,7 +5,7 @@ Run the following commands to install necessary libraries: ```shell -$ npm install @pythnetwork/pyth-sdk-solidity +$ npm install $ forge install foundry-rs/forge-std --no-git --no-commit $ forge install OpenZeppelin/openzeppelin-contracts --no-git --no-commit ```