Skip to content

Commit 5fb0649

Browse files
authored
refactor to serve the compilation artifacts from the docker image (#3401)
* refactor to serve the compilation artifacts from the docker image * update CI workflow * check in an empty artifacts/ dir * only serve from artifacts/ if the directory exists * remove extra build-storage-artifacts step * remove gcs upload instructions * add caching for 1 hour
1 parent 9779041 commit 5fb0649

File tree

25 files changed

+83
-210
lines changed

25 files changed

+83
-210
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 & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@ steps:
2828
- FLUTTER_CHANNEL=${_FLUTTER_CHANNEL}
2929
dir: pkgs/dart_services
3030

31-
# Build storage artifacts
32-
- name: gcr.io/$PROJECT_ID/flutter:${_FLUTTER_CHANNEL}
33-
id: Build storage artifacts
34-
entrypoint: dart
35-
args:
36-
- tool/grind.dart
37-
- build-storage-artifacts
38-
env:
39-
- FLUTTER_CHANNEL=${_FLUTTER_CHANNEL}
40-
dir: pkgs/dart_services
41-
4231
# Save flutter version to a file
4332
- name: gcr.io/$PROJECT_ID/flutter:${_FLUTTER_CHANNEL}
4433
id: Save flutter version
@@ -51,30 +40,6 @@ steps:
5140
- FLUTTER_CHANNEL=${_FLUTTER_CHANNEL}
5241
dir: pkgs/dart_services
5342

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-
7843
# Build the container image
7944
- name: 'gcr.io/cloud-builders/docker'
8045
args:
@@ -118,7 +83,7 @@ steps:
11883
- --cpu-boost
11984
- --max-instances=1000
12085
- --command=bin/server
121-
- --args=--redis-url=redis://${_REDIS_ADDR},--storage-bucket=${_STORAGE_BUCKET}
86+
- --args=--redis-url=redis://${_REDIS_ADDR}
12287
dir: pkgs/dart_services
12388
timeout: 1200s
12489
images:

.github/workflows/dart_services.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ jobs:
4242
run: dart format --set-exit-if-changed bin lib test tool
4343

4444
- name: Create template projects and populate the custom pub cache
45-
run: dart run grinder build-project-templates
45+
run: dart tool/grind.dart build-project-templates
4646

4747
# Build the web artifacts on the bots to ensure they don't regress.
4848
- name: Build web artifacts
49-
run: dart run grinder build-storage-artifacts
49+
run: dart tool/grind.dart build-storage-artifacts
5050

5151
- name: Run tests
5252
run: dart test test/presubmit
5353

54-
- run: sh ./tool/check_cycles.sh
54+
- run: tool/check_cycles.sh

.github/workflows/dartpad_shared.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
- name: Analyze project source
3838
run: dart analyze --fatal-infos
3939

40-
- run: sh ./tool/check_cycles.sh
40+
- run: tool/check_cycles.sh

.github/workflows/dartpad_ui.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ jobs:
3535
- run: flutter pub get
3636
- run: flutter analyze
3737
- run: dart format --set-exit-if-changed .
38-
- name: Create template projects and populate the custom pub cache
39-
run: dart run grinder build-project-templates
38+
39+
- name: Create template projects
40+
run: dart tool/grind.dart build-project-templates
4041
working-directory: pkgs/dart_services/
42+
4143
- run: flutter build web
42-
- run: flutter test test
43-
- run: sh ./tool/check_cycles.sh
44+
- run: flutter test
45+
46+
- run: tool/check_cycles.sh

.github/workflows/samples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
- run: dart format --set-exit-if-changed .
3131
- run: dart tool/samples.dart --verify
3232
- run: flutter build web
33-
- run: sh ./tool/check_cycles.sh
33+
- run: tool/check_cycles.sh

pkgs/dart_services/.gitignore

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

2121
# compilation artifacts
22-
artifacts/
22+
artifacts/**
2323
project_templates/
2424
flutter-sdks/
2525
local_pub_cache/

pkgs/dart_services/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ WORKDIR /pkgs/dart_services
1212
RUN dart pub get
1313
RUN dart compile exe bin/server.dart -o bin/server
1414

15-
RUN dart run grinder build-project-templates
15+
RUN dart tools/grind.dart build-project-templates
16+
RUN dart tools/grind.dart build-storage-artifacts
1617

1718
ENV BUILD_SHA=$BUILD_SHA
1819

pkgs/dart_services/README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ dart bin/server.dart
2929
The server will run from port 8080 and export several JSON APIs, like
3030
`/api/v3/analyze` and `/api/v3/compile`.
3131

32-
3332
### Enabling code generation
3433

3534
To test code generation features locally:
@@ -61,12 +60,6 @@ are uploaded to Cloud Storage automatically. These files are located in the
6160

6261
If you need to re-generate these files, run the following command.
6362

64-
```
65-
grind build-storage-artifacts
66-
```
67-
68-
Or, if you don't have `grind` on your PATH:
69-
7063
```
7164
dart tool/grind.dart build-storage-artifacts
7265
```
@@ -82,18 +75,13 @@ that the dependencies resolve and update the pinned versions specified in the
8275
whitelisted list of packages.
8376
2. Create the Dart and Flutter projects in the `project_templates/` directory:
8477

85-
```bash
86-
grind build-project-templates
87-
```
88-
89-
Or, if you don't have `grind` on your PATH:
9078

91-
```
79+
```bash
9280
dart tool/grind.dart build-project-templates
9381
```
9482

9583
4. Run `pub upgrade` in the Dart or Flutter project in `project_templates/`
96-
5. Run `grind update-pub-dependencies` to overwrite the
84+
5. Run `dart tool/grind.dart update-pub-dependencies` to overwrite the
9785
`tool/dependencies/pub_dependencies_<CHANNEL>.yaml` file for your current
9886
channel. Or, if you don't have `grind` on your PATH, `dart tool/grind.dart update-pub-dependencies`
9987
6. Repeat the above steps for the latest version of each Flutter channel

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
}

0 commit comments

Comments
 (0)