Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version checker #934

Merged
merged 57 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
75ccfa9
[WIP] Version checker
jiivan Jan 18, 2021
2ec47c2
Rest endpoint for getting version (Placeholder values)
nieznanysprawiciel Jan 21, 2021
b41dd7d
Merge branch 'master' into version-notifier
tworec Jan 21, 2021
868a421
cargo fmt
tworec Jan 21, 2021
c59e47f
Merge branch 'master' into version-notifier
tworec Jan 21, 2021
1e14bd5
sort deps
tworec Jan 21, 2021
14d7d3d
Get current and pending version from db
nieznanysprawiciel Jan 22, 2021
1e9df14
Merge branch 'version-notifier' of github.com:golemfactory/yagna into…
nieznanysprawiciel Jan 22, 2021
0080e0b
Version sql migrations
jiivan Jan 22, 2021
46f5792
Apply suggestions from code review
nieznanysprawiciel Jan 22, 2021
32ed513
Don't clean old version entries
jiivan Jan 22, 2021
a6488ee
Update core/version/src/db.rs
jiivan Jan 22, 2021
cb40d40
readonly_transaction
jiivan Jan 22, 2021
def7e4d
Use semver_str()
jiivan Jan 22, 2021
1911cc8
Merge pull request #955 from golemfactory/version/rest
jiivan Jan 22, 2021
c789e4b
Compile time utils dependency
jiivan Jan 22, 2021
1087cb6
Proper date parsing
jiivan Jan 22, 2021
49e2890
Merge pull request #960 from golemfactory/version/dates
jiivan Jan 22, 2021
8805449
Update UPDATE_CURL
jiivan Jan 22, 2021
9fc302b
Merge branch 'version-notifier' of github.com:golemfactory/yagna into…
jiivan Jan 22, 2021
a5cb1e6
Fake release entry on start
jiivan Jan 22, 2021
3fecec2
update CODEOWNERS
tworec Jan 22, 2021
083dedb
Test DEFAULT_RELEASE_TS
jiivan Jan 22, 2021
968e260
main Cargo.toml cleanup
tworec Jan 22, 2021
1b8ce80
[core model] added version module
tworec Jan 22, 2021
89cc620
ya-version as Yagna Service
tworec Jan 22, 2021
f9e8f80
Merge pull request #959 from golemfactory/version/ancient_entries
jiivan Jan 22, 2021
97b787c
Merge pull request #958 from golemfactory/version/sql
jiivan Jan 22, 2021
2931d9a
Merge branch 'version-notifier' into version/service
tworec Jan 22, 2021
2c7afa4
[web-middleware] allow /version wo auth
tworec Jan 22, 2021
05c970c
[ya-version] all parts fastened together
tworec Jan 22, 2021
1d3ab10
[ya-version] messages better UX + counter fix
tworec Jan 22, 2021
0a51a7d
[ya-version] check only latest release and save it + msgs & logs UX
tworec Jan 22, 2021
17597e5
[ya-version] splitted modules into files
tworec Jan 22, 2021
68d2d94
[ya-version] rest and cli json unification + show command added + dao…
tworec Jan 22, 2021
9bbbc7b
[ya-version] pending release sorted by release_ts and version
tworec Jan 22, 2021
c829ff4
[golemsp] new version notification in status
tworec Jan 22, 2021
b5fa96d
[ya-version] further UX improovements
tworec Jan 22, 2021
8de9732
[ya-version] tuneup creation of (initial) release from binary-hardcod…
tworec Jan 22, 2021
ad5fa7e
[ya-version] log warning interval 30min
tworec Jan 22, 2021
1eb4cdc
[ya-version] v0.1 + github fns in separate module
tworec Jan 23, 2021
0032bb2
Revert "update CODEOWNERS"; moved to separate PR #963
tworec Jan 25, 2021
98dea9f
get current release on start, to not request GH unnecessary
tworec Jan 25, 2021
3ff8f06
[ya-version] show help message for the main cli entry + hide skip option
tworec Jan 25, 2021
d1bdc1b
[ya-version] first check running release and then latest
tworec Jan 25, 2021
cca57ae
[ya-version] apply review comments by @jiivan: fixed release_ts ordering
tworec Jan 25, 2021
104b707
[ya-version] fixed tag stripping + aux order by insertion_ts
tworec Jan 25, 2021
b27d17c
Merge pull request #961 from golemfactory/version/service
tworec Jan 25, 2021
f76f0de
Merge branch 'master' of github.com:golemfactory/yagna into version-n…
jiivan Jan 25, 2021
55f60ef
[ya-version] test DBRelease::current
tworec Jan 25, 2021
9f52ec0
[ya-version] bump ya-service-bus dependency to 0.3
tworec Jan 25, 2021
d38b487
Revert accidentally modified json from exe-unit
jiivan Jan 25, 2021
391d689
Merge branch 'master' into version-notifier
tworec Jan 25, 2021
5025733
Merge branch 'master' into version-notifier
tworec Jan 25, 2021
b62e7ca
[ya-version] remove gitrev from core model
tworec Jan 25, 2021
692e3a9
[yagna] initialize Identity Service first
tworec Jan 25, 2021
b2fcc45
[ya-version] rename UpgradeCLI to VersionCLI
tworec Jan 25, 2021
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
523 changes: 392 additions & 131 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ ya-sgx = "0.1"
ya-utils-path = "0.1"
ya-utils-futures = "0.1"
ya-utils-process = { version = "0.1", features = ["lock"] }
ya-version = "0.1"

