Unverified Commit a2a520cb authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

only cache release manifest files for 60 seconds (#79325)

parent b2b98a26
...@@ -11,6 +11,7 @@ import 'package:args/args.dart'; ...@@ -11,6 +11,7 @@ import 'package:args/args.dart';
import 'package:crypto/crypto.dart'; import 'package:crypto/crypto.dart';
import 'package:crypto/src/digest_sink.dart'; import 'package:crypto/src/digest_sink.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:meta/meta.dart' show required;
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:platform/platform.dart' show Platform, LocalPlatform; import 'package:platform/platform.dart' show Platform, LocalPlatform;
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -26,6 +27,7 @@ const String oldBaseUrl = 'https://storage.googleapis.com/flutter_infra'; ...@@ -26,6 +27,7 @@ const String oldBaseUrl = 'https://storage.googleapis.com/flutter_infra';
const String newGsBase = 'gs://flutter_infra_release'; const String newGsBase = 'gs://flutter_infra_release';
const String newGsReleaseFolder = '$newGsBase$releaseFolder'; const String newGsReleaseFolder = '$newGsBase$releaseFolder';
const String newBaseUrl = 'https://storage.googleapis.com/flutter_infra_release'; const String newBaseUrl = 'https://storage.googleapis.com/flutter_infra_release';
const int shortCacheSeconds = 60;
/// Exception class for when a process fails to run, so we can catch /// Exception class for when a process fails to run, so we can catch
/// it and provide something more readable than a stack trace. /// it and provide something more readable than a stack trace.
...@@ -547,7 +549,10 @@ class ArchivePublisher { ...@@ -547,7 +549,10 @@ class ArchivePublisher {
); );
} }
} }
await _cloudCopy(outputFile.absolute.path, destGsPath); await _cloudCopy(
src: outputFile.absolute.path,
dest: destGsPath,
);
assert(tempDir.existsSync()); assert(tempDir.existsSync());
await _updateMetadata('$releaseFolder/${getMetadataFilename(platform)}', newBucket: false); await _updateMetadata('$releaseFolder/${getMetadataFilename(platform)}', newBucket: false);
} }
...@@ -614,7 +619,14 @@ class ArchivePublisher { ...@@ -614,7 +619,14 @@ class ArchivePublisher {
const JsonEncoder encoder = JsonEncoder.withIndent(' '); const JsonEncoder encoder = JsonEncoder.withIndent(' ');
metadataFile.writeAsStringSync(encoder.convert(jsonData)); metadataFile.writeAsStringSync(encoder.convert(jsonData));
} }
await _cloudCopy(metadataFile.absolute.path, gsPath); await _cloudCopy(
src: metadataFile.absolute.path,
dest: gsPath,
// This metadata file is used by the website, so we don't want a long
// latency between publishing a release and it being available on the
// site.
cacheSeconds: shortCacheSeconds,
);
} }
Future<String> _runGsUtil( Future<String> _runGsUtil(
...@@ -655,7 +667,11 @@ class ArchivePublisher { ...@@ -655,7 +667,11 @@ class ArchivePublisher {
return true; return true;
} }
Future<String> _cloudCopy(String src, String dest) async { Future<String> _cloudCopy({
@required String src,
@required String dest,
int cacheSeconds,
}) async {
// We often don't have permission to overwrite, but // We often don't have permission to overwrite, but
// we have permission to remove, so that's what we do. // we have permission to remove, so that's what we do.
await _runGsUtil(<String>['rm', dest], failOk: true); await _runGsUtil(<String>['rm', dest], failOk: true);
...@@ -673,6 +689,7 @@ class ArchivePublisher { ...@@ -673,6 +689,7 @@ class ArchivePublisher {
// Use our preferred MIME type for the files we care about // Use our preferred MIME type for the files we care about
// and let gsutil figure it out for anything else. // and let gsutil figure it out for anything else.
if (mimeType != null) ...<String>['-h', 'Content-Type:$mimeType'], if (mimeType != null) ...<String>['-h', 'Content-Type:$mimeType'],
if (cacheSeconds != null) ...<String>['-h', 'Cache-Control:max-age=$cacheSeconds'],
'cp', 'cp',
src, src,
dest, dest,
...@@ -804,7 +821,7 @@ Future<void> main(List<String> rawArguments) async { ...@@ -804,7 +821,7 @@ Future<void> main(List<String> rawArguments) async {
branch, branch,
version, version,
outputFile, outputFile,
parsedArguments['dry_run'] as bool, parsedArguments['dry_run'] as bool,
); );
await publisher.publishArchive(parsedArguments['force'] as bool); await publisher.publishArchive(parsedArguments['force'] as bool);
} }
......
...@@ -301,13 +301,13 @@ void main() { ...@@ -301,13 +301,13 @@ void main() {
'$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $gsArchivePath': null, '$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $gsArchivePath': null,
'$gsutilCall -- cp $gsJsonPath $jsonPath': null, '$gsutilCall -- cp $gsJsonPath $jsonPath': null,
'$gsutilCall -- rm $gsJsonPath': null, '$gsutilCall -- rm $gsJsonPath': null,
'$gsutilCall -- -h Content-Type:application/json cp $jsonPath $gsJsonPath': null, '$gsutilCall -- -h Content-Type:application/json -h Cache-Control:max-age=60 cp $jsonPath $gsJsonPath': null,
'$gsutilCall -- stat $newGsArchivePath': <ProcessResult>[ProcessResult(0, 1, '', '')], '$gsutilCall -- stat $newGsArchivePath': <ProcessResult>[ProcessResult(0, 1, '', '')],
'$gsutilCall -- rm $newGsArchivePath': null, '$gsutilCall -- rm $newGsArchivePath': null,
'$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $newGsArchivePath': null, '$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $newGsArchivePath': null,
'$gsutilCall -- cp $newGsJsonPath $jsonPath': null, '$gsutilCall -- cp $newGsJsonPath $jsonPath': null,
'$gsutilCall -- rm $newGsJsonPath': null, '$gsutilCall -- rm $newGsJsonPath': null,
'$gsutilCall -- -h Content-Type:application/json cp $jsonPath $newGsJsonPath': null, '$gsutilCall -- -h Content-Type:application/json -h Cache-Control:max-age=60 cp $jsonPath $newGsJsonPath': null,
}; };
processManager.addCommands(convertResults(calls)); processManager.addCommands(convertResults(calls));
final File outputFile = File(path.join(tempDir.absolute.path, archiveName)); final File outputFile = File(path.join(tempDir.absolute.path, archiveName));
...@@ -437,12 +437,12 @@ void main() { ...@@ -437,12 +437,12 @@ void main() {
'$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $gsArchivePath': null, '$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $gsArchivePath': null,
'$gsutilCall -- cp $gsJsonPath $jsonPath': null, '$gsutilCall -- cp $gsJsonPath $jsonPath': null,
'$gsutilCall -- rm $gsJsonPath': null, '$gsutilCall -- rm $gsJsonPath': null,
'$gsutilCall -- -h Content-Type:application/json cp $jsonPath $gsJsonPath': null, '$gsutilCall -- -h Content-Type:application/json -h Cache-Control:max-age=60 cp $jsonPath $gsJsonPath': null,
'$gsutilCall -- rm $newGsArchivePath': null, '$gsutilCall -- rm $newGsArchivePath': null,
'$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $newGsArchivePath': null, '$gsutilCall -- -h Content-Type:$archiveMime cp $archivePath $newGsArchivePath': null,
'$gsutilCall -- cp $newGsJsonPath $jsonPath': null, '$gsutilCall -- cp $newGsJsonPath $jsonPath': null,
'$gsutilCall -- rm $newGsJsonPath': null, '$gsutilCall -- rm $newGsJsonPath': null,
'$gsutilCall -- -h Content-Type:application/json cp $jsonPath $newGsJsonPath': null, '$gsutilCall -- -h Content-Type:application/json -h Cache-Control:max-age=60 cp $jsonPath $newGsJsonPath': null,
}; };
processManager.addCommands(convertResults(calls)); processManager.addCommands(convertResults(calls));
assert(tempDir.existsSync()); assert(tempDir.existsSync());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment