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
7 changes: 7 additions & 0 deletions apps/cli/lib/src/analyzer/resolver/project_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ final class CelestProjectResolver with CelestAnalysisHelpers {
String? projectName;
String? projectDisplayName;
ast.Region? projectRegion;
String? productionUrl;
String? variableName;
FileSpan? projectDefineLocation;

Expand Down Expand Up @@ -273,6 +274,11 @@ final class CelestProjectResolver with CelestAnalysisHelpers {
),
):
projectRegion = ast.Region.valueOf(region);
case NamedExpression(
name: Label(label: SimpleIdentifier(name: 'productionUrl')),
expression: SimpleStringLiteral(:final value)
):
productionUrl = value;
default:
performance.captureError(
FormatException(
Expand Down Expand Up @@ -310,6 +316,7 @@ final class CelestProjectResolver with CelestAnalysisHelpers {
// Environment is provided by the CLI flag so resolved projects target
// the correct configuration bundle.
displayName: projectDisplayName,
productionUrl: productionUrl,
primaryRegion: projectRegion,
reference: refer(
variableName!,
Expand Down
27 changes: 24 additions & 3 deletions apps/cli/lib/src/frontend/celest_frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,14 @@ final class CelestFrontend with CloudRepository {
project.name,
localUri,
),
productionUri: await isolatedSecureStorage.getProductionUri(
project.name,
),
productionUri: project.productionUrl != null
? await isolatedSecureStorage.setProductionUri(
project.name,
Uri.parse(project.productionUrl!),
)
: await isolatedSecureStorage.getProductionUri(
project.name,
),
),
);

Expand Down Expand Up @@ -646,6 +651,21 @@ final class CelestFrontend with CloudRepository {
performance.captureError(e, stackTrace: st);
return 1;
}
// During build with Dockerfile, it's useful to also regenerate client code
// so that the production url can be captured too.
await _generateClientCode(
project: project,
resolvedProject: resolvedProject,
projectUris: (
localUri: await isolatedSecureStorage.getLocalUri(project.name),
productionUri: project.productionUrl != null
? await isolatedSecureStorage.setProductionUri(
project.name,
Uri.parse(project.productionUrl!),
)
: await isolatedSecureStorage.getProductionUri(project.name),
),
);

currentProgress.complete(
'Celest project has been built for deployment',
Expand Down Expand Up @@ -1086,6 +1106,7 @@ final class CelestFrontend with CloudRepository {
);
});

/// Generates client code for [project] and writes to the [project] client directory.
Future<void> _generateClientCode({
required ast.Project project,
required ast.ResolvedProject resolvedProject,
Expand Down
9 changes: 8 additions & 1 deletion packages/celest/lib/src/core/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:celest/src/core/cloud_widget.dart';
/// {@endtemplate}
class Project implements CloudWidget {
/// {@macro celest.core.project}
const Project({required this.name, this.displayName, this.region});
const Project({required this.name, this.displayName, this.region, this.productionUrl,});

/// The name of the project as its identified in your Celest backend.
final String name;
Expand All @@ -22,6 +22,13 @@ class Project implements CloudWidget {
/// If not specified, the closest region will be chosen at the time of
/// deployment.
final Region? region;

/// The production URL for self-hosted-deployments.
///
/// When specified this URL will be used as the production endpoint
/// in the generated client code. This is useful for self-hosted
/// deployments where Celest Cloud is not used therefore a production URL is not set
final String? productionUrl;
}

/// The Celest cloud region to deploy to.
Expand Down
3 changes: 3 additions & 0 deletions packages/celest_ast/lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class Project implements Built<Project, ProjectBuilder>, AstNode {
required String environment,
String? displayName,
Region? primaryRegion,
String? productionUrl,
required Reference reference,
required FileSpan location,
Map<String, Api> apis = const {},
Expand All @@ -47,6 +48,7 @@ abstract class Project implements Built<Project, ProjectBuilder>, AstNode {
environment: environment,
displayName: displayName,
primaryRegion: primaryRegion,
productionUrl: productionUrl,
reference: reference,
location: location,
apis: apis.build(),
Expand All @@ -66,6 +68,7 @@ abstract class Project implements Built<Project, ProjectBuilder>, AstNode {
String get environment;
String? get displayName;
Region? get primaryRegion;
String? get productionUrl;
Reference get reference;
BuiltMap<String, Api> get apis;
BuiltList<Variable> get variables;
Expand Down
Loading