Skip to content

Commit 6093b40

Browse files
committed
only serve from artifacts/ if the directory exists
1 parent 657cac8 commit 6093b40

File tree

8 files changed

+19
-65
lines changed

8 files changed

+19
-65
lines changed

.cloud_build/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ gcloud builds submit \
3535

3636
The substitutions are a comma separated list of `SUBSITUTION=value`:
3737
- `_FLUTTER_CHANNEL` - The Flutter channel to use. (`stable`, `beta`, or `main`)
38-
- `_STORAGE_BUCKET` - The name of the Cloud Storage bucket to use (nnbd_artifacts)
3938
- `_SERVICE_NAME` - The name of the Cloud Run service (dart-services-cloud-run, flutter-beta-channel, or flutter-master-channel)
4039
- `_DEPLOY_REGION` - The region to deploy the Cloud Run service to (us-central1)
4140
- `_REDIS_ADDR` - the IP address of the Redis bucket (10.0.0.4:6379)

.cloud_build/dart_services.yaml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,6 @@ steps:
5151
- FLUTTER_CHANNEL=${_FLUTTER_CHANNEL}
5252
dir: pkgs/dart_services
5353

54-
# Upload storage artifacts
55-
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
56-
id: Upload storage artifacts
57-
entrypoint: bash
58-
args:
59-
- -c
60-
- |
61-
echo "Uploading storage artifact for version $(cat /workspace/dart_version.txt)" && gsutil -h "Cache-Control: public, max-age=604800, immutable" cp -z js artifacts/*.js* gs://${_STORAGE_BUCKET}/$(cat /workspace/dart_version.txt)/
62-
env:
63-
- FLUTTER_CHANNEL=${_FLUTTER_CHANNEL}
64-
dir: pkgs/dart_services
65-
66-
# Validate storage artifacts
67-
- name: gcr.io/$PROJECT_ID/flutter:${_FLUTTER_CHANNEL}
68-
id: Validate storage artifacts
69-
entrypoint: dart
70-
args:
71-
- tool/grind.dart
72-
- validate-storage-artifacts
73-
- --bucket=${_STORAGE_BUCKET}
74-
env:
75-
- FLUTTER_CHANNEL=${_FLUTTER_CHANNEL}
76-
dir: pkgs/dart_services
77-
7854
# Build the container image
7955
- name: 'gcr.io/cloud-builders/docker'
8056
args:
@@ -118,7 +94,7 @@ steps:
11894
- --cpu-boost
11995
- --max-instances=1000
12096
- --command=bin/server
121-
- --args=--redis-url=redis://${_REDIS_ADDR},--storage-bucket=${_STORAGE_BUCKET}
97+
- --args=--redis-url=redis://${_REDIS_ADDR}
12298
dir: pkgs/dart_services
12399
timeout: 1200s
124100
images:

pkgs/dart_services/.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ pubspec.lock
1919
dump.rdb
2020

2121
# compilation artifacts
22-
artifacts/*.dill
23-
artifacts/*.js
24-
artifacts/*.map
22+
artifacts/**
2523
project_templates/
2624
flutter-sdks/
2725
local_pub_cache/

pkgs/dart_services/artifacts/_placeholder.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkgs/dart_services/lib/server.dart

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ Future<void> main(List<String> args) async {
2727
final parser = ArgParser()
2828
..addOption('port', valueHelp: 'port', help: 'The port to listen on.')
2929
..addOption('redis-url', valueHelp: 'url', help: 'The redis server url.')
30-
..addOption(
31-
'storage-bucket',
32-
valueHelp: 'name',
33-
help: 'The name of the Cloud Storage bucket for compilation artifacts.',
34-
defaultsTo: 'nnbd_artifacts',
35-
)
3630
..addFlag(
3731
'help',
3832
abbr: 'h',
@@ -68,8 +62,6 @@ Future<void> main(List<String> args) async {
6862
emitLogsToStdout();
6963

7064
final redisServerUri = results['redis-url'] as String?;
71-
final storageBucket =
72-
results['storage-bucket'] as String? ?? 'nnbd_artifacts';
7365

7466
final cloudRunEnvVars = Platform.environment.entries
7567
.where((entry) => entry.key.startsWith('K_'))
@@ -89,8 +81,7 @@ Starting dart-services:
8981
final server = await EndpointsServer.serve(
9082
port,
9183
sdk,
92-
redisServerUri,
93-
storageBucket,
84+
redisServerUri: redisServerUri,
9485
);
9586

9687
_logger.genericInfo('Listening on port ${server.port}');
@@ -99,15 +90,10 @@ Starting dart-services:
9990
class EndpointsServer {
10091
static Future<EndpointsServer> serve(
10192
int port,
102-
Sdk sdk,
103-
String? redisServerUri,
104-
String storageBucket,
105-
) async {
106-
final endpointsServer = EndpointsServer._(
107-
sdk,
108-
redisServerUri,
109-
storageBucket,
110-
);
93+
Sdk sdk, {
94+
required String? redisServerUri,
95+
}) async {
96+
final endpointsServer = EndpointsServer._(sdk, redisServerUri);
11197
await endpointsServer._init();
11298

11399
endpointsServer.server = await shelf.serve(
@@ -125,7 +111,7 @@ class EndpointsServer {
125111

126112
late final CommonServerApi commonServer;
127113

128-
EndpointsServer._(Sdk sdk, String? redisServerUri, String storageBucket) {
114+
EndpointsServer._(Sdk sdk, String? redisServerUri) {
129115
// The name of the Cloud Run revision being run, for more detail please see:
130116
// https://cloud.google.com/run/docs/reference/container-contract#env-vars
131117
final serverVersion = Platform.environment['K_REVISION'];
@@ -134,9 +120,7 @@ class EndpointsServer {
134120
? NoopCache()
135121
: RedisCache(redisServerUri, sdk, serverVersion);
136122

137-
commonServer = CommonServerApi(
138-
CommonServerImpl(sdk, cache, storageBucket: storageBucket),
139-
);
123+
commonServer = CommonServerApi(CommonServerImpl(sdk, cache));
140124

141125
final pipeline = const Pipeline()
142126
.addMiddleware(logRequestsToLogger(_logger))
@@ -196,7 +180,7 @@ class TestServerRunner {
196180

197181
_started = Completer<void>();
198182
try {
199-
await EndpointsServer.serve(_port, sdk, null, 'nnbd_artifacts');
183+
await EndpointsServer.serve(_port, sdk, redisServerUri: null);
200184
} on SocketException {
201185
// This is expected if the server is already running.
202186
}

pkgs/dart_services/lib/src/common_server.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,21 @@ final log = DartPadLogger('common_server');
3737
class CommonServerImpl {
3838
final Sdk sdk;
3939
final ServerCache cache;
40-
final String storageBucket;
4140

4241
late Analyzer analyzer;
4342
late Compiler compiler;
4443
final ai = GenerativeAI();
4544
final GenUi genui = GenUi();
4645

47-
CommonServerImpl(
48-
this.sdk,
49-
this.cache, {
50-
this.storageBucket = 'nnbd_artifacts',
51-
});
46+
CommonServerImpl(this.sdk, this.cache);
5247

5348
Future<void> init() async {
5449
log.genericFine('initializing CommonServerImpl');
5550

5651
analyzer = Analyzer(sdk);
5752
await analyzer.init();
5853

59-
compiler = Compiler(sdk, storageBucket: storageBucket);
54+
compiler = Compiler(sdk);
6055
}
6156

6257
Future<void> shutdown() async {
@@ -81,7 +76,10 @@ class CommonServerApi {
8176
router.get(r'/api/<apiVersion>/version', handleVersion);
8277

8378
// serve the compiled artifacts
84-
router.mount('/artifacts/', createStaticHandler('artifacts'));
79+
final artifactsDir = Directory('artifacts');
80+
if (artifactsDir.existsSync()) {
81+
router.mount('/artifacts/', createStaticHandler(artifactsDir.path));
82+
}
8583

8684
// general requests (POST)
8785
router.post(r'/api/<apiVersion>/analyze', handleAnalyze);
@@ -103,6 +101,7 @@ class CommonServerApi {
103101
router.post(r'/api/<apiVersion>/generateCode', generateCode);
104102
router.post(r'/api/<apiVersion>/updateCode', updateCode);
105103
router.post(r'/api/<apiVersion>/suggestFix', suggestFix);
104+
106105
return router;
107106
}();
108107

pkgs/dart_services/lib/src/compiling.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class Compiler {
2727

2828
final ProjectTemplates _projectTemplates;
2929

30-
Compiler(Sdk sdk, {required String storageBucket})
31-
: this._(sdk, path.join(sdk.dartSdkPath, 'bin', 'dart'));
30+
Compiler(Sdk sdk) : this._(sdk, path.join(sdk.dartSdkPath, 'bin', 'dart'));
3231

3332
Compiler._(this._sdk, this._dartPath)
3433
: _ddcDriver = BazelWorkerDriver(

pkgs/dart_services/test/presubmit/compiling_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void main() {
1515
final sdk = Sdk.fromLocalFlutter();
1616

1717
setUpAll(() async {
18-
compiler = Compiler(sdk, storageBucket: 'nnbd_artifacts');
18+
compiler = Compiler(sdk);
1919
});
2020

2121
tearDownAll(() async {

0 commit comments

Comments
 (0)