Skip to content

Commit 97c3983

Browse files
authored
Image proxy (#8996)
1 parent f2df54e commit 97c3983

File tree

11 files changed

+1088
-12
lines changed

11 files changed

+1088
-12
lines changed

app/test/shared/versions_test.dart

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void main() {
6565
'accepted runtime versions should be lexicographically ordered',
6666
() {
6767
for (final version in acceptedRuntimeVersions) {
68-
expect(runtimeVersionPattern.hasMatch(version), isTrue);
68+
expect(version, matches(runtimeVersionPattern));
6969
}
7070
final sorted = [...acceptedRuntimeVersions]
7171
..sort((a, b) => -a.compareTo(b));
@@ -77,23 +77,29 @@ void main() {
7777
expect(acceptedRuntimeVersions, hasLength(lessThan(6)));
7878
});
7979

80-
test('runtime sdk version should match CI and dockerfile', () async {
80+
test('runtime sdk version should match CI and dockerfiles', () async {
8181
final String docker = await File('../Dockerfile.app').readAsString();
82-
expect(docker.contains('\nFROM dart:$runtimeSdkVersion\n'), isTrue);
82+
expect(docker, contains('\nFROM dart:$runtimeSdkVersion\n'));
8383
final ci = await File('../.github/workflows/all-test.yml').readAsString();
84-
expect(ci.contains("DART_SDK_VERSION: '$runtimeSdkVersion'"), isTrue);
84+
expect(ci, contains("DART_SDK_VERSION: '$runtimeSdkVersion'"));
85+
final imageProxyDocker = await File(
86+
'../pkg/image_proxy/Dockerfile',
87+
).readAsString();
88+
expect(imageProxyDocker, contains('\nFROM dart:$runtimeSdkVersion '));
8589
});
8690

8791
test('Dart SDK versions should match Dockerfile.worker', () async {
8892
final dockerfileContent = await File('../Dockerfile.worker').readAsString();
8993
expect(
90-
dockerfileContent.contains(
91-
'tool/setup-dart.sh /home/worker/dart/stable stable/raw/hash/',
92-
) ||
93-
dockerfileContent.contains(
94-
'tool/setup-dart.sh /home/worker/dart/stable $toolStableDartSdkVersion',
95-
),
96-
isTrue,
94+
dockerfileContent,
95+
anyOf(
96+
contains(
97+
'tool/setup-dart.sh /home/worker/dart/stable stable/raw/hash/',
98+
),
99+
contains(
100+
'tool/setup-dart.sh /home/worker/dart/stable $toolStableDartSdkVersion',
101+
),
102+
),
97103
);
98104
});
99105

@@ -166,7 +172,7 @@ and do not format to also bump the runtimeVersion.''',
166172
// roll traffic backwards.
167173
// Avoid this by temporarily hardcoding gcBeforeRuntimeVersion to not be
168174
// the last version of acceptedRuntimeVersions.
169-
expect(gcBeforeRuntimeVersion != runtimeVersion, isTrue);
175+
expect(gcBeforeRuntimeVersion, isNot(runtimeVersion));
170176
});
171177

172178
scopedTest('GC is returning correct values for known versions', () {

pkg/image_proxy/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Use latest stable channel SDK.
2+
FROM dart:3.9.0 AS build
3+
4+
ENV PUB_ENVIRONMENT="bot"
5+
ENV PUB_CACHE="/project/.pub-cache"
6+
7+
# Resolve app dependencies.
8+
WORKDIR /app
9+
COPY . .
10+
RUN dart pub get --enforce-lockfile
11+
RUN dart compile exe pkg/image_proxy/bin/server.dart -o server
12+
13+
# Build minimal serving image from AOT-compiled `/server`
14+
# and the pre-built AOT-runtime in the `/runtime/` directory of the base image.
15+
FROM scratch
16+
COPY --from=build /runtime/ /
17+
COPY --from=build /app/server /app/bin/
18+
19+
# Start server.
20+
EXPOSE 8080
21+
CMD ["/app/bin/server"]

pkg/image_proxy/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Image proxy for pub.dev.
2+
3+
4+
Will forward requests to a url, when given a request like:
5+
```
6+
https://external-image.pub.dev/<base64(hmac(url,hmac_kms(date))>/<date>/<urlencode(url)>
7+
```
8+
9+
date is a "microsecond after epoch" timestamp of a specific date's midnight.
10+
11+
hmac_kms is calculated in KMS with the key version at HMAC_KEY_ID.
12+
13+
## Development
14+
15+
To build the docker image (from the repository root):
16+
17+
```
18+
docker build -t image-proxy-server . --file pkg/image_proxy/Dockerfile
19+
```
20+

pkg/image_proxy/bin/server.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
export 'package:pub_dev_image_proxy/image_proxy_service.dart' show main;

0 commit comments

Comments
 (0)