Skip to content

Commit

Permalink
feat: deployment related fixes (#647)
Browse files Browse the repository at this point in the history
* Remove --testing from build package action
* Re-add css and js faucet files
* Limit deploy conccurency to 1 per network
* Fix the faucet root route
* faucet endpoint defaults to public
* Simplify faucet static file handling
  • Loading branch information
Mirko-von-Leipzig authored Jan 28, 2025
1 parent 4613db3 commit c11a67e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/actions/build_package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ runs:
env:
repo-url: ${{ github.server_url }}/${{ github.repository }}
run: |
cargo install miden-node --root . --locked --features testing --git ${{ env.repo-url }} --rev ${{ steps.git-sha.outputs.sha }}
cargo install miden-faucet --root . --locked --features testing --git ${{ env.repo-url }} --rev ${{ steps.git-sha.outputs.sha }}
cargo install miden-node --root . --locked --git ${{ env.repo-url }} --rev ${{ steps.git-sha.outputs.sha }}
cargo install miden-faucet --root . --locked --git ${{ env.repo-url }} --rev ${{ steps.git-sha.outputs.sha }}
- name: Copy binary files
shell: bash
Expand Down
30 changes: 19 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ on:
required: true
type: string

# Limit concurrency to 1 per network.
concurrency:
group: ${{ github.workflow }}-${{ inputs.network }}
cancel-in-progress: true

permissions:
id-token: write
contents: write
Expand All @@ -33,10 +38,9 @@ jobs:
oidcrole: midendev
instance-id: ${{ inputs.network == 'testnet' && 'TESTNET_INSTANCE_TF' || 'DEVNET_INSTANCE_TF' }}

# Define the expected package names.
node-package: miden-node-${{ inputs.gitref }}-arm64.deb
faucet-package: miden-faucet-${{ inputs.gitref }}-arm64.deb

# Unique name for each package file per workflow run so there are no clashes on s3.
node-package: node-${{ github.run_id }}-${{ github.run_number }}.arm64.deb
faucet-package: faucet-${{ github.run_id }}-${{ github.run_number }}.arm64.deb

steps:
# S3 path where packages are stored; used to send packages to instance as this isn't trivially possible directly.
Expand All @@ -55,14 +59,19 @@ jobs:
if: ${{ startsWith(inputs.gitref, 'v') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
node-artifact: miden-node-${{ inputs.gitref }}-arm64.deb
faucet-artifact: miden-faucet-${{ inputs.gitref }}-arm64.deb
run: |
gh release download ${{ inputs.gitref }} -p ${{ env.node-package }}
gh release download ${{ inputs.gitref }} -p ${{ env.node-package }}.checksum
gh release download ${{ inputs.gitref }} -p ${{ env.faucet-package }}
gh release download ${{ inputs.gitref }} -p ${{ env.faucet-package }}.checksum
gh release download ${{ inputs.gitref }} -p ${{ env.node-artifact }}
gh release download ${{ inputs.gitref }} -p ${{ env.node-artifact }}.checksum
gh release download ${{ inputs.gitref }} -p ${{ env.faucet-artifact }}
gh release download ${{ inputs.gitref }} -p ${{ env.faucet-artifact }}.checksum
sha256sum --check ${{ env.node-package }}.checksum
sha256sum --check ${{ env.faucet-package }}.checksum
sha256sum --check ${{ env.node-artifact }}.checksum
sha256sum --check ${{ env.faucet-artifact }}.checksum
mv ${{ env.node-artifact }} ${{ env.node-package }}
mv ${{ env.faucet-artifact }} ${{ env.faucet-package }}
# Otherwise build the packages from source.
#
Expand All @@ -80,7 +89,6 @@ jobs:
run: |
mv miden-node.deb ${{ env.node-package }}
mv miden-faucet.deb ${{ env.faucet-package }}
# Configure AWS communication via SSM.
- name: Configure AWS credentials
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Changes

- [BREAKING] Default faucet endpoint is now public instead of localhost (#647).

## v0.7.0 (2025-01-23)

### Enhancements
Expand Down
10 changes: 8 additions & 2 deletions bin/faucet/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::{
path::PathBuf,
};

use miden_node_utils::config::{Endpoint, DEFAULT_FAUCET_SERVER_PORT, DEFAULT_NODE_RPC_PORT};
use miden_node_utils::config::{
Endpoint, Protocol, DEFAULT_FAUCET_SERVER_PORT, DEFAULT_NODE_RPC_PORT,
};
use serde::{Deserialize, Serialize};

// Faucet config
Expand Down Expand Up @@ -42,7 +44,11 @@ impl Display for FaucetConfig {
impl Default for FaucetConfig {
fn default() -> Self {
Self {
endpoint: Endpoint::localhost(DEFAULT_FAUCET_SERVER_PORT),
endpoint: Endpoint {
host: "0.0.0.0".to_string(),
port: DEFAULT_FAUCET_SERVER_PORT,
protocol: Protocol::Http,
},
node_url: Endpoint::localhost(DEFAULT_NODE_RPC_PORT).to_string(),
timeout_ms: DEFAULT_RPC_TIMEOUT_MS,
asset_amount_options: vec![100, 500, 1000],
Expand Down
26 changes: 23 additions & 3 deletions bin/faucet/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,30 @@ pub async fn get_tokens(
.map_err(Into::into)
}

pub async fn get_index(state: State<FaucetState>) -> Result<impl IntoResponse, HandlerError> {
info!(target: COMPONENT, "Serving `index.html`");
pub async fn get_index_html(state: State<FaucetState>) -> Result<impl IntoResponse, HandlerError> {
get_static_file(state, "index.html")
}

pub async fn get_index_js(state: State<FaucetState>) -> Result<impl IntoResponse, HandlerError> {
get_static_file(state, "index.js")
}

pub async fn get_index_css(state: State<FaucetState>) -> Result<impl IntoResponse, HandlerError> {
get_static_file(state, "index.css")
}

/// Returns a static file bundled with the app state.
///
/// # Panics
///
/// Panics if the file does not exist.
fn get_static_file(
State(state): State<FaucetState>,
file: &'static str,
) -> Result<impl IntoResponse, HandlerError> {
info!(target: COMPONENT, file, "Serving static file");

let static_file = state.static_files.get("index.html").expect("index.html should be bundled");
let static_file = state.static_files.get(file).expect("static file not found");

Response::builder()
.status(StatusCode::OK)
Expand Down
7 changes: 5 additions & 2 deletions bin/faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use axum::{
};
use clap::{Parser, Subcommand};
use client::initialize_faucet_client;
use handlers::{get_index_css, get_index_html, get_index_js};
use http::HeaderValue;
use miden_lib::{account::faucets::create_basic_fungible_faucet, AuthScheme};
use miden_node_utils::{config::load_config, crypto::get_rpo_random_coin, version::LongVersion};
Expand All @@ -33,7 +34,7 @@ use tracing::info;

use crate::{
config::{FaucetConfig, DEFAULT_FAUCET_ACCOUNT_PATH},
handlers::{get_index, get_metadata, get_tokens},
handlers::{get_metadata, get_tokens},
};

// CONSTANTS
Expand Down Expand Up @@ -102,7 +103,9 @@ async fn main() -> anyhow::Result<()> {
info!(target: COMPONENT, %config, "Initializing server");

let app = Router::new()
.route("/", get(get_index))
.route("/", get(get_index_html))
.route("/index.js", get(get_index_js))
.route("/index.css", get(get_index_css))
.route("/get_metadata", get(get_metadata))
.route("/get_tokens", post(get_tokens))
.layer(
Expand Down

0 comments on commit c11a67e

Please sign in to comment.