actix-rt = "1.0"
actix-service = "1.0"
Expand Down Expand Up @@ -119,6 +120,7 @@ members = [
"core/serv-api/interfaces",
"core/serv-api/web",
"core/sgx",
"core/version",
"exe-unit",
"exe-unit/runtime-api",
"exe-unit/tokio-process-ns",
Expand All @@ -138,17 +140,18 @@ members = [

[patch.crates-io]
## SERVICES
ya-identity = { path = "core/identity" }
ya-net = { path = "core/net" }
ya-market = { path = "core/market" }
ya-market-resolver = { path = "core/market/resolver" }
ya-activity = { path = "core/activity" }
ya-sgx = { path = "core/sgx" }
ya-payment = { path = "core/payment" }
ya-payment-driver = { path = "core/payment-driver/base" }
ya-dummy-driver = { path = "core/payment-driver/dummy" }
ya-gnt-driver = { path = "core/payment-driver/gnt" }
ya-zksync-driver = { path = "core/payment-driver/zksync" }
ya-identity = { path = "core/identity" }
ya-market = { path = "core/market" }
ya-market-resolver = { path = "core/market/resolver" }
ya-net = { path = "core/net" }
ya-payment = { path = "core/payment" }
ya-sgx = { path = "core/sgx" }
ya-version = { path = "core/version" }

## CORE UTILS
ya-core-model = { path = "core/model" }
Expand Down
12 changes: 3 additions & 9 deletions core/market/tests/test_agreement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,9 +1049,7 @@ async fn test_terminate_from_wrong_states() {
from: AgreementState::Proposal,
to: AgreementState::Terminated,
},
)) => {
assert_eq!(id, agreement_id)
}
)) => assert_eq!(id, agreement_id),
e => panic!("Wrong error returned, got: {:?}", e),
};

Expand All @@ -1078,9 +1076,7 @@ async fn test_terminate_from_wrong_states() {
from: AgreementState::Pending,
to: AgreementState::Terminated,
},
)) => {
assert_eq!(id, agreement_id)
}
)) => assert_eq!(id, agreement_id),
e => panic!("Wrong error returned, got: {:?}", e),
};

Expand All @@ -1102,9 +1098,7 @@ async fn test_terminate_from_wrong_states() {
from: AgreementState::Pending,
to: AgreementState::Terminated,
},
)) => {
assert_eq!(id, agreement_id)
}
)) => assert_eq!(id, agreement_id),
e => panic!("Wrong error returned, got: {:?}", e),
};
}
Expand Down
4 changes: 3 additions & 1 deletion core/model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ full = [
'net',
'payment',
'gftp',
'sgx'
'sgx',
'version',
]
activity = []
appkey = []
Expand All @@ -31,6 +32,7 @@ market = []
net = []
payment = ['bigdecimal', 'bitflags']
sgx = ['graphene-sgx']
version = []

[dependencies]
ya-client-model = "0.2"
Expand Down
3 changes: 3 additions & 0 deletions core/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub mod gftp;
#[cfg(feature = "sgx")]
pub mod sgx;

#[cfg(feature = "version")]
pub mod version;

use derive_more::Display;
use serde::{Deserialize, Serialize};
pub use ya_client_model::NodeId;
Expand Down
110 changes: 110 additions & 0 deletions core/model/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//! Version handling service bus API.

use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};

use ya_client_model::ErrorMessage;
use ya_service_bus::RpcMessage;

pub const BUS_ID: &'static str = "/local/version";

/// Skip upgrading to the latest Yagna release.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Skip();

