Skip to content

Commit

Permalink
Option to use dockerized worker in fake_server analysis + cleanup. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 2, 2024
1 parent 9b2306f commit 4b8e6d7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 117 deletions.
26 changes: 22 additions & 4 deletions app/lib/fake/tool/init_data_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:_pub_shared/data/task_payload.dart';
import 'package:_pub_shared/worker/docker_utils.dart';
import 'package:args/command_runner.dart';
import 'package:gcloud/service_scope.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -41,8 +42,9 @@ class FakeInitDataFileCommand extends Command {
)
..addOption(
'analysis',
allowed: ['none', 'fake', 'real'],
help: 'Analyze the package with fake or real analysis.',
allowed: ['none', 'fake', 'local', 'worker'],
help:
'Analyze the package with fake, local or dockerized worker analysis.',
defaultsTo: 'none',
)
..addOption('data-file', help: 'The file to store the local state.');
Expand Down Expand Up @@ -88,7 +90,9 @@ class FakeInitDataFileCommand extends Command {
: ImportSource.autoGenerated(),
);

if (analysis == 'real') {
if (analysis == 'local') {
await _analyzeLocal();
} else if (analysis == 'worker') {
await _analyzeWorker();
} else if (analysis == 'fake') {
await processTasksWithFakePanaAndDartdoc();
Expand All @@ -98,7 +102,7 @@ class FakeInitDataFileCommand extends Command {
}
}

Future<void> _analyzeWorker() async {
Future<void> _analyzeLocal() async {
await fork(() async {
await taskBackend.backfillAndProcessAllPackages((Payload payload) async {
final arguments = [json.encode(payload.toJson())];
Expand All @@ -113,3 +117,17 @@ Future<void> _analyzeWorker() async {
});
});
}

Future<void> _analyzeWorker() async {
await buildDockerImage();
await fork(() async {
await taskBackend.backfillAndProcessAllPackages((Payload payload) async {
final p = await startDockerAnalysis(payload);
final exitCode = await p.exitCode;
if (exitCode != 0) {
throw Exception(
'Failed to analyze ${payload.package} with exitCode $exitCode');
}
});
});
}
12 changes: 7 additions & 5 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ Using the test-profile above, the following process will:
cd app/
dart bin/fake_server.dart init-data-file \
--test-profile=[the file you have created] \
--analysis=[ none | fake | real ] \
--analysis=[ none | fake | local | worker ] \
--data-file=dev-data-file.jsonl
```

`fake` analysis will use a deterministic, but random-looking
process to create analysis results quickly, while `real`
analysis will run `pana` and `dartdoc` the same way as the
production server would run them.
- `fake` analysis will use a deterministic, but random-looking
process to create analysis results quickly.
- `local` analysis will use the locally available SDKs from `PATH`.
- `worker` analysis will run `pana` and `dartdoc` inside a docker container,
similarly as the production server would run them, using the configured
SDK versions.

### Using the fake server with the data file

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:convert';
import 'dart:io';

import 'package:pub_worker/payload.dart';
import 'package:_pub_shared/data/task_payload.dart';

final _ciEnv = Platform.environment['CI']?.toLowerCase();
final _isRunningOnCI = _ciEnv == 'true' || _ciEnv == '1';
Expand Down
1 change: 0 additions & 1 deletion pkg/pub_worker/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
targets:
$default:
sources:
- 'lib/payload.dart'
- 'lib/pana_report.dart'
- 'lib/src/testing/server.dart'
70 changes: 0 additions & 70 deletions pkg/pub_worker/lib/payload.dart

This file was deleted.

32 changes: 0 additions & 32 deletions pkg/pub_worker/lib/payload.g.dart

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/pub_worker/test/dockerized_end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import 'dart:convert';
import 'dart:io';

import 'package:_pub_shared/data/task_payload.dart';
import 'package:_pub_shared/worker/docker_utils.dart';
import 'package:http/http.dart' as http;
import 'package:pana/pana.dart';
import 'package:pub_worker/payload.dart';
import 'package:pub_worker/src/testing/docker_utils.dart';
import 'package:pub_worker/src/testing/server.dart';
import 'package:test/test.dart';

Expand Down
4 changes: 2 additions & 2 deletions pkg/pub_worker/tool/trypkg.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:convert';
import 'dart:io';

import 'package:_pub_shared/data/task_payload.dart';
import 'package:_pub_shared/worker/docker_utils.dart';
import 'package:args/args.dart';
import 'package:path/path.dart' as p;
import 'package:pub_worker/payload.dart';
import 'package:pub_worker/src/testing/docker_utils.dart';
import 'package:pub_worker/src/testing/server.dart';

final _argParser = ArgParser()
Expand Down

0 comments on commit 4b8e6d7

Please sign in to comment.