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

Implement app-deployment related CLI commands #5144

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
207 changes: 206 additions & 1 deletion lib/backend-api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type User implements Node & PackageOwner & Owner {
loginMethods: [LoginMethod!]!
githubUser: SocialAuth
githubScopes: [String]!
githubRepositories: [GithubRepository]!
}

"""Setup for backwards compatibility with existing frontends."""
Expand Down Expand Up @@ -949,12 +950,14 @@ type DeployApp implements Node & Owner {
aggregateMetrics: AggregateMetrics!
aliases(offset: Int, before: String, after: String, first: Int, last: Int): AppAliasConnection!
secrets(offset: Int, before: String, after: String, first: Int, last: Int): SecretConnection!
databases(offset: Int, before: String, after: String, first: Int, last: Int): AppDatabaseConnection!
usageMetrics(forRange: MetricRange!, variant: MetricType!): [UsageMetric]!
s3Url: URL
s3Credentials: S3Credentials
deleted: Boolean!
favicon: URL
screenshot(viewportSize: AppScreenshotViewportSize, appearance: AppScreenshotAppearance): URL
deployments(offset: Int, before: String, after: String, first: Int, last: Int): AutobuildRepositoryConnection
}

enum DeployAppVersionsSortBy {
Expand Down Expand Up @@ -1042,6 +1045,39 @@ type Secret implements Node {
id: ID!
}

type AppDatabaseConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!

"""Contains the nodes in this connection."""
edges: [AppDatabaseEdge]!

"""Total number of items in the connection."""
totalCount: Int
}

"""A Relay edge containing a `AppDatabase` and its cursor."""
type AppDatabaseEdge {
"""The item at the end of the edge"""
node: AppDatabase

"""A cursor for use in pagination"""
cursor: String!
}

type AppDatabase implements Node {
createdAt: DateTime!
updatedAt: DateTime!
deletedAt: DateTime
name: String!
username: String!
app: DeployApp!

"""The ID of the object"""
id: ID!
host: String!
}

type UsageMetric {
variant: MetricType!
value: Float!
Expand Down Expand Up @@ -1108,6 +1144,59 @@ enum AppScreenshotAppearance {
DARK
}

type AutobuildRepositoryConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!

"""Contains the nodes in this connection."""
edges: [AutobuildRepositoryEdge]!

"""Total number of items in the connection."""
totalCount: Int
}

"""A Relay edge containing a `AutobuildRepository` and its cursor."""
type AutobuildRepositoryEdge {
"""The item at the end of the edge"""
node: AutobuildRepository

"""A cursor for use in pagination"""
cursor: String!
}

type AutobuildRepository implements Node {
"""The ID of the object"""
id: ID!
user: User!
name: String!
namespace: String!
app: DeployApp
createdAt: DateTime!
updatedAt: DateTime!
appName: String
buildId: UUID!
repoUrl: String!
status: StatusEnum!
appVersion: DeployAppVersion
logUrl: String
}

"""
Leverages the internal Python implementation of UUID (uuid.UUID) to provide native UUID objects
in fields, resolvers and input.
"""
scalar UUID

enum StatusEnum {
SUCCESS
WORKING
FAILURE
QUEUED
TIMEOUT
INTERNAL_ERROR
CANCELLED
}

type LogConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!
Expand Down Expand Up @@ -1136,7 +1225,7 @@ type AppVersionVolume {
name: String!
s3Url: String!
mountPaths: [AppVersionVolumeMountPath]!
size: Int
size: BigInt
usedSize: BigInt
}

Expand Down Expand Up @@ -2066,6 +2155,12 @@ type SocialAuth implements Node {
username: String!
}

type GithubRepository {
url: String!
name: String!
namespace: String!
}

