diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2a43537 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.github/ +LICENCE +README.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..f8c00ab --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ +## Description + + Please, type here Pull Request description. + + +## Type of change + + Please delete options that are not relevant. + + - [ ] Bug fix (non-breaking change which fixes an issue) + - [ ] New feature (non-breaking change which adds functionality) + - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) + - [ ] This change requires a documentation update + + +# How Has This Been Tested? + + Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration + + - [x] Test A - Run the code locally with `dry-run` mode; + - [x] Test B - Run the code on `devnet` environment; + - [x] Test C - ... + +## Notes + + If you want to left some extra comment please type it here. diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..2a8a818 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,54 @@ +--- +name: "[Check] Code Hygiene" + +on: + pull_request: + branches: ["devnet", "testnet", "mainnet"] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-code-hygiene: + name: Cargo + runs-on: self-hosted + + env: + CARGO_TERM_COLOR: always + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: wasm32-unknown-unknown + components: rustfmt clippy rust-src + + - name: Install needed tools + run: sudo apt-get install protobuf-compiler jq ripgrep libclang-dev libssl-dev -y + + - name: Build + run: cargo build --locked + + - name: Test + run: cargo test --locked + + - name: Format check + run: | + rustup toolchain add nightly-x86_64-unknown-linux-gnu + rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt + cargo +nightly fmt -- --check + + - name: Apply "cargo clippy" for suggestions and warnings for potential errors + run: cargo clippy --all-targets -- --deny warnings + + - name: Clippy checks all features (exclude node and runtime) + run: | + set -o pipefail + cargo metadata --format-version=1 --no-deps \ + | jq '.packages | .[] | .name' \ + | rg --invert-match 'data-storage-(node|runtime)' \ + | xargs -I {} cargo clippy --package {} --all-targets --all-features -- --deny warnings --deny missing_docs diff --git a/.github/workflows/release-binary.yaml b/.github/workflows/release-binary.yaml new file mode 100644 index 0000000..22b5135 --- /dev/null +++ b/.github/workflows/release-binary.yaml @@ -0,0 +1,116 @@ +name: "[Release] Binary (Linux & MacOS)" + +on: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +permissions: + contents: write + +jobs: + build-linux: + runs-on: self-hosted + + outputs: + artifact: data-storage-node-${{ runner.os }}-${{ runner.arch }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: apt-get update && apt install protobuf-compiler libclang-dev libssl-dev -y + + - name: Setup Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: wasm32-unknown-unknown + components: rust-src + + - name: Fetch + run: cargo fetch + + - name: Build + run: cargo build --locked --release --allow warnings + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: data-storage-node-${{ runner.os }}-${{ runner.arch }} + path: ./target/release/data-storage-node + if-no-files-found: error + + build-macos: + runs-on: macos-latest + + needs: define-variables + + outputs: + artifact: data-storage-node-${{ runner.os }}-${{ runner.arch }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install dependencies + run: | + brew update + brew upgrade rustup + brew install protobuf + + - name: Setup Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: wasm32-unknown-unknown + components: rust-src + + - name: Fetch + run: cargo fetch + + - name: Build + run: cargo build --locked --release --allow warnings + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: data-storage-node-${{ runner.os }}-${{ runner.arch }} + path: ./target/release/data-storage-node + if-no-files-found: error + + publish: + runs-on: self-hosted + + needs: [build-linux, build-macos] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set GitHub commit short SHA + run: echo "SHORT_SHA=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV + + - name: Set GitHub branch + run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + + - name: Download Linux binary file + uses: actions/download-artifact@v4 + with: + name: ${{ needs.build-linux.outputs.artifact }} + path: release/linux + + - name: Download MacOS binary file + uses: actions/download-artifact@v4 + with: + name: ${{ needs.build-macos.outputs.artifact }} + path: release/macos + + - name: Publish + uses: softprops/action-gh-release@v2 + with: + name: binary-release-${{ env.BRANCH }}-${{ env.SHORT_SHA }} + files: | + LICENSE + ./release/linux/${{ needs.build-linux.outputs.artifact }} + ./release/macos/${{ needs.build-macos.outputs.artifact }} diff --git a/.github/workflows/release-docker.yaml b/.github/workflows/release-docker.yaml new file mode 100644 index 0000000..b4fd250 --- /dev/null +++ b/.github/workflows/release-docker.yaml @@ -0,0 +1,43 @@ +name: "[Release] Docker" + +on: + workflow_dispatch: + +env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + DOCKERHUB_REPOSITORY: ${{ vars.DOCKERHUB_REPOSITORY }} + +jobs: + build-and-push: + name: Build & Push + runs-on: self-hosted + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set GitHub commit short SHA + run: echo "SHORT_SHA=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV + + - name: Set GitHub branch + run: echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + + - name: Login to OVH (Harbor) private registry + run: | + docker login \ + --username ${{ env.DOCKERHUB_USERNAME }} \ + --password ${{ env.DOCKERHUB_PASSWORD }} \ + docker.io + + - name: Build Docker image(s) + run: | + docker build \ + -t ${{ env.DOCKERHUB_REPOSITORY }}:${{ env.BRANCH }}-latest \ + -t ${{ env.DOCKERHUB_REPOSITORY }}:${{ env.BRANCH }}-${{ env.SHORT_SHA } \ + . + + - name: Push Docker image(s) + run: | + docker push \ + --all-tags \ + ${{ env.DOCKERHUB_REPOSITORY }} diff --git a/.github/workflows/release-runtime.yaml b/.github/workflows/release-runtime.yaml new file mode 100644 index 0000000..824dc77 --- /dev/null +++ b/.github/workflows/release-runtime.yaml @@ -0,0 +1,54 @@ +name: "[Release] Runtime" + +on: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +permissions: + contents: write + +jobs: + build-and-publish: + runs-on: self-hosted + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: wasm32-unknown-unknown + components: rust-src + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install protobuf-compiler jq + + - name: Fetch + run: cargo fetch + + - name: Build + run: cargo build --all --locked --release + + - name: Define variables + id: define-variables + run: | + commit_sha=${{ github.sha }} + echo "commit_sha=${commit_sha:0:7}" >> "$GITHUB_OUTPUT" + echo "release_name=$(./target/release/data-storage-node runtime-version | jq '[.spec_name, .spec_version, .authoring_version, .state_version, .transaction_version, .apis_hash[:16]] | join("-")')" >> "$GITHUB_OUTPUT" + + - uses: softprops/action-gh-release@v2 + env: + release_name: ${{ steps.define-variables.outputs.release_name }} + commit_sha: ${{ steps.define-variables.outputs.commit_sha }} + with: + name: runtime-release-${{ env.release_name }}-${{ env.commit_sha }} + files: | + LICENSE + ./target/release/wbuild/data-storage-runtime/data_storage_runtime.wasm + ./target/release/wbuild/data-storage-runtime/data_storage_runtime.compact.wasm + ./target/release/wbuild/data-storage-runtime/data_storage_runtime.compact.compressed.wasm diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c9a1221 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: build application binary +FROM rust:1.84.0 AS builder + +# Working directory +WORKDIR /app + +# Copy application files +COPY . /app + +# Install dependencies +RUN apt-get update && apt-get install protobuf-compiler libclang-dev libssl-dev -y + +# Setup Rust toolchain +RUN rustup target add wasm32-unknown-unknown +RUN rustup component add rustfmt clippy rust-src + +# Fetch +RUN cargo fetch + +# Build +RUN cargo build --locked --release + +# Stage 2: use small image as a "base" image +FROM ubuntu:24.10 + +# Working directory +WORKDIR /app + +# Copy built binary file +COPY --from=builder /app/target/release/lib* /app/target/release/data-storage-node /app/bin/ + +# Expose default ports (P2P, WebSocket, RPC, Prometheus) +EXPOSE 30333 9933 9944 9615 + +# Specify entrypoint +ENTRYPOINT ["/app/bin/data-storage-node"]