From cbe239fee2198127df3492cb9f07096347b7722a Mon Sep 17 00:00:00 2001 From: Elijah Quartey Date: Thu, 20 Jun 2024 10:16:30 -0500 Subject: [PATCH 1/2] chore(infra): Add verbose flag to deploy step --- infra-gen2/pubspec.yaml | 1 + infra-gen2/tool/deploy_gen2.dart | 45 +++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/infra-gen2/pubspec.yaml b/infra-gen2/pubspec.yaml index 74a3373de7..ec07ffb1ce 100644 --- a/infra-gen2/pubspec.yaml +++ b/infra-gen2/pubspec.yaml @@ -6,6 +6,7 @@ environment: dependencies: amplify_core: any + args: ^2.5.0 path: ">=1.8.0 <2.0.0" dev_dependencies: diff --git a/infra-gen2/tool/deploy_gen2.dart b/infra-gen2/tool/deploy_gen2.dart index 7712a4f3d5..f5f8daf2b5 100644 --- a/infra-gen2/tool/deploy_gen2.dart +++ b/infra-gen2/tool/deploy_gen2.dart @@ -8,6 +8,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:amplify_core/amplify_core.dart'; +import 'package:args/args.dart'; import 'package:path/path.dart' as p; /// This is the source of truth for the infra-gen2 backends @@ -52,7 +53,10 @@ const List infraConfig = [ const pathToBackends = 'infra-gen2/backends'; -void main() { +void main(List arguments) async { + final args = _parseArgs(arguments); + final verbose = args.flag('verbose'); + final bucketNames = []; print('🚀 Deploying Gen 2 backends!'); for (final backendGroup in infraConfig) { @@ -73,10 +77,11 @@ void main() { print('🏃 Running sandbox deployment for $categoryName'); for (final backend in backendGroup.backends) { final backendName = backend.name; - _deployBackend( + await _deployBackend( backendGroup.category, backend, amplifyOutputs.path.replaceFirst('amplify_outputs.dart', ''), + verbose, ); // Skip if there is only one backend @@ -135,18 +140,31 @@ void main() { print('🪣 S3 Bucket Names: $bucketNames'); } +ArgResults _parseArgs(List args) { + final parser = ArgParser() + ..addFlag( + 'verbose', + abbr: 'v', + help: 'Run command in verbose mode', + defaultsTo: false, + ); + + return parser.parse(args); +} + /// Deploy Sandbox for a given backend backend -void _deployBackend( +Future _deployBackend( Category category, AmplifyBackend backend, String outputPath, -) { + bool verbose, +) async { print( '🏖️ Deploying ${category.name} ${backend.name}, this may take a while...', ); // Deploy the backend - final deployBackend = Process.runSync( + final process = await Process.start( 'npx', [ 'ampx', @@ -161,13 +179,20 @@ void _deployBackend( '--once', ], workingDirectory: p.join(repoRoot.path, backend.pathToSource), - stdoutEncoding: utf8, - stderrEncoding: utf8, ); - if (deployBackend.exitCode != 0) { + + if (verbose) { + process.stdout.transform(const SystemEncoding().decoder).listen(print); + process.stderr.transform(const SystemEncoding().decoder).listen((data) { + print('❌ Error: $data'); + }); + } + + final exitCode = await process.exitCode; + + if (exitCode != 0) { throw Exception( - '❌ Error deploying ${category.name}: ' - '${deployBackend.stdout}\n${deployBackend.stderr}', + '❌ Error deploying ${category.name} ${backend.identifier} sandbox', ); } else { print( From c809dbb6ac946bc41f23c76f06f09ae0bbeb6287 Mon Sep 17 00:00:00 2001 From: Elijah Quartey Date: Thu, 20 Jun 2024 10:18:43 -0500 Subject: [PATCH 2/2] chore: updated readme --- infra-gen2/readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/infra-gen2/readme.md b/infra-gen2/readme.md index b49121ce5b..c6bfa53bc4 100644 --- a/infra-gen2/readme.md +++ b/infra-gen2/readme.md @@ -21,6 +21,12 @@ To deploy the infra stack to your personal account simply run: If this is your first deployment, grab a snack, it will be a few minutes for each backend to deploy. +### Debuggings + +The same command can be run with verbose logging + +`$ dart run tool/deploy_gen2.dart -v` + ## Creating a new backend 1. Create a new directory for the backend.