Skip to content

Commit 870b802

Browse files
authored
feat(dart_frog_cli): build supports custom Dockerfile (#433)
1 parent ba32f4a commit 870b802

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

packages/dart_frog_cli/e2e/test/dart_frog_build_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,44 @@ void main() {
4545
expect(path.basename(entities.first.path), equals(projectName));
4646
});
4747

48+
test('creates the project directory with a custom Dockerfile', () async {
49+
final customDockerFileContents = '''
50+
# My Custom Dockerfile
51+
FROM dart:2.18 AS build
52+
53+
WORKDIR /app
54+
55+
COPY pubspec.* ./
56+
RUN dart pub get
57+
58+
COPY . .
59+
60+
RUN dart pub get --offline
61+
RUN dart compile exe bin/server.dart -o bin/server
62+
63+
FROM scratch
64+
COPY --from=build /runtime/ /
65+
COPY --from=build /app/bin/server /app/bin/
66+
67+
CMD ["/app/bin/server"]
68+
''';
69+
final tempDirectory = Directory.systemTemp.createTempSync();
70+
final projectDirectoryPath = path.join(tempDirectory.path, projectName);
71+
final projectDirectory = Directory(projectDirectoryPath);
72+
await dartFrogCreate(projectName: projectName, directory: tempDirectory);
73+
File(
74+
path.join(projectDirectoryPath, 'Dockerfile'),
75+
).writeAsStringSync(customDockerFileContents);
76+
await dartFrogBuild(directory: projectDirectory);
77+
expect(
78+
File(
79+
path.join(projectDirectoryPath, 'build', 'Dockerfile'),
80+
).readAsStringSync(),
81+
equals(customDockerFileContents),
82+
);
83+
await tempDirectory.delete(recursive: true);
84+
});
85+
4886
testServer('GET / returns 200 with greeting', (host) async {
4987
final response = await http.get(Uri.parse(host));
5088
expect(response.statusCode, equals(HttpStatus.ok));

packages/dart_frog_cli/lib/src/commands/build/build.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class BuildCommand extends DartFrogCommand {
4747
final _ = await generator.generate(
4848
DirectoryGeneratorTarget(cwd),
4949
vars: vars,
50-
fileConflictResolution: FileConflictResolution.overwrite,
50+
fileConflictResolution: FileConflictResolution.skip,
5151
);
5252

5353
logger.detail('[codegen] running post-gen...');

packages/dart_frog_cli/test/src/commands/build/build_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void main() {
6565
() => generator.generate(
6666
any(),
6767
vars: any(named: 'vars'),
68-
fileConflictResolution: FileConflictResolution.overwrite,
68+
fileConflictResolution: FileConflictResolution.skip,
6969
),
7070
).thenAnswer((_) async => []);
7171
when(

0 commit comments

Comments
 (0)