Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
test:
name: Build and test ${{ matrix.label }}
runs-on: ${{ matrix.runner }}
env:
GIT_SHA: ${{ github.sha }}

strategy:
fail-fast: false
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
contents: read
env:
VERSION: ${{ github.ref_name }}
BEAM_VERSION: ${{ github.ref_name }}
GIT_SHA: ${{ github.sha }}
strategy:
fail-fast: false
matrix:
Expand Down
9 changes: 9 additions & 0 deletions beam-init-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ pub enum ServiceStatus {
Error(String),
}

/// Version information for beam-init
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VersionResponse {
/// The version reported by beam-init
pub version: String,
/// The commit sha beam-init was compiled from
pub sha: String,
}

impl std::fmt::Display for ServiceStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
6 changes: 5 additions & 1 deletion beam-init-client/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::io::Read;
use std::path::Path;

use beam_init_api::{CreateService, Service, ServiceStatus};
use beam_init_api::{CreateService, Service, ServiceStatus, VersionResponse};
use reqwest::{Method, StatusCode};
use serde::Serialize;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -116,6 +116,10 @@ impl Client {
self.get_raw(&path)
}

pub fn version(&self) -> Result<VersionResponse, Error> {
self.get("/version")
}

fn request(&self, method: Method, path: &str) -> reqwest::blocking::RequestBuilder {
debug_assert!(path.starts_with('/'));
self.client
Expand Down
11 changes: 10 additions & 1 deletion beam-init/src/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tokio_stream::StreamExt;
use crate::Event;
use crate::services::{self, ServiceError, ServiceManager, StartReason};
use beam_init::system::cerr;
use beam_init_api::{API_SOCKET_PATH, CreateService, ServiceStatus};
use beam_init_api::{API_SOCKET_PATH, CreateService, ServiceStatus, VersionResponse};

#[allow(clippy::enum_variant_names)]
#[derive(Debug)]
Expand Down Expand Up @@ -109,6 +109,7 @@ pub fn bind_api_socket(tx_event: mpsc::Sender<Event>) -> io::Result<()> {
.route("/service/{name}/thaw", post(thaw_service))
.route("/service/{name}/show", post(show_service))
.route("/service/{name}/logs", get(service_logs))
.route("/version", get(version))
.with_state(tx_event);

tokio::spawn(async move {
Expand Down Expand Up @@ -286,6 +287,14 @@ async fn service_logs(
rx.await.expect("main task crashed")
}

async fn version() -> Response {
Json(VersionResponse {
version: crate::VERSION.to_string(),
sha: crate::GIT_SHA.to_string(),
})
.into_response()
}

impl From<&crate::services::Service> for beam_init_api::Service {
fn from(value: &crate::services::Service) -> Self {
Self {
Expand Down
16 changes: 16 additions & 0 deletions beam-init/src/bin/beamctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ use clap_complete::{Shell, generate};
use beam_init_api::Probe;
use beam_init_client::blocking::Client;

const VERSION: &str = match option_env!("BEAM_VERSION") {
Some(version) => version,
None => env!("CARGO_PKG_VERSION"),
};
const GIT_SHA: &str = match option_env!("GIT_SHA") {
Some(sha) => sha,
None => "unknown",
};

#[cfg(feature = "unstable-pty")]
mod terminal;

Expand Down Expand Up @@ -99,6 +108,8 @@ enum Command {
/// Shell to generate completions for.
shell: Shell,
},
/// Show the version of beamctl and beam-init
Version,
}

// Defaults are from https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/v1/defaults.go.
Expand Down Expand Up @@ -270,6 +281,11 @@ fn main() {

generate(shell, &mut command, "beamctl", &mut std::io::stdout());
}
Command::Version => {
println!("beamctl: Version: {} - SHA: {}", VERSION, GIT_SHA);
let resp = client.version().unwrap_or_else(show_error_and_exit);
println!("beam-init: Version: {} - SHA: {}", resp.version, resp.sha);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions beam-init/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ mod logs;
mod services;
mod signal_stream;

pub(crate) const VERSION: &str = match option_env!("BEAM_VERSION") {
Some(version) => version,
None => env!("CARGO_PKG_VERSION"),
};
pub(crate) const GIT_SHA: &str = match option_env!("GIT_SHA") {
Some(sha) => sha,
None => "unknown",
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be put in beam-init/src/lib.rs to share it between beam-init and beamctl?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I originally did that but moved to individual bins since it required pub visibility

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it would be a problem to make these pub in the beam-init library.

/// If true we will print log messages that may contain sensitive information.
///
/// Set to true using the `BEAM_INIT_ENABLE_DEBUG_LOGS=1` env var.
Expand Down