Skip to content

Commit

Permalink
feat!: Code updates
Browse files Browse the repository at this point in the history
- Added Dockerfile and .dockerignore
- Added GitHub Actions workflows
- Added pull request template
  • Loading branch information
craaazymight committed Jan 29, 2025
1 parent 4385dfe commit 8fc1abd
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github/
LICENCE
README.md
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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.
54 changes: 54 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -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
116 changes: 116 additions & 0 deletions .github/workflows/release-binary.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
43 changes: 43 additions & 0 deletions .github/workflows/release-docker.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
54 changes: 54 additions & 0 deletions .github/workflows/release-runtime.yaml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 8fc1abd

Please sign in to comment.