type Signature {
id: ID!
publicKey: PublicKey!
Expand Down Expand Up @@ -2360,6 +2455,7 @@ type Query {
getSecretValue(id: ID!): String
getAppTemplate(slug: String!): AppTemplate
getAppTemplateCategories(offset: Int, before: String, after: String, first: Int, last: Int): AppTemplateCategoryConnection
getBuildKinds(offset: Int, before: String, after: String, first: Int, last: Int): BuildKindConnection!
viewer: User
getUser(username: String!): User
getPasswordResetToken(token: String!): GetPasswordResetToken
Expand Down Expand Up @@ -2596,6 +2692,36 @@ type AppTemplateCategoryEdge {
cursor: String!
}

type BuildKindConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!

"""Contains the nodes in this connection."""
edges: [BuildKindEdge]!

"""Total number of items in the connection."""
totalCount: Int
}

"""A Relay edge containing a `BuildKind` and its cursor."""
type BuildKindEdge {
"""The item at the end of the edge"""
node: BuildKind

"""A cursor for use in pagination"""
cursor: String!
}

type BuildKind implements Node {
name: String!
setupDb: Boolean!
buildCmd: String!
installCmd: String!

"""The ID of the object"""
id: ID!
}

type GetPasswordResetToken {
valid: Boolean!
user: User
Expand Down Expand Up @@ -3049,6 +3175,15 @@ type Mutation {

"""Redeploy the active version of an app."""
rotateS3SecretsForApp(input: RotateS3SecretsForAppInput!): RotateS3SecretsForAppPayload

"""Delete a database for an app."""
rotateCredentialsForAppDb(input: RotateCredentialsForAppDBInput!): RotateCredentialsForAppDBPayload

"""Create a new database for an app."""
createAppDb(input: CreateAppDBInput!): CreateAppDBPayload

"""Delete a database for an app."""
deleteAppDb(input: DeleteAppDBInput!): DeleteAppDBPayload
tokenAuth(input: ObtainJSONWebTokenInput!): ObtainJSONWebTokenPayload
generateDeployToken(input: GenerateDeployTokenInput!): GenerateDeployTokenPayload
verifyAccessToken(token: String): Verify
Expand Down Expand Up @@ -3532,6 +3667,47 @@ input RotateS3SecretsForAppInput {
clientMutationId: String
}

"""Delete a database for an app."""
type RotateCredentialsForAppDBPayload {
database: AppDatabase!
password: String!
clientMutationId: String
}

input RotateCredentialsForAppDBInput {
"""App Database ID"""
id: ID!
clientMutationId: String
}

"""Create a new database for an app."""
type CreateAppDBPayload {
database: AppDatabase!
password: String!
clientMutationId: String
}

input CreateAppDBInput {
"""App ID"""
id: ID!

"""Database name"""
name: String!
clientMutationId: String
}

"""Delete a database for an app."""
type DeleteAppDBPayload {
success: Boolean!
clientMutationId: String
}

input DeleteAppDBInput {
"""App Database ID"""
id: ID!
clientMutationId: String
}

type ObtainJSONWebTokenPayload {
payload: GenericScalar!
refreshExpiresIn: Int!
Expand Down Expand Up @@ -4382,13 +4558,42 @@ type Subscription {
): Log!
waitOnRepoCreation(repoId: ID!): Boolean!
appIsPublishedFromRepo(repoId: ID!): DeployAppVersion!
publishAppFromRepoAutobuild(repoUrl: String!, appName: String!, owner: String, buildCmd: String, installCmd: String, databaseName: String, secrets: [SecretInput]): AutobuildLog
fetchBuildLogs(buildId: String!): String
autobuildConfigForRepo(repoUrl: String!): BuildConfig
packageVersionCreated(publishedBy: ID, ownerId: ID): PackageVersion!

"""Subscribe to package version ready"""
packageVersionReady(packageVersionId: ID!): PackageVersionReadyResponse!
userNotificationCreated(userId: ID!): UserNotificationCreated!
}

"""Log entry for Deploying app from github repo"""
type AutobuildLog {
"""Kind of log message."""
kind: AutoBuildDeployAppLogKind!

"""Log message"""
message: String
appVersion: DeployAppVersion

"""The database password, if DB was setup."""
dbPassword: String
}

enum AutoBuildDeployAppLogKind {
LOG
COMPLETE
}

"""Log entry for Deploying app from github repo"""
type BuildConfig {
buildCmd: String!
installCmd: String!
setupDb: Boolean!
presetName: String!
}

type PackageVersionReadyResponse {
state: PackageVersionState!
packageVersion: PackageVersion!
Expand Down
35 changes: 35 additions & 0 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,41 @@ pub async fn get_deploy_app_versions(
Ok(versions)
}

/// Get app deployments for an app.
pub async fn app_deployments(
client: &WasmerClient,
vars: types::GetAppDeploymentsVariables,
) -> Result<Vec<types::AutobuildRepository>, anyhow::Error> {
let res = client
.run_graphql_strict(types::GetAppDeployments::build(vars))
.await?;
let builds = res
.get_deploy_app
.and_then(|x| x.deployments)
.context("no data returned")?
.edges
.into_iter()
.flatten()
.filter_map(|x| x.node)
.collect();

Ok(builds)
}

/// Get an app deployment by ID.
pub async fn app_deployment(
client: &WasmerClient,
id: String,
) -> Result<types::AutobuildRepository, anyhow::Error> {
let node = get_node(client, id.clone())
.await?
.with_context(|| format!("app deployment with id '{}' not found", id))?;
match node {
types::Node::AutobuildRepository(x) => Ok(*x),
_ => anyhow::bail!("invalid node type returned"),
}
}

/// Load all versions of an app.
///
/// Will paginate through all versions and return them in a single list.
Expand Down
Loading
Loading