Skip to content

Commit

Permalink
Build contract in docker (#89)
Browse files Browse the repository at this point in the history
* Build contract in docker

* CI: add build step

* Update contract builds

* Update .github/workflows/tests.yml

Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>

---------

Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>
  • Loading branch information
karim-en and aleksuss committed Jul 4, 2024
1 parent e9f3c1d commit 7816753
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CARGO_FEATURES_TEST=""
RUSTC_FLAGS_BUILD="-C link-arg=-s"
NEAR_EVM_ACCOUNT="aurora"
WASM_FILE="aurora-eth-connector-mainnet.wasm"
WASM_FILE_MIGRATION="aurora-eth-connector-mainnet-migration.wasm"
WASM_FILE_TEST="aurora-eth-connector-test.wasm"
NEAR_CLI="near"
IS_PROD=true
1 change: 1 addition & 0 deletions .env/local.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ CARGO_FEATURES_BUILD="mainnet"
RUSTC_FLAGS_BUILD="-C link-arg=-s"
NEAR_EVM_ACCOUNT="aurora.test.near"
WASM_FILE="aurora-eth-connector-local.wasm"
WASM_FILE_MIGRATION="aurora-eth-connector-local-migration.wasm"
NEAR_CLI="local-near"
IS_PROD=false
1 change: 1 addition & 0 deletions .env/mainnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CARGO_FEATURES_TEST="migration-tests"
RUSTC_FLAGS_BUILD="-C link-arg=-s"
NEAR_EVM_ACCOUNT="aurora"
WASM_FILE="aurora-eth-connector-mainnet.wasm"
WASM_FILE_MIGRATION="aurora-eth-connector-mainnet-migration.wasm"
WASM_FILE_TEST="aurora-eth-connector-test.wasm"
NEAR_CLI="near"
IS_PROD=true
1 change: 1 addition & 0 deletions .env/testnet.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CARGO_FEATURES_TEST="migration-tests"
RUSTC_FLAGS_BUILD="-C link-arg=-s"
NEAR_EVM_ACCOUNT="aurora"
WASM_FILE="aurora-eth-connector-testnet.wasm"
WASM_FILE_MIGRATION="aurora-eth-connector-mainnet-migration.wasm"
WASM_FILE_TEST="aurora-eth-connector-testnet-test.wasm"
NEAR_CLI="near"
IS_PROD=false
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ jobs:
- name: Test mainnet
run: cargo make --profile mainnet test

test-build:
name: Build and diff
runs-on: ubuntu-latest
steps:
- name: Clone the repository
uses: actions/checkout@v4

- name: Build
run: ./build.sh

- name: Diff
run: |
git diff
git status
changed_files=$(git status --porcelain --untracked-files=no | wc -l)
if [ $changed_files -gt 0 ]; then
echo 'contract changed, please rebuild contract'
exit 1
fi
env:
NEAR_SANDBOX_BIN_PATH: /usr/local/bin/near-sandbox
CARGO_TERM_COLOR: always
Expand Down
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ run_task = "build-contract-flow"

[tasks.build-migration]
condition = { profiles = ["mainnet", "testnet", "localnet", "development", "custom"] }
env = { "RUSTFLAGS" = "${RUSTC_FLAGS_BUILD}", "CARGO_FEATURES" = "${CARGO_FEATURES_BUILD_MIGRATION}", "RELEASE" = "--release", "TARGET_DIR" = "release" }
env = { "RUSTFLAGS" = "${RUSTC_FLAGS_BUILD}", "CARGO_FEATURES" = "${CARGO_FEATURES_BUILD_MIGRATION}", "WASM_FILE" = "${WASM_FILE_MIGRATION}", "RELEASE" = "--release", "TARGET_DIR" = "release" }
category = "Build"
run_task = "build-contract-flow"

Expand Down
20 changes: 20 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Exit script as soon as a command fails.
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

docker run \
--rm \
--mount type=bind,source=$DIR,target=/host \
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
-w /host \
-e RUSTFLAGS='-C link-arg=-s' \
rust:latest \
/bin/bash -c "rustup target add wasm32-unknown-unknown; cargo install --force cargo-make; \
cargo make --profile mainnet build; cargo make --profile mainnet build-migration"

mkdir -p res
cp $DIR/bin/aurora-eth-connector-mainnet.wasm $DIR/res/
cp $DIR/bin/aurora-eth-connector-mainnet-migration.wasm $DIR/res/
Binary file added res/aurora-eth-connector-mainnet-migration.wasm
Binary file not shown.
Binary file added res/aurora-eth-connector-mainnet.wasm
Binary file not shown.

0 comments on commit 7816753

Please sign in to comment.