Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷 Handle symbolic links between host platforms and containers #9320

Closed
wants to merge 18 commits into from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ _site
build
node_modules
flutter/
.symlinks

# Dart and Flutter, build related
.dart_tool
Expand Down
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ RUN apt-get update && apt-get install -yq --no-install-recommends \

WORKDIR /app


# Replace symlinks with the real file.
# Note: This should be only executed before an actual test/build happened.
# Otherwise, `COPY`s will be broken by it.
ENV REPLACE_SYMLINKS dart pub get && dart run tool/handle_symlinks.dart replace

# ============== INSTALL FLUTTER ==============
FROM base AS flutter

COPY ./site-shared ./site-shared
COPY pubspec.yaml ./

ARG FLUTTER_BUILD_BRANCH=stable
ENV FLUTTER_BUILD_BRANCH=$FLUTTER_BUILD_BRANCH
ENV FLUTTER_ROOT=flutter
ENV FLUTTER_BIN=flutter/bin
ENV PATH="/flutter/bin:$PATH"
ENV FLUTTER_ROOT=/flutter
ENV FLUTTER_BIN=$FLUTTER_ROOT/bin
ENV DART_BIN=$FLUTTER_BIN/cache/dart-sdk/bin
ENV PATH="$FLUTTER_BIN:$DART_BIN:$PATH"

RUN git clone --branch $FLUTTER_BUILD_BRANCH --single-branch --filter=tree:0 https://github.com/flutter/flutter /flutter/
VOLUME /flutter
Expand All @@ -40,6 +41,9 @@ VOLUME /flutter
# and this is to be disregarded since this image is never deployed to production.
RUN flutter doctor
RUN flutter --version

COPY ./site-shared ./site-shared
COPY pubspec.yaml ./
RUN dart pub get


Expand All @@ -63,6 +67,7 @@ RUN npm install -g [email protected]
FROM flutter AS tests

COPY ./ ./
RUN $REPLACE_SYMLINKS

# Only test the code here, checking links is purely for site deployment
ENTRYPOINT ["tool/test.sh"]
Expand All @@ -83,6 +88,7 @@ COPY package.json package-lock.json ./
RUN npm install

COPY ./ ./
RUN $REPLACE_SYMLINKS

# Jekyl ports
EXPOSE 35730
Expand All @@ -108,6 +114,7 @@ COPY package.json package-lock.json ./
RUN npm ci

COPY ./ ./
RUN $REPLACE_SYMLINKS

RUN echo 'User-agent: *\nDisallow:\n\nSitemap: https://docs.flutter.dev/sitemap.xml' > src/robots.txt

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ shell:
# overcome inconsistent bugs with missing packages at runtime.
setup:
make clean
dart pub get
dart run ./tool/handle_symlinks.dart find
docker-compose build --no-cache site
docker-compose run --rm site npm install
docker-compose run --rm site bundle config set force_ruby_platform true
Expand Down
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
include: package:lints/recommended.yaml

analyzer:
exclude: [flutter, site-shared, src, tmp]
3 changes: 1 addition & 2 deletions examples/deployment/obfuscate/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ environment:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.5
flutter_test:
sdk: flutter
cupertino_icons: ^1.0.5

dev_dependencies:
example_utils:
path: ../../example_utils
integration_test:
sdk: flutter


flutter:
uses-material-design: true
1 change: 1 addition & 0 deletions examples/get-started/codelab_web/lib/starter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* {$ begin main.dart $} */
// ignore_for_file: prefer_final_fields
import 'package:flutter/material.dart';

void main() => runApp(const SignUpApp());
Expand Down
4 changes: 4 additions & 0 deletions examples/get-started/codelab_web/lib/step1.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: prefer_final_fields
import 'package:flutter/material.dart';

// #docregion WelcomeScreen
Expand Down Expand Up @@ -127,3 +128,6 @@ class _SignUpFormState extends State<SignUpForm> {
);
}
}

// Avoid warning on "double _formProgress = 0;"
//_ignore_for_file: prefer_final_fields
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ environment:
sdk: ^3.1.0

dev_dependencies:
archive: ^3.3.7
build_runner: ^2.4.6
code_excerpt_updater:
path: site-shared/packages/code_excerpt_updater
code_excerpter:
path: site-shared/packages/code_excerpter
linkcheck: ^3.0.0
lints: any
path: ^1.8.3
94 changes: 94 additions & 0 deletions tool/handle_symlinks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as p;

final symlinkFile = File('.symlinks');

void main(List<String> args) async {
final command = args.singleOrNull;
if (command == null) {
throw ArgumentError.notNull();
}
switch (command) {
case 'find':
_find();
case 'replace':
_replace();
default:
throw UnimplementedError();
}
}

void _find() {
final links = Directory.current
.listSync(recursive: true)
.where(
(file) => !file.path.contains('node_modules'),
) // Exclude node_modules.
.where((file) => FileSystemEntity.isLinkSync(file.path));
final linksContent = Map.fromEntries(
links.map(
(link) => MapEntry(
Uri.file(
p.relative(
link.path,
from: Directory.current.path,
),
).toFilePath(windows: false),
Uri.file(
p.relative(
link.resolveSymbolicLinksSync(),
from: Directory.current.path,
),
).toFilePath(windows: false),
),
),
);
print(linksContent.entries.join('\n'));
symlinkFile.writeAsStringSync(
const JsonEncoder.withIndent(' ').convert(linksContent),
);
}

Future<void> _replace() async {
final linksContent =
jsonDecode(symlinkFile.readAsStringSync()) as Map<String, dynamic>;
final links = linksContent.entries;
if (links.isEmpty) {
return;
}
for (final link in links) {
final key = p.join(
Directory.current.path,
Uri.file(link.key).toFilePath(),
);
final value = p.join(
Directory.current.path,
Uri.file(link.value).toFilePath(),
);
if (FileSystemEntity.isDirectorySync(key)) {
await Directory(key).delete(recursive: true);
_copySync(Directory(value), Directory(key));
} else {
await File(key).delete();
File(value).copySync(key);
}
}
}

void _copySync(Directory source, Directory destination) {
// Creates the destination folder if not exist.
if (!destination.existsSync()) {
destination.createSync(recursive: true);
}
// Get all files from source.
source.listSync(recursive: false).forEach((entity) {
final newPath = p.join(destination.path, p.basename(entity.path));
if (entity is File) {
entity.copySync(newPath);
} else if (entity is Directory) {
_copySync(entity, Directory(newPath));
}
});
}
Loading