impl RpcMessage for Skip {
const ID: &'static str = "skip";
type Item = Option<Release>;
type Error = ErrorMessage;
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Get {
pub check: bool,
}

impl Get {
pub fn show_only() -> Self {
Get { check: false }
}

pub fn with_check() -> Self {
Get { check: true }
}
}

impl RpcMessage for Get {
const ID: &'static str = "check";
type Item = VersionInfo;
type Error = ErrorMessage;
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, thiserror::Error)]
#[serde(rename_all = "camelCase")]
#[error("Version {version}{} '{name}' released {}",
gitrev.as_ref().map(|r| format!(" ({})",r)).unwrap_or("".into()),
release_ts.format("%Y-%m-%d")
)]
pub struct Release {
pub version: String,
pub name: String,
pub gitrev: Option<String>,
pub seen: bool,
pub release_ts: NaiveDateTime,
pub insertion_ts: Option<NaiveDateTime>,
pub update_ts: Option<NaiveDateTime>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VersionInfo {
pub current: Release,
pub pending: Option<Release>,
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_release_no_gitrev_to_string() {
let now = NaiveDateTime::parse_from_str("2015-10-13T15:43:00GMT+2", "%Y-%m-%dT%H:%M:%S%Z")
.unwrap();
let r = Release {
version: "0.6.1".to_string(),
name: "some code name".to_string(),
gitrev: None,
seen: false,
release_ts: now,
insertion_ts: None,
update_ts: None,
};

assert_eq!(
r.to_string(),
"Version 0.6.1 'some code name' released 2015-10-13"
);
}

#[test]
fn test_release_gitrev_to_string() {
let now = NaiveDateTime::parse_from_str("2015-10-13T15:43:00GMT+2", "%Y-%m-%dT%H:%M:%S%Z")
.unwrap();
let r = Release {
version: "0.6.1".to_string(),
name: "some code name".to_string(),
gitrev: Some("0032bb27".into()),
seen: false,
release_ts: now,
insertion_ts: None,
update_ts: None,
};

assert_eq!(
r.to_string(),
"Version 0.6.1 (0032bb27) 'some code name' released 2015-10-13"
);
}
}
4 changes: 3 additions & 1 deletion core/serv-api/web/src/middleware/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ where
let service = self.service.clone();

// TODO: remove this hack; possibly by enabling creation of arbitrary appkey from CLI
if req.uri().to_string().starts_with("/metrics-api") {
if req.uri().to_string().starts_with("/metrics-api")
|| req.uri().to_string().starts_with("/version")
{
log::debug!("skipping authorization for uri={}", req.uri());
return Box::pin(service.borrow_mut().call(req));
}
Expand Down
3 changes: 3 additions & 0 deletions core/serv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use ya_service_api_web::{
use ya_sgx::SgxService;
use ya_utils_path::data_dir::DataDir;
use ya_utils_process::lock::ProcLock;
use ya_version::VersionService;

mod autocomplete;
use autocomplete::CompleteCommand;
Expand Down Expand Up @@ -187,6 +188,8 @@ enum Services {
// other services to initialize counters and other metrics.
#[enable(gsb, rest)]
Metrics(MetricsService),
#[enable(gsb, rest, cli)]
Version(VersionService),
#[enable(gsb, cli(flatten))]
Identity(IdentityService),
#[enable(gsb)]
Expand Down
29 changes: 29 additions & 0 deletions core/version/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "ya-version"
version = "0.1.0"
description = "Version handling"
authors = ["Golem Factory <contact@golem.network>"]
edition = "2018"

[dependencies]
ya-client = "0.4"
ya-compile-time-utils = "0.1"
ya-core-model = { version = "0.2.0", features = ["version"] }
ya-persistence = "0.2"
ya-service-api = "0.1"
ya-service-api-interfaces = "0.1"
ya-service-bus = "0.3"

actix-web = "3.2"
anyhow = "1.0"
chrono = { version = "0.4", features = ["serde"] }
diesel = { version = "1.4", features = ["chrono", "sqlite", "r2d2"] }
diesel_migrations = "1.4"
log = "0.4"
metrics = "0.12"
self_update = "0.23"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = "0.3.21"
thiserror = "^1.0"
tokio = { version = "0.2", features = ["time", "sync"] }
5 changes: 5 additions & 0 deletions core/version/diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "src/db/schema.rs"
Empty file.
2 changes: 2 additions & 0 deletions core/version/migrations/2021-01-22-093722_initial/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Note that triggers are automatically dropped when the associated table is dropped.
DROP TABLE version_release;
17 changes: 17 additions & 0 deletions core/version/migrations/2021-01-22-093722_initial/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE version_release (
version TEXT PRIMARY KEY,
name TEXT NOT NULL,
seen BOOLEAN NOT NULL DEFAULT false,
release_ts TIMESTAMP NOT NULL,
insertion_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
update_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TRIGGER version_release_update_ts
AFTER UPDATE
ON version_release
FOR EACH ROW
WHEN NEW.update_ts <= OLD.update_ts --- this avoids infinite loop
BEGIN
UPDATE version_release SET update_ts=CURRENT_TIMESTAMP WHERE version=OLD.version;
END;
9 changes: 9 additions & 0 deletions core/version/src/db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub(crate) mod dao;
pub(crate) mod model;
pub(crate) mod schema;

#[allow(dead_code)]
pub(crate) mod migrations {
#[derive(EmbedMigrations)]
struct _Dummy;
}
Loading