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

Adopt the push-tag publishing mechanism #4643

Merged
merged 19 commits into from
May 8, 2024
Merged
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
669 changes: 376 additions & 293 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ wasmer-config = { path = "./lib/config" }
wasmer-wasix = { path = "./lib/wasix" }

# Wasmer-owned crates
webc = { version = "6.0.0-alpha6", default-features = false, features = ["package"] }
webc = { version = "6.0.0-alpha8", default-features = false, features = ["package"] }
edge-schema = { version = "=0.1.0" }
shared-buffer = "0.1.4"

Expand Down
98 changes: 68 additions & 30 deletions lib/backend-api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ type Package implements Likeable & Node & PackageOwner {
"""List of app templates for this package"""
appTemplates(offset: Int, before: String, after: String, first: Int, last: Int): AppTemplateConnection!
packagewebcSet(offset: Int, before: String, after: String, first: Int, last: Int): PackageWebcConnection!
versions: [PackageVersion]!
versions: [PackageVersion]
collectionSet: [Collection!]!
categories(offset: Int, before: String, after: String, first: Int, last: Int): CategoryConnection!
keywords(offset: Int, before: String, after: String, first: Int, last: Int): PackageKeywordConnection!
Expand Down Expand Up @@ -504,7 +504,7 @@ scalar JSONString
type WebcImage implements Node {
"""The ID of the object"""
id: ID!
version: RegistryWebcImageVersionChoices!
version: WebcVersion

""""""
fileSize: BigInt!
Expand All @@ -518,11 +518,8 @@ type WebcImage implements Node {
webcUrl: String!
}

enum RegistryWebcImageVersionChoices {
"""v2"""
enum WebcVersion {
V2

"""v3"""
V3
}

Expand Down Expand Up @@ -645,7 +642,9 @@ type DeployAppVersion implements Node {
last: Int
): LogConnection!
usageMetrics(forRange: MetricRange!, variant: MetricType!): [UsageMetric]!
sourcePackageVersion: PackageVersion!
sourcePackageVersion: PackageVersion
sourcePackageRelease: PackageWebc
sourcePackage: Package!
aggregateMetrics: AggregateMetrics!
volumes: [AppVersionVolume]
favicon: URL
Expand Down Expand Up @@ -806,6 +805,24 @@ enum LogStream {
RUNTIME
}

type PackageWebc implements Node & PackageReleaseInterface & PackageInstance {
"""The ID of the object"""
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
package: Package!
webc: WebcImage
piritaManifest: JSONString
piritaOffsets: JSONString
piritaVolumes: JSONString
isArchived: Boolean!
clientName: String
publishedBy: User!
webcV3: WebcImage
tag: String!
webcUrl: String!
}

type AppVersionVolume {
name: String!
mountPaths: [AppVersionVolumeMountPath]!
Expand Down Expand Up @@ -1052,11 +1069,6 @@ type PackageDistribution {
webcVersion: WebcVersion
}

enum WebcVersion {
V2
V3
}

type PackageVersionFilesystem {
wasm: String!
host: String!
Expand Down Expand Up @@ -1235,24 +1247,6 @@ type PackageWebcEdge {
cursor: String!
}

type PackageWebc implements Node & PackageReleaseInterface & PackageInstance {
"""The ID of the object"""
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
package: Package!
webc: WebcImage
piritaManifest: JSONString
piritaOffsets: JSONString
piritaVolumes: JSONString
isArchived: Boolean!
clientName: String
publishedBy: User!
webcV3: WebcImage
tag: String!
webcUrl: String!
}

type Collection {
slug: String!
displayName: String!
Expand Down Expand Up @@ -2834,6 +2828,8 @@ type Mutation {
mfa2EmailGetToken(input: MFAGenerateEmailOTPInput!): MFAEmailGenerationResponse
publishPublicKey(input: PublishPublicKeyInput!): PublishPublicKeyPayload
publishPackage(input: PublishPackageInput!): PublishPackagePayload
pushPackageRelease(input: PushPackageReleaseInput!): PushPackageReleasePayload
tagPackageRelease(input: TagPackageReleaseInput!): TagPackageReleasePayload
updatePackage(input: UpdatePackageInput!): UpdatePackagePayload
likePackage(input: LikePackageInput!): LikePackagePayload
unlikePackage(input: UnlikePackageInput!): UnlikePackagePayload
Expand Down Expand Up @@ -3586,6 +3582,48 @@ enum UploadFormat {
webcv3
}

type PushPackageReleasePayload {
success: Boolean!
packageWebc: PackageWebc
clientMutationId: String
}

input PushPackageReleaseInput {
namespace: String!
signedUrl: String!
name: String

"""Whether the package is private"""
private: Boolean = false
clientMutationId: String
}

type TagPackageReleasePayload {
success: Boolean!
packageVersion: PackageVersion
clientMutationId: String
}

input TagPackageReleaseInput {
packageReleaseId: ID!
name: String!
version: String!
manifest: String!
namespace: String
description: String
license: String
licenseFile: String
readme: String
repository: String
homepage: String
signature: InputSignature

"""The package icon"""
icon: String
private: Boolean = false
clientMutationId: String
}

type UpdatePackagePayload {
package: Package!
clientMutationId: String
Expand Down
83 changes: 81 additions & 2 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use crate::{
types::{
self, CreateNamespaceVars, DeployApp, DeployAppConnection, DeployAppVersion,
DeployAppVersionConnection, DnsDomain, GetCurrentUserWithAppsVars, GetDeployAppAndVersion,
GetDeployAppVersionsVars, GetNamespaceAppsVars, Log, LogStream, PackageVersionConnection,
PublishDeployAppVars, UpsertDomainFromZoneFileVars,
GetDeployAppVersionsVars, GetNamespaceAppsVars, GetSignedUrlForPackageUploadVariables, Log,
LogStream, PackageVersionConnection, PublishDeployAppVars, PushPackageReleasePayload,
SignedUrl, TagPackageReleasePayload, UpsertDomainFromZoneFileVars,
},
GraphQLApiFailure, WasmerClient,
};
Expand Down Expand Up @@ -54,6 +55,84 @@ pub async fn fetch_webc_package(
webc::compat::Container::from_bytes(data).context("failed to parse webc package")
}

/// Get a signed URL to upload packages.
pub async fn get_signed_url_for_package_upload(
client: &WasmerClient,
expires_after_seconds: Option<i32>,
filename: Option<&str>,
name: Option<&str>,
version: Option<&str>,
) -> Result<Option<SignedUrl>, anyhow::Error> {
client
.run_graphql(types::GetSignedUrlForPackageUpload::build(
GetSignedUrlForPackageUploadVariables {
expires_after_seconds,
filename,
name,
version,
},
))
.await
.map(|r| r.get_signed_url_for_package_upload)
}
/// Push a package to the registry.
pub async fn push_package_release(
client: &WasmerClient,
name: Option<&str>,
namespace: &str,
signed_url: &str,
private: Option<bool>,
) -> Result<Option<PushPackageReleasePayload>, anyhow::Error> {
client
.run_graphql_strict(types::PushPackageRelease::build(
types::PushPackageReleaseVariables {
name,
namespace,
private,
signed_url,
},
))
.await
.map(|r| r.push_package_release)
}

#[allow(clippy::too_many_arguments)]
pub async fn tag_package_release(
client: &WasmerClient,
description: Option<&str>,
homepage: Option<&str>,
license: Option<&str>,
license_file: Option<&str>,
manifest: &str,
name: &str,
namespace: Option<&str>,
package_release_id: &cynic::Id,
private: Option<bool>,
readme: Option<&str>,
repository: Option<&str>,
version: &str,
) -> Result<Option<TagPackageReleasePayload>, anyhow::Error> {
client
.run_graphql_strict(types::TagPackageRelease::build(
types::TagPackageReleaseVariables {
description,
homepage,
license,
license_file,
manifest,
name,
namespace,
package_release_id,
private,
readme,
repository,
version,
},
))
.await
.map(|r| r.tag_package_release)
}

/// Get the currently logged in used, together with all accessible namespaces.
///
/// You can optionally filter the namespaces by the user role.
Expand Down
95 changes: 79 additions & 16 deletions lib/backend-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ mod queries {
V3,
}

#[derive(cynic::Enum, Clone, Copy, Debug)]
pub enum RegistryWebcImageVersionChoices {
V2,
V3,
}

impl From<RegistryWebcImageVersionChoices> for WebcVersion {
fn from(v: RegistryWebcImageVersionChoices) -> Self {
match v {
RegistryWebcImageVersionChoices::V2 => WebcVersion::V2,
RegistryWebcImageVersionChoices::V3 => WebcVersion::V3,
}
}
}

#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
pub struct WebcImage {
pub created_at: DateTime,
Expand All @@ -106,7 +91,7 @@ mod queries {
pub webc_sha256: String,
pub file_size: BigInt,
pub manifest: JSONString,
pub version: RegistryWebcImageVersionChoices,
pub version: Option<WebcVersion>,
}

#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
Expand Down Expand Up @@ -184,6 +169,61 @@ mod queries {
Oldest,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct PushPackageReleaseVariables<'a> {
pub name: Option<&'a str>,
pub namespace: &'a str,
pub private: Option<bool>,
pub signed_url: &'a str,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "PushPackageReleaseVariables")]
pub struct PushPackageRelease {
#[arguments(input: { name: $name, namespace: $namespace, private: $private, signedUrl: $signed_url })]
pub push_package_release: Option<PushPackageReleasePayload>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct PushPackageReleasePayload {
pub package_webc: Option<PackageWebc>,
pub success: bool,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct TagPackageReleaseVariables<'a> {
pub description: Option<&'a str>,
pub homepage: Option<&'a str>,
pub license: Option<&'a str>,
pub license_file: Option<&'a str>,
pub manifest: &'a str,
pub name: &'a str,
pub namespace: Option<&'a str>,
pub package_release_id: &'a cynic::Id,
pub private: Option<bool>,
pub readme: Option<&'a str>,
pub repository: Option<&'a str>,
pub version: &'a str,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "TagPackageReleaseVariables")]
pub struct TagPackageRelease {
#[arguments(input: { description: $description, homepage: $homepage, license: $license, licenseFile: $license_file, manifest: $manifest, name: $name, namespace: $namespace, packageReleaseId: $package_release_id, private: $private, readme: $readme, repository: $repository, version: $version })]
pub tag_package_release: Option<TagPackageReleasePayload>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct TagPackageReleasePayload {
pub success: bool,
}

#[derive(cynic::InputObject, Debug)]
pub struct InputSignature<'a> {
pub public_key_key_id: &'a str,
pub data: &'a str,
}

#[derive(cynic::QueryVariables, Debug, Clone, Default)]
pub struct AllPackageVersionsVars {
pub offset: Option<i32>,
Expand Down Expand Up @@ -253,6 +293,29 @@ mod queries {
}
}

#[derive(cynic::QueryVariables, Debug)]
pub struct GetSignedUrlForPackageUploadVariables<'a> {
pub expires_after_seconds: Option<i32>,
pub filename: Option<&'a str>,
pub name: Option<&'a str>,
pub version: Option<&'a str>,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
graphql_type = "Query",
variables = "GetSignedUrlForPackageUploadVariables"
)]
pub struct GetSignedUrlForPackageUpload {
#[arguments(name: $name, version: $version, filename: $filename, expiresAfterSeconds: $expires_after_seconds)]
pub get_signed_url_for_package_upload: Option<SignedUrl>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct SignedUrl {
pub url: String,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct PackageWebcConnection {
pub page_info: PageInfo,
Expand Down
Loading
Loading