Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Dockerfile.app
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ RUN apt-get update && \
# Let the pub server know that this is not a "typical" pub client but rather a bot.
ENV PUB_ENVIRONMENT="bot.pub_dartlang_org.docker"
ENV PUB_CACHE="/project/.pub-cache"
# Let the pub server know that it is running inside a container.
# It will not rebuild web-app assets, only assert their presence.
ENV PUB_DEV_ENVIRONMENT="production"

COPY app /project/app
COPY pkg /project/pkg
Expand Down
20 changes: 20 additions & 0 deletions app/lib/frontend/static_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:meta/meta.dart';
import 'package:mime/mime.dart' as mime;
import 'package:pana/pana.dart' show runConstrained;
import 'package:path/path.dart' as path;
import 'package:pub_dev/shared/monitoring.dart';

final _logger = Logger('pub.static_files');

Expand Down Expand Up @@ -344,6 +345,25 @@ Future updateLocalBuiltFilesIfNeeded() async {
_logger.info('Building pkg/web_css');
await updateWebCssBuild();
}

await assertLocalBuiltFilesArePresent();
}

/// Checks whether the local built files are present, throws
/// [AssertionError] if anything is missing.
Future assertLocalBuiltFilesArePresent() async {
Future<void> assertExists(String path) async {
final file = File(path);
if (!file.existsSync()) {
_logger.pubNoticeShout(
'missing-built-file', 'The local built file is missing: $path');
}
}

final staticDirPath = resolveStaticDirPath();
await assertExists(path.join(staticDirPath, 'js', 'script.dart.js'));
await assertExists(path.join(staticDirPath, 'css', 'style.css'));
await assertExists(path.join(staticDirPath, 'css', 'dartdoc.css'));
}

/// Runs build.sh in pkg/web_app
Expand Down
4 changes: 4 additions & 0 deletions app/lib/search/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:meta/meta.dart';
import 'package:pana/src/dartdoc/pub_dartdoc_data.dart';
import 'package:path/path.dart' as p;
import 'package:pool/pool.dart';
import 'package:pub_dev/shared/env_config.dart';
import 'package:pub_dev/shared/monitoring.dart';
import 'package:retry/retry.dart';

Expand Down Expand Up @@ -451,6 +452,9 @@ class SearchBackend {
}
if (canUseCached) {
return await file.readAsString();
} else if (envConfig.isInProductionEnvironment) {
_logger.pubNoticeShout('missing-sdk-index-json',
'The SDK index.json file is missing: fileName');
}
}

Expand Down
6 changes: 5 additions & 1 deletion app/lib/service/entrypoint/frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class DefaultCommand extends Command {
}

Future _main() async {
await updateLocalBuiltFilesIfNeeded();
if (envConfig.isInProductionEnvironment) {
await assertLocalBuiltFilesArePresent();
} else {
await updateLocalBuiltFilesIfNeeded();
}
final appHandler = createAppHandler();

if (envConfig.isRunningLocally) {
Expand Down
4 changes: 4 additions & 0 deletions app/lib/shared/env_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class _EnvConfig {
/// True, if running inside AppEngine.
bool get isRunningInAppengine => _gaeService != null && _gaeVersion != null;

/// True, if the application is running inside a container environment.
late final isInProductionEnvironment =
Platform.environment['PUB_DEV_ENVIRONMENT'] == 'production';

/// True, if running locally and not inside AppEngine.
bool get isRunningLocally => !isRunningInAppengine;

Expand Down