diff --git a/.github/workflows/build-debian.yml b/.github/workflows/build-debian.yml new file mode 100644 index 0000000..e38099c --- /dev/null +++ b/.github/workflows/build-debian.yml @@ -0,0 +1,80 @@ +name: Build Debian Package + +on: + workflow_run: + workflows: ["Release"] + types: [completed] + push: + branches: + - debian-package + +jobs: + build-debian: + name: Build Debian Package + runs-on: ubuntu-22.04 + # Only run if Release succeeded (when triggered by workflow_run) or on manual triggers + if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + dpkg-dev + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: 1.88.0 + + - name: Install cargo-deb + run: | + if ! command -v cargo-deb &> /dev/null; then + cargo install cargo-deb + fi + + - name: Build release binaries + run: cargo build --release + + - name: Build Debian package + run: cargo deb + + - name: Get package version + id: version + run: | + VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version') + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "deb_file=hydrapool_${VERSION}_amd64.deb" >> $GITHUB_OUTPUT + + - name: List generated files + run: | + ls -lh target/debian/ + + - name: Upload Debian package as artifact + uses: actions/upload-artifact@v4 + with: + name: debian-package + path: target/debian/*.deb + if-no-files-found: error + + - name: Attach to GitHub Release + if: github.event_name == 'workflow_run' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Get the tag from the workflow run that triggered this + TAG_NAME=$(git describe --tags --exact-match ${{ github.event.workflow_run.head_sha }} 2>/dev/null || echo "") + + if [ -z "$TAG_NAME" ]; then + echo "No tag found for this release, skipping upload" + exit 0 + fi + + echo "Attaching Debian package to release: $TAG_NAME" + gh release upload "$TAG_NAME" target/debian/*.deb --clobber + echo "Debian package uploaded successfully to release $TAG_NAME" diff --git a/Cargo.toml b/Cargo.toml index c446fb9..79a9ee2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,3 +45,26 @@ bench = false name = "hydrapool_cli" test = false bench = false + +[package.metadata.deb] +maintainer = "Kulpreet Singh " +copyright = "2024, Kulpreet Singh " +license-file = ["LICENSE", "4"] +extended-description = """\ +Hydrapool is an open source Bitcoin mining pool with support for solo mining \ +and PPLNS (Pay Per Last N Shares) accounting. Features include:\n\ + - Run a private solo pool or PPLNS pool\n\ + - Payouts made directly from coinbase (no custody)\n\ + - API for downloading and validating share accounting\n\ + - Compatible with any bitcoin RPC node""" +depends = "$auto, systemd" +section = "net" +priority = "optional" +assets = [ + ["target/release/hydrapool", "usr/bin/", "755"], + ["target/release/hydrapool_cli", "usr/bin/", "755"], + ["config.toml", "etc/hydrapool/config.toml", "644"], +] +conf-files = ["/etc/hydrapool/config.toml"] +maintainer-scripts = "packages/debian/" +systemd-units = { enable = false } \ No newline at end of file diff --git a/config.toml b/config.toml index ca1b324..f2310ba 100644 --- a/config.toml +++ b/config.toml @@ -8,8 +8,9 @@ hostname = "0.0.0.0" port = 3333 start_difficulty = 1 minimum_difficulty = 1 -# The bitcoin address to use for first jobs when there are no shares -bootstrap_address = "" +# The bitcoin address to use for first jobs when there are no +# shares. The default provided is the 256 Foundation address. +bootstrap_address = "bc1qypskemx80lznv4tjpnmpw9c5pgpy32fpkk3sw2" # Any donation amount for developers to be sent to donation address. Default no donation. # donation_address = "" # In basis points, 1% = 100 basis points. Default 0 @@ -31,9 +32,6 @@ difficulty_multiplier = 1.0 # to add a pool signature. Maximum length 16 bytes. pool_signature = "hydrapool" -[miner] -pubkey = "020202020202020202020202020202020202020202020202020202020202020202" - [bitcoinrpc] # RPC credentials are loaded from env vars url = "http://127.0.0.1:38332" diff --git a/hydrapool.service b/hydrapool.service deleted file mode 100644 index f5e0444..0000000 --- a/hydrapool.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Hydrapool Service - -[Service] -Type=simple -User=hydrapool -Group=hydrapool -ExecStart=/home/hydrapool/.cargo/bin/hydrapool --config /home/hydrapool/.cargo/bin/hydrapool/config.toml -Restart=always -RestartSec=30 -StandardOutput=journal -StandardError=journal -SyslogIdentifier=hydrapool - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/packages/Dockerfile.debian b/packages/Dockerfile.debian new file mode 100644 index 0000000..ba68927 --- /dev/null +++ b/packages/Dockerfile.debian @@ -0,0 +1,39 @@ +FROM ubuntu:jammy + +# Install required build dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + clang \ + pkg-config \ + libzmq3-dev \ + git \ + cmake \ + libzstd-dev \ + libsnappy-dev \ + libbz2-dev \ + liblz4-dev \ + zlib1g-dev \ + libssl-dev \ + curl \ + dpkg-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN curl https://sh.rustup.rs -sSf | bash -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" +RUN cargo install cargo-deb + +RUN mkdir -p /hydrapool +COPY ../LICENSE /hydrapool +COPY ../Cargo.toml /hydrapool +COPY ../Cargo.lock /hydrapool +COPY ../config.toml /hydrapool +COPY ../src /hydrapool/src/ +COPY ../packages/ /hydrapool/packages/ + +WORKDIR /hydrapool +RUN cargo build --release + +WORKDIR /hydrapool/packages + +ENTRYPOINT [ ] +CMD ["/hydrapool/packages/build-deb.sh"] diff --git a/packages/README.adoc b/packages/README.adoc new file mode 100644 index 0000000..3c34841 --- /dev/null +++ b/packages/README.adoc @@ -0,0 +1,18 @@ += Packaging for Hydrapool + +== Supported packages: + +. Debian + += Debian Build Locally Using Docker + +== Build docker image + +This image runs cargo build --release so that later we use the image +only to build the package. + +`docker build -f packages/Dockerfile.debian -t debian-build-hydrapool-package .` + +== Build package + +`docker run --volume ./:/hydrapool/target debian-build-hydrapool-package` diff --git a/packages/build-deb.sh b/packages/build-deb.sh new file mode 100755 index 0000000..b276690 --- /dev/null +++ b/packages/build-deb.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +echo "Building Hydrapool Debian package..." +echo + +# Check if cargo-deb is installed +if ! command -v cargo-deb &> /dev/null; then + echo "cargo-deb not found. Installing..." + cargo install cargo-deb +fi + +# Build the release binaries first +echo "Building release binaries..." +cargo build --release + +# Build the Debian package +echo "Creating Debian package..." +cargo deb + +echo +echo "Build complete!" +echo "Package location: target/debian/" +ls -lh ../target/debian/*.deb +echo +echo "To install the package:" +echo " sudo dpkg -i target/debian/hydrapool_*.deb" +echo +echo "After installation:" +echo " 1. Edit /etc/hydrapool/config.toml with your settings" +echo " 2. Start the service: sudo systemctl start hydrapool" +echo " 3. Enable at boot: sudo systemctl enable hydrapool" +echo " 4. Check status: sudo systemctl status hydrapool" diff --git a/packages/debian/service b/packages/debian/service new file mode 100644 index 0000000..3754e74 --- /dev/null +++ b/packages/debian/service @@ -0,0 +1,25 @@ +[Unit] +Description=Hydrapool Bitcoin Mining Pool +After=network.target + +[Service] +Type=simple +User=hydrapool +Group=hydrapool +WorkingDirectory=/var/lib/hydrapool +ExecStart=/usr/bin/hydrapool --config /etc/hydrapool/config.toml +Restart=always +RestartSec=30 +StandardOutput=journal +StandardError=journal +SyslogIdentifier=hydrapool + +# Security hardening +NoNewPrivileges=true +PrivateTmp=true +ProtectSystem=strict +ProtectHome=true +ReadWritePaths=/var/lib/hydrapool /var/log/hydrapool + +[Install] +WantedBy=multi-user.target \ No newline at end of file