Skip to content

Commit

Permalink
chore(infra): Add verbose flag to deploy step (#5042)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equartey authored Jun 24, 2024
1 parent 0c48b66 commit 161f73a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions infra-gen2/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ environment:

dependencies:
amplify_core: any
args: ^2.5.0
path: ">=1.8.0 <2.0.0"

dev_dependencies:
Expand Down
6 changes: 6 additions & 0 deletions infra-gen2/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
45 changes: 35 additions & 10 deletions infra-gen2/tool/deploy_gen2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,7 +53,10 @@ const List<AmplifyBackendGroup> infraConfig = [

const pathToBackends = 'infra-gen2/backends';

void main() {
void main(List<String> arguments) async {
final args = _parseArgs(arguments);
final verbose = args.flag('verbose');

final bucketNames = <String>[];
print('🚀 Deploying Gen 2 backends!');
for (final backendGroup in infraConfig) {
Expand All @@ -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
Expand Down Expand Up @@ -135,18 +140,31 @@ void main() {
print('🪣 S3 Bucket Names: $bucketNames');
}

ArgResults _parseArgs(List<String> 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<void> _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',
Expand All @@ -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(
Expand Down

0 comments on commit 161f73a

Please sign in to comment.