From 57fe805c91d4e7f6ec1044c04d26a33cdb2f8cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20ATA=C3=87?= Date: Mon, 15 Apr 2024 00:47:23 +0300 Subject: [PATCH 1/6] added port to build --- .../__brick__/build/bin/server.dart | 2 +- .../lib/src/commands/build/build.dart | 22 ++++++++++++++----- .../dart_frog_prod_server_bundle.dart | 2 +- .../prod_server_builder.dart | 6 +++++ .../test/src/commands/build/build_test.dart | 2 ++ .../prod_server_builder_test.dart | 3 +++ 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/bricks/dart_frog_prod_server/__brick__/build/bin/server.dart b/bricks/dart_frog_prod_server/__brick__/build/bin/server.dart index 7107f9e5c..9cd1cf4d5 100644 --- a/bricks/dart_frog_prod_server/__brick__/build/bin/server.dart +++ b/bricks/dart_frog_prod_server/__brick__/build/bin/server.dart @@ -12,7 +12,7 @@ import 'package:dart_frog/dart_frog.dart'; {{/middleware}} void main() async { final address = InternetAddress.anyIPv6; - final port = int.tryParse(Platform.environment['PORT'] ?? '8080') ?? 8080;{{#invokeCustomInit}} + final port = int.tryParse(Platform.environment['PORT'] ?? '{{{port}}}') ?? {{{port}}};{{#invokeCustomInit}} await entrypoint.init(address, port);{{/invokeCustomInit}} createServer(address, port); } diff --git a/packages/dart_frog_cli/lib/src/commands/build/build.dart b/packages/dart_frog_cli/lib/src/commands/build/build.dart index a6de875a2..2cfbc7de6 100644 --- a/packages/dart_frog_cli/lib/src/commands/build/build.dart +++ b/packages/dart_frog_cli/lib/src/commands/build/build.dart @@ -18,12 +18,19 @@ class BuildCommand extends DartFrogCommand { }) : _generator = generator ?? MasonGenerator.fromBundle, _prodServerBuilderConstructor = prodServerBuilderConstructor ?? ProdServerBuilder.new { - argParser.addOption( - 'dart-version', - defaultsTo: 'stable', - help: 'The Dart SDK version used to build the Dockerfile, defaults to' - ' stable.', - ); + argParser + ..addOption( + 'dart-version', + defaultsTo: 'stable', + help: 'The Dart SDK version used to build the Dockerfile, defaults to' + ' stable.', + ) + ..addOption( + 'port', + abbr: 'p', + defaultsTo: '8080', + help: 'Which port number the server should start on.', + ); } final GeneratorBuilder _generator; @@ -38,11 +45,14 @@ class BuildCommand extends DartFrogCommand { @override Future run() async { final dartVersion = results['dart-version'] as String; + final port = (results['port'] as String?) ?? '8080'; + final generator = await _generator(dartFrogProdServerBundle); final builder = _prodServerBuilderConstructor( logger: logger, dartVersion: dartVersion, + port: port, workingDirectory: cwd, prodServerBundleGenerator: generator, ); diff --git a/packages/dart_frog_cli/lib/src/commands/build/templates/dart_frog_prod_server_bundle.dart b/packages/dart_frog_cli/lib/src/commands/build/templates/dart_frog_prod_server_bundle.dart index 6b1d717b2..1a9df2e58 100644 --- a/packages/dart_frog_cli/lib/src/commands/build/templates/dart_frog_prod_server_bundle.dart +++ b/packages/dart_frog_cli/lib/src/commands/build/templates/dart_frog_prod_server_bundle.dart @@ -14,7 +14,7 @@ final dartFrogProdServerBundle = MasonBundle.fromJson({ { "path": "build/bin/server.dart", "data": - "Ly8gR0VORVJBVEVEIENPREUgLSBETyBOT1QgTU9ESUZZIEJZIEhBTkQKLy8gaWdub3JlX2Zvcl9maWxlOiB0eXBlPWxpbnQsIGltcGxpY2l0X2R5bmFtaWNfbGlzdF9saXRlcmFsCgppbXBvcnQgJ2RhcnQ6aW8nOwoKaW1wb3J0ICdwYWNrYWdlOmRhcnRfZnJvZy9kYXJ0X2Zyb2cuZGFydCc7Cgp7eyNpbnZva2VDdXN0b21FbnRyeXBvaW50fX1pbXBvcnQgJy4uL21haW4uZGFydCcgYXMgZW50cnlwb2ludDt7ey9pbnZva2VDdXN0b21FbnRyeXBvaW50fX0Ke3sjcm91dGVzfX1pbXBvcnQgJ3t7e3BhdGh9fX0nIGFzIHt7I3NuYWtlQ2FzZX19e3t7bmFtZX19fXt7L3NuYWtlQ2FzZX19Owp7ey9yb3V0ZXN9fQp7eyNtaWRkbGV3YXJlfX1pbXBvcnQgJ3t7e3BhdGh9fX0nIGFzI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WwgcGlwZWxpbmUgPSBjb25zdCBQaXBlbGluZSgpe3sjbWlkZGxld2FyZS4wfX17eyNtaWRkbGV3YXJlfX0uYWRkTWlkZGxld2FyZSh7eyNzbmFrZUNhc2V9fXt7e25hbWV9fX17ey9zbmFrZUNhc2V9fS5taWRkbGV3YXJlKXt7L21pZGRsZXdhcmV9fXt7L21pZGRsZXdhcmUuMH19OwogIGZpbmFsIHJvdXRlciA9IFJvdXRlcigpCiAgICB7eyNmaWxlc319e3sjd2lsZGNhcmR9fS4ubW91bnQoJ3t7e3JvdXRlfX19JywgKGNvbnRleHQpID0+IHt7I3NuYWtlQ2FzZX19e3t7bmFtZX19fXt7L3NuYWtlQ2FzZX19Lm9uUmVxdWVzdChjb250ZXh0LGNvbnRleHQucmVxdWVzdC51cmwucGF0aCkpe3svd2lsZGNhcmR9fXt7XndpbGRjYXJkfX0uLmFsbCgne3t7cm91dGV9fX0nLCAoY29udGV4dHt7I2ZpbGVfcGFyYW1zLjB9fSx7eyNmaWxlX3BhcmFtc319e3sufX0se3svZmlsZV9wYXJhbXN9fXt7L2ZpbGVfcGFyYW1zLjB9fSkgPT4ge3sjc25ha2VDYXNlfX17e3tuYW1lfX19e3svc25ha2VDYXNlfX0ub25SZXF1ZXN0KGNvbnRleHQse3sjZGlyZWN0b3J5X3BhcmFtc319e3sufX0se3svZGlyZWN0b3J5X3BhcmFtc319e3sjZmlsZV9wYXJhbXN9fXt7Ln19LHt7L2ZpbGVfcGFyYW1zfX0pKXt7L3dpbGRjYXJkfX17ey9maWxlc319OwogIHJldHVybiBwaXBlbGluZS5hZGRIYW5kbGVyKHJvdXRlcik7Cn0Ke3svZGlyZWN0b3JpZXN9fQo=", "type": "text" }, { diff --git a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart index 34c5d387f..52d213f4f 100644 --- a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart +++ b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart @@ -8,6 +8,7 @@ import 'package:meta/meta.dart'; typedef ProdServerBuilderConstructor = ProdServerBuilder Function({ required Logger logger, required String dartVersion, + required String port, required io.Directory workingDirectory, required MasonGenerator prodServerBundleGenerator, }); @@ -26,6 +27,7 @@ class ProdServerBuilder { ProdServerBuilder({ required this.logger, required this.dartVersion, + required this.port, required this.workingDirectory, required this.prodServerBundleGenerator, @visibleForTesting @@ -36,6 +38,9 @@ class ProdServerBuilder { /// The Dart SDK version used to build the Dockerfile. final String dartVersion; + /// The port number the server should start on. + final String port; + /// [Logger] instance used to wrap stdout. final Logger logger; @@ -53,6 +58,7 @@ class ProdServerBuilder { var vars = { 'dartVersion': dartVersion, + 'port': port, }; logger.detail('[codegen] running pre-gen...'); diff --git a/packages/dart_frog_cli/test/src/commands/build/build_test.dart b/packages/dart_frog_cli/test/src/commands/build/build_test.dart index 3a5aa3f79..6b55187d6 100644 --- a/packages/dart_frog_cli/test/src/commands/build/build_test.dart +++ b/packages/dart_frog_cli/test/src/commands/build/build_test.dart @@ -57,6 +57,7 @@ void main() { prodServerBuilderConstructor: ({ required Logger logger, required String dartVersion, + required String port, required Directory workingDirectory, required MasonGenerator prodServerBundleGenerator, }) { @@ -87,6 +88,7 @@ void main() { prodServerBuilderConstructor: ({ required Logger logger, required String dartVersion, + required String port, required Directory workingDirectory, required MasonGenerator prodServerBundleGenerator, }) => diff --git a/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart b/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart index f90a9c215..58bd7d18b 100644 --- a/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart +++ b/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart @@ -40,6 +40,7 @@ void main() { logger: logger, prodServerBundleGenerator: generator, dartVersion: 'stable', + port: '8080', workingDirectory: Directory.current, ), isNotNull, @@ -51,6 +52,7 @@ void main() { final builder = ProdServerBuilder( logger: logger, dartVersion: 'stable', + port: '8080', workingDirectory: Directory.current, prodServerBundleGenerator: generator, runtimeCompatibilityCallback: (_) { @@ -91,6 +93,7 @@ void main() { logger: logger, prodServerBundleGenerator: generator, dartVersion: 'stable', + port: '8080', workingDirectory: Directory.current, runtimeCompatibilityCallback: (_) {}, ); From fa6716af8e3c9df4869b4945922955ca26e96571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20ATA=C3=87?= Date: Mon, 15 Apr 2024 01:47:28 +0300 Subject: [PATCH 2/6] affixed variables from arguments for #1327 --- .gitignore | 2 +- .../lib/src/prod_server_builder/prod_server_builder.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 17d453872..9bdb0751f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .idea -.vscode/settings.json +.vscode/ .DS_Store diff --git a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart index 52d213f4f..b418e8c9a 100644 --- a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart +++ b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart @@ -65,7 +65,7 @@ class ProdServerBuilder { await prodServerBundleGenerator.hooks.preGen( vars: vars, workingDirectory: workingDirectory.path, - onVarsChanged: (v) => vars = v, + onVarsChanged: (v) => vars..addAll(v), ); logger.detail('[codegen] running generate...'); From 8b2552da3da779d223184e7644dc4be872498ff8 Mon Sep 17 00:00:00 2001 From: Plato Date: Mon, 15 Apr 2024 18:10:01 +0300 Subject: [PATCH 3/6] fix: vars changed to final vars was initialized with "var" though it should have been "final". --- .../lib/src/prod_server_builder/prod_server_builder.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart index b418e8c9a..2b0ad8d7c 100644 --- a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart +++ b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart @@ -56,7 +56,7 @@ class ProdServerBuilder { Future build() async { _ensureRuntimeCompatibility(workingDirectory); - var vars = { + final vars = { 'dartVersion': dartVersion, 'port': port, }; From 10e31aba5915c20e3bc74464e091e4db5bfc20ba Mon Sep 17 00:00:00 2001 From: Plato Date: Tue, 16 Apr 2024 15:14:46 +0300 Subject: [PATCH 4/6] fix: modified prod_server_builder_test to include port number in the "vars" When there are no "port" number defined in this test, it causes error. This fixes it. --- .../src/prod_server_builder/prod_server_builder_test.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart b/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart index 58bd7d18b..1de0eca47 100644 --- a/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart +++ b/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart @@ -66,19 +66,19 @@ void main() { final generatorHooks = _MockGeneratorHooks(); when( () => generatorHooks.preGen( - vars: {'dartVersion': 'stable'}, + vars: {'dartVersion': 'stable', 'port': '8080'}, workingDirectory: any(named: 'workingDirectory'), onVarsChanged: any(named: 'onVarsChanged'), ), ).thenAnswer((invocation) async { (invocation.namedArguments[const Symbol('onVarsChanged')] as void Function(Map)) - .call({'dartVersion': 'stable'}); + .call({'dartVersion': 'stable', 'port': '8080'}); }); when( () => generator.generate( any(), - vars: {'dartVersion': 'stable'}, + vars: {'dartVersion': 'stable', 'port': '8080'}, fileConflictResolution: FileConflictResolution.overwrite, ), ).thenAnswer((_) async => []); From 05e941419d3148e84fa7998362f71da49a4c402f Mon Sep 17 00:00:00 2001 From: Plato Date: Thu, 25 Apr 2024 09:15:54 +0300 Subject: [PATCH 5/6] fix: port parameter is default to 8080 in ProdServerBuilder Set the port parameter to 8080 if it's not supplied. This fixes the problems with tests which don't provide port number. --- .../lib/src/prod_server_builder/prod_server_builder.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart index 2b0ad8d7c..7c3df886f 100644 --- a/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart +++ b/packages/dart_frog_cli/lib/src/prod_server_builder/prod_server_builder.dart @@ -27,9 +27,9 @@ class ProdServerBuilder { ProdServerBuilder({ required this.logger, required this.dartVersion, - required this.port, required this.workingDirectory, required this.prodServerBundleGenerator, + this.port = '8080', @visibleForTesting RuntimeCompatibilityCallback? runtimeCompatibilityCallback, }) : _ensureRuntimeCompatibility = From 7343e52aa0cfa068d9c8f17eb60b123d34dfc140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20ATA=C3=87?= Date: Thu, 25 Apr 2024 09:20:32 +0300 Subject: [PATCH 6/6] fix: removed warnings about redundant port parameter after it's set to default --- .../test/src/prod_server_builder/prod_server_builder_test.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart b/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart index 1de0eca47..c9f667ec3 100644 --- a/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart +++ b/packages/dart_frog_cli/test/src/prod_server_builder/prod_server_builder_test.dart @@ -40,7 +40,6 @@ void main() { logger: logger, prodServerBundleGenerator: generator, dartVersion: 'stable', - port: '8080', workingDirectory: Directory.current, ), isNotNull, @@ -52,7 +51,6 @@ void main() { final builder = ProdServerBuilder( logger: logger, dartVersion: 'stable', - port: '8080', workingDirectory: Directory.current, prodServerBundleGenerator: generator, runtimeCompatibilityCallback: (_) { @@ -93,7 +91,6 @@ void main() { logger: logger, prodServerBundleGenerator: generator, dartVersion: 'stable', - port: '8080', workingDirectory: Directory.current, runtimeCompatibilityCallback: (_) {}, );