Skip to content

Commit dd8c3a3

Browse files
authored
Merge pull request wasmerio#4810 from wasmerio/issue-4795-cli-app-cache-purge
feat(cli): Add "app purge-cache" command
2 parents cac4312 + 4170a09 commit dd8c3a3

File tree

7 files changed

+152
-28
lines changed

7 files changed

+152
-28
lines changed

benches/import_functions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub fn run_import_inner(store: &mut Store, n_fn: u32, compiler_name: &str, c: &m
5656
}
5757

5858
fn run_import_functions_benchmarks_small(_c: &mut Criterion) {
59+
#[allow(unused_variables)]
5960
let size = 10;
6061

6162
#[cfg(feature = "llvm")]
@@ -78,6 +79,7 @@ fn run_import_functions_benchmarks_small(_c: &mut Criterion) {
7879
}
7980

8081
fn run_import_functions_benchmarks_medium(_c: &mut Criterion) {
82+
#[allow(unused_variables)]
8183
let size = 100;
8284

8385
#[cfg(feature = "llvm")]
@@ -100,6 +102,7 @@ fn run_import_functions_benchmarks_medium(_c: &mut Criterion) {
100102
}
101103

102104
fn run_import_functions_benchmarks_large(_c: &mut Criterion) {
105+
#[allow(unused_variables)]
103106
let size = 1000;
104107
#[cfg(feature = "llvm")]
105108
{

lib/backend-api/schema.graphql

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type User implements Node & PackageOwner & Owner {
3737
bio: String
3838
location: String
3939
websiteUrl: String
40+
wasmerInternal: Boolean!
4041

4142
"""The ID of the object"""
4243
id: ID!
@@ -199,6 +200,7 @@ type Namespace implements Node & PackageOwner & Owner {
199200
websiteUrl: String
200201
createdAt: DateTime!
201202
updatedAt: DateTime!
203+
wasmerInternal: Boolean!
202204
maintainerInvites(offset: Int, before: String, after: String, first: Int, last: Int): NamespaceCollaboratorInviteConnection!
203205
userSet(offset: Int, before: String, after: String, first: Int, last: Int): UserConnection!
204206
globalName: String!
@@ -446,6 +448,7 @@ type PackageVersion implements Node & PackageReleaseInterface & PackageInstance
446448
bindingsState: RegistryPackageVersionBindingsStateChoices!
447449
nativeExecutablesState: RegistryPackageVersionNativeExecutablesStateChoices!
448450
deployappversionSet(offset: Int, before: String, after: String, first: Int, last: Int): DeployAppVersionConnection!
451+
packagewebcSet(offset: Int, before: String, after: String, first: Int, last: Int): PackageWebcConnection!
449452
lastversionPackage(offset: Int, before: String, after: String, first: Int, last: Int): PackageConnection!
450453
commands: [Command!]!
451454
nativeexecutableSet(offset: Int, before: String, after: String, first: Int, last: Int): NativeExecutableConnection!
@@ -504,7 +507,9 @@ scalar JSONString
504507
type WebcImage implements Node {
505508
"""The ID of the object"""
506509
id: ID!
507-
version: WebcVersion
510+
511+
"""The version of the webc image, defaults to v2."""
512+
version: WebcVersion!
508513

509514
""""""
510515
fileSize: BigInt!
@@ -835,6 +840,26 @@ type AppVersionVolumeMountPath {
835840
subpath: String!
836841
}
837842

843+
type PackageWebcConnection {
844+
"""Pagination data for this connection."""
845+
pageInfo: PageInfo!
846+
847+
"""Contains the nodes in this connection."""
848+
edges: [PackageWebcEdge]!
849+
850+
"""Total number of items in the connection."""
851+
totalCount: Int
852+
}
853+
854+
"""A Relay edge containing a `PackageWebc` and its cursor."""
855+
type PackageWebcEdge {
856+
"""The item at the end of the edge"""
857+
node: PackageWebc
858+
859+
"""A cursor for use in pagination"""
860+
cursor: String!
861+
}
862+
838863
type Command {
839864
command: String!
840865
packageVersion: PackageVersion!
@@ -1227,26 +1252,6 @@ type AppTemplateCategory implements Node {
12271252
appTemplates(offset: Int, before: String, after: String, first: Int, last: Int): AppTemplateConnection!
12281253
}
12291254

1230-
type PackageWebcConnection {
1231-
"""Pagination data for this connection."""
1232-
pageInfo: PageInfo!
1233-
1234-
"""Contains the nodes in this connection."""
1235-
edges: [PackageWebcEdge]!
1236-
1237-
"""Total number of items in the connection."""
1238-
totalCount: Int
1239-
}
1240-
1241-
"""A Relay edge containing a `PackageWebc` and its cursor."""
1242-
type PackageWebcEdge {
1243-
"""The item at the end of the edge"""
1244-
node: PackageWebc
1245-
1246-
"""A cursor for use in pagination"""
1247-
cursor: String!
1248-
}
1249-
12501255
type Collection {
12511256
slug: String!
12521257
displayName: String!
@@ -2088,6 +2093,9 @@ type Log {
20882093

20892094
"""Log stream"""
20902095
stream: LogStream
2096+
2097+
"""ID of instance from which the log was generated"""
2098+
instanceId: String!
20912099
}
20922100

20932101
"""This is for backwards compatibility with the old PackageInstance type."""
@@ -2249,7 +2257,7 @@ type Query {
22492257
getAppByGlobalAlias(alias: String!): DeployApp
22502258
getDeployApps(sortBy: DeployAppsSortBy, updatedAfter: DateTime, offset: Int, before: String, after: String, first: Int, last: Int): DeployAppConnection!
22512259
getAppVersions(sortBy: DeployAppVersionsSortBy, updatedAfter: DateTime, offset: Int, before: String, after: String, first: Int, last: Int): DeployAppVersionConnection!
2252-
getAppTemplates(categorySlug: String, offset: Int, before: String, after: String, first: Int, last: Int): AppTemplateConnection
2260+
getAppTemplates(categorySlug: String, sortBy: AppTemplatesSortBy, offset: Int, before: String, after: String, first: Int, last: Int): AppTemplateConnection
22532261
getAppTemplate(slug: String!): AppTemplate
22542262
getAppTemplateCategories(offset: Int, before: String, after: String, first: Int, last: Int): AppTemplateCategoryConnection
22552263
viewer: User
@@ -2348,6 +2356,12 @@ enum DNSRecordsSortBy {
23482356
OLDEST
23492357
}
23502358

2359+
enum AppTemplatesSortBy {
2360+
NEWEST
2361+
OLDEST
2362+
POPULAR
2363+
}
2364+
23512365
type AppTemplateCategoryConnection {
23522366
"""Pagination data for this connection."""
23532367
pageInfo: PageInfo!
@@ -2788,6 +2802,9 @@ type Mutation {
27882802
generateDeployConfigToken(input: GenerateDeployConfigTokenInput!): GenerateDeployConfigTokenPayload
27892803
renameApp(input: RenameAppInput!): RenameAppPayload
27902804
renameAppAlias(input: RenameAppAliasInput!): RenameAppAliasPayload
2805+
2806+
"""Purges all cache for this app version"""
2807+
purgeCacheForAppVersion(input: PurgeCacheForAppVersionInput!): PurgeCacheForAppVersionPayload
27912808
requestAppTransfer(input: RequestAppTransferInput!): RequestAppTransferPayload
27922809
acceptAppTransferRequest(input: AcceptAppTransferRequestInput!): AcceptAppTransferRequestPayload
27932810
removeAppTransferRequest(input: RemoveAppTransferRequestInput!): RemoveAppTransferRequestPayload
@@ -3026,6 +3043,18 @@ input RenameAppAliasInput {
30263043
clientMutationId: String
30273044
}
30283045

3046+
"""Purges all cache for this app version"""
3047+
type PurgeCacheForAppVersionPayload {
3048+
appVersion: DeployAppVersion!
3049+
clientMutationId: String
3050+
}
3051+
3052+
input PurgeCacheForAppVersionInput {
3053+
"""ID of the app version to purge cache for."""
3054+
id: ID!
3055+
clientMutationId: String
3056+
}
3057+
30293058
type RequestAppTransferPayload {
30303059
appTransferRequest: AppTransferRequest
30313060
wasInstantlyTransferred: Boolean!
@@ -3086,6 +3115,7 @@ input CreateRepoForAppTemplateInput {
30863115
name: String!
30873116
namespace: String!
30883117
private: Boolean = false
3118+
domains: [String] = null
30893119
clientMutationId: String
30903120
}
30913121

@@ -3606,9 +3636,9 @@ type TagPackageReleasePayload {
36063636

36073637
input TagPackageReleaseInput {
36083638
packageReleaseId: ID!
3609-
name: String!
36103639
version: String!
3611-
manifest: String!
3640+
name: String
3641+
manifest: String
36123642
namespace: String
36133643
description: String
36143644
license: String

lib/backend-api/src/query.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,20 @@ pub fn get_all_dns_records_stream(
11371137
)
11381138
}
11391139

1140+
pub async fn purge_cache_for_app_version(
1141+
client: &WasmerClient,
1142+
vars: types::PurgeCacheForAppVersionVars,
1143+
) -> Result<(), anyhow::Error> {
1144+
client
1145+
.run_graphql_strict(types::PurgeCacheForAppVersion::build(vars))
1146+
.await
1147+
.map_err(anyhow::Error::from)
1148+
.map(|x| x.purge_cache_for_app_version)
1149+
.context("backend did not return data")?;
1150+
1151+
Ok(())
1152+
}
1153+
11401154
/// Convert a [`OffsetDateTime`] to a unix timestamp that the WAPM backend
11411155
/// understands.
11421156
fn unix_timestamp(ts: OffsetDateTime) -> f64 {

lib/backend-api/src/types.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,23 @@ mod queries {
15471547
pub records: Option<Vec<Option<DnsRecord>>>,
15481548
}
15491549

1550+
#[derive(cynic::QueryVariables, Debug)]
1551+
pub struct PurgeCacheForAppVersionVars {
1552+
pub id: cynic::Id,
1553+
}
1554+
1555+
#[derive(cynic::QueryFragment, Debug)]
1556+
pub struct PurgeCacheForAppVersionPayload {
1557+
pub app_version: DeployAppVersion,
1558+
}
1559+
1560+
#[derive(cynic::QueryFragment, Debug)]
1561+
#[cynic(graphql_type = "Mutation", variables = "PurgeCacheForAppVersionVars")]
1562+
pub struct PurgeCacheForAppVersion {
1563+
#[arguments(input: {id: $id})]
1564+
pub purge_cache_for_app_version: Option<PurgeCacheForAppVersionPayload>,
1565+
}
1566+
15501567
#[derive(cynic::Scalar, Debug, Clone)]
15511568
pub struct BigInt(pub i64);
15521569

lib/cli/src/commands/app/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod get;
77
pub mod info;
88
pub mod list;
99
pub mod logs;
10+
pub mod purge_cache;
1011
pub mod version;
1112

1213
mod util;
@@ -16,15 +17,16 @@ use crate::commands::AsyncCliCommand;
1617
/// Manage Wasmer Deploy apps.
1718
#[derive(clap::Subcommand, Debug)]
1819
pub enum CmdApp {
20+
Deploy(deploy::CmdAppDeploy),
21+
Create(create::CmdAppCreate),
1922
Get(get::CmdAppGet),
2023
Info(info::CmdAppInfo),
2124
List(list::CmdAppList),
2225
Logs(logs::CmdAppLogs),
23-
Create(create::CmdAppCreate),
26+
PurgeCache(purge_cache::CmdAppPurgeCache),
2427
Delete(delete::CmdAppDelete),
2528
#[clap(subcommand)]
2629
Version(version::CmdAppVersion),
27-
Deploy(deploy::CmdAppDeploy),
2830
}
2931

3032
#[async_trait::async_trait]
@@ -50,6 +52,7 @@ impl AsyncCliCommand for CmdApp {
5052
Self::Delete(cmd) => cmd.run_async().await,
5153
Self::Version(cmd) => cmd.run_async().await,
5254
Self::Deploy(cmd) => cmd.run_async().await,
55+
Self::PurgeCache(cmd) => cmd.run_async().await,
5356
}
5457
}
5558
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Get information about an edge app.
2+
3+
use super::util::AppIdentOpts;
4+
use crate::{
5+
commands::AsyncCliCommand,
6+
opts::{ApiOpts, ItemFormatOpts},
7+
};
8+
9+
/// Purge caches for applications.
10+
///
11+
/// Cache scopes that can be cleared:
12+
/// * InstaBoot startup snapshots
13+
/// Will delete all existing snapshots.
14+
/// New snapshots will be created automatically.
15+
#[derive(clap::Parser, Debug)]
16+
pub struct CmdAppPurgeCache {
17+
#[clap(flatten)]
18+
#[allow(missing_docs)]
19+
pub api: ApiOpts,
20+
#[clap(flatten)]
21+
#[allow(missing_docs)]
22+
pub fmt: ItemFormatOpts,
23+
24+
#[clap(flatten)]
25+
#[allow(missing_docs)]
26+
pub ident: AppIdentOpts,
27+
}
28+
29+
#[async_trait::async_trait]
30+
impl AsyncCliCommand for CmdAppPurgeCache {
31+
type Output = ();
32+
33+
async fn run_async(self) -> Result<(), anyhow::Error> {
34+
let client = self.api.client()?;
35+
let (_ident, app) = self.ident.load_app(&client).await?;
36+
37+
let version_id = app.active_version.id;
38+
39+
let name = format!("{} ({})", app.name, app.owner.global_name);
40+
41+
println!(
42+
"Purging caches for {}, app version {}...",
43+
name,
44+
version_id.inner()
45+
);
46+
47+
let vars = wasmer_api::types::PurgeCacheForAppVersionVars { id: version_id };
48+
wasmer_api::query::purge_cache_for_app_version(&client, vars).await?;
49+
50+
println!("🚽 swirl! All caches have been purged!");
51+
52+
Ok(())
53+
}
54+
}

lib/cli/src/commands/app/util.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ pub fn get_app_config_from_current_dir() -> Result<(AppConfigV1, std::path::Path
112112
///
113113
/// Provides convenience methods for resolving an app identifier or loading it
114114
/// from a local app.yaml.
115+
///
116+
/// NOTE: this is a separate struct to prevent the need for copy-pasting the
117+
/// field docs
115118
#[derive(clap::Parser, Debug)]
116119
pub struct AppIdentOpts {
117120
/// Identifier of the application.
@@ -123,7 +126,7 @@ pub struct AppIdentOpts {
123126
/// - namespace/app-name
124127
/// - app-alias
125128
/// - App ID
126-
pub app_ident: Option<AppIdent>,
129+
pub app: Option<AppIdent>,
127130
}
128131

129132
// Allowing because this is not performance-critical at all.
@@ -148,7 +151,7 @@ impl ResolvedAppIdent {
148151

149152
impl AppIdentOpts {
150153
pub fn resolve_static(&self) -> Result<ResolvedAppIdent, anyhow::Error> {
151-
if let Some(id) = &self.app_ident {
154+
if let Some(id) = &self.app {
152155
return Ok(ResolvedAppIdent::Ident(id.clone()));
153156
}
154157

0 commit comments

Comments
 (0)