Skip to content

Commit 326b5bb

Browse files
Connect networks
1 parent e1685e6 commit 326b5bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+77
-112
lines changed

mock-server/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \
1515
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`
1616

1717
FROM phpswoole/swoole:4.8.7-php8.1-alpine as final
18+
RUN ["apk", "add", "docker"]
1819

1920
ENV _APP_REDIS_HOST=redis \
2021
_APP_REDIS_PORT=6379

mock-server/app/http.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@
3939

4040
$http = new Server("0.0.0.0", App::getEnv('PORT', 80));
4141
$payloadSize = 6 * (1024 * 1024); // 6MB
42+
$workerNumber = swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6));
43+
44+
$http
45+
->set([
46+
'worker_num' => $workerNumber,
47+
'open_http2_protocol' => true,
48+
// 'document_root' => __DIR__.'/../public',
49+
// 'enable_static_handler' => true,
50+
'http_compression' => true,
51+
'http_compression_level' => 6,
52+
'package_max_length' => $payloadSize,
53+
'buffer_output_size' => $payloadSize,
54+
]);
4255

4356
// Mock Routes
4457
App::get('/v1/mock/tests/foo')
@@ -236,7 +249,7 @@
236249
->label('sdk.mock', true)
237250
->inject('request')
238251
->inject('response')
239-
->action(function (Request $request, Response $response) {
252+
->action(function (Request $request, UtopiaSwooleResponse $response) {
240253
$res = [
241254
'x-sdk-name' => $request->getHeader('x-sdk-name'),
242255
'x-sdk-platform' => $request->getHeader('x-sdk-platform'),
@@ -248,7 +261,7 @@
248261
}, array_keys($res), $res);
249262
$res = implode("; ", $res);
250263

251-
$response->dynamic(new Document(['result' => $res]), Response::MODEL_MOCK);
264+
$response->json(['result' => $res]);
252265
});
253266

254267
App::get('/v1/mock/tests/general/download')
@@ -264,7 +277,7 @@
264277
->label('sdk.response.code', Response::STATUS_CODE_OK)
265278
->label('sdk.mock', true)
266279
->inject('response')
267-
->action(function (Response $response) {
280+
->action(function (UtopiaSwooleResponse $response) {
268281

269282
$response
270283
->setContentType('text/plain')
@@ -293,7 +306,7 @@
293306
->param('file', [], new File(), 'Sample file param', skipValidation: true)
294307
->inject('request')
295308
->inject('response')
296-
->action(function (string $x, int $y, array $z, mixed $file, Request $request, Response $response) {
309+
->action(function (string $x, int $y, array $z, mixed $file, Request $request, UtopiaSwooleResponse $response) {
297310

298311
$file = $request->getFiles('file');
299312

@@ -375,7 +388,7 @@
375388
->label('sdk.response.model', Response::MODEL_MOCK)
376389
->label('sdk.mock', true)
377390
->inject('response')
378-
->action(function (Response $response) {
391+
->action(function (UtopiaSwooleResponse $response) {
379392

380393
$response->redirect('/v1/mock/tests/general/redirect/done');
381394
});
@@ -409,7 +422,7 @@
409422
->label('sdk.mock', true)
410423
->inject('response')
411424
->inject('request')
412-
->action(function (Response $response, Request $request) {
425+
->action(function (UtopiaSwooleResponse $response, Request $request) {
413426

414427
$response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', $request->getHostname(), true, true);
415428
});
@@ -446,7 +459,7 @@
446459
->label('sdk.response.model', Response::MODEL_NONE)
447460
->label('sdk.mock', true)
448461
->inject('response')
449-
->action(function (Response $response) {
462+
->action(function (UtopiaSwooleResponse $response) {
450463

451464
$response->noContent();
452465
});
@@ -524,7 +537,7 @@
524537
->label('sdk.response.model', Response::MODEL_ANY)
525538
->label('sdk.mock', true)
526539
->inject('response')
527-
->action(function (Response $response) {
540+
->action(function (UtopiaSwooleResponse $response) {
528541

529542
$response
530543
->setStatusCode(502)
@@ -542,7 +555,7 @@
542555
->param('scope', '', new Text(100), 'OAuth2 scope list.')
543556
->param('state', '', new Text(1024), 'OAuth2 state.')
544557
->inject('response')
545-
->action(function (string $client_id, string $redirectURI, string $scope, string $state, Response $response) {
558+
->action(function (string $client_id, string $redirectURI, string $scope, string $state, UtopiaSwooleResponse $response) {
546559

547560
$response->redirect($redirectURI . '?' . \http_build_query(['code' => 'abcdef', 'state' => $state]));
548561
});
@@ -560,7 +573,7 @@
560573
->param('code', '', new Text(100), 'OAuth2 state.', true)
561574
->param('refresh_token', '', new Text(100), 'OAuth2 refresh token.', true)
562575
->inject('response')
563-
->action(function (string $client_id, string $client_secret, string $grantType, string $redirectURI, string $code, string $refreshToken, Response $response) {
576+
->action(function (string $client_id, string $client_secret, string $grantType, string $redirectURI, string $code, string $refreshToken, UtopiaSwooleResponse $response) {
564577

565578
if ($client_id != '1') {
566579
throw new Exception(Exception::GENERAL_MOCK, 'Invalid client ID');
@@ -600,7 +613,7 @@
600613
->label('docs', false)
601614
->param('token', '', new Text(100), 'OAuth2 Access Token.')
602615
->inject('response')
603-
->action(function (string $token, Response $response) {
616+
->action(function (string $token, UtopiaSwooleResponse $response) {
604617

605618
if ($token != '123456') {
606619
throw new Exception(Exception::GENERAL_MOCK, 'Invalid token');
@@ -619,7 +632,7 @@
619632
->label('scope', 'public')
620633
->label('docs', false)
621634
->inject('response')
622-
->action(function (Response $response) {
635+
->action(function (UtopiaSwooleResponse $response) {
623636

624637
$response->json([
625638
'result' => 'success',
@@ -632,7 +645,7 @@
632645
->label('scope', 'public')
633646
->label('docs', false)
634647
->inject('response')
635-
->action(function (Response $response) {
648+
->action(function (UtopiaSwooleResponse $response) {
636649

637650
$response
638651
->setStatusCode(Response::STATUS_CODE_BAD_REQUEST)
@@ -646,7 +659,7 @@
646659
->inject('utopia')
647660
->inject('response')
648661
->inject('request')
649-
->action(function (App $utopia, Response $response, Request $request) {
662+
->action(function (App $utopia, UtopiaSwooleResponse $response, Request $request) {
650663

651664
$result = [];
652665
$route = $utopia->getRoute();
@@ -665,7 +678,7 @@
665678
throw new Exception(Exception::GENERAL_MOCK, 'Failed to save results', 500);
666679
}
667680

668-
$response->dynamic(new Document(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']), Response::MODEL_MOCK);
681+
$response->json(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']);
669682
});
670683

671684
App::error()
@@ -714,7 +727,6 @@ function ($utopia, $error, $request, $response) {
714727
break;
715728
default:
716729
$code = 500; // All other errors get the generic 500 server error status code
717-
$message = 'Server Error';
718730
}
719731

720732
$output = ((App::isDevelopment())) ? [

mock-server/docker-compose.yml

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
version: '3'
22

33
services:
4-
traefik:
5-
image: traefik:2.9
6-
container_name: appwrite-traefik
7-
command:
8-
- --log.level=DEBUG
9-
- --api.insecure=true
10-
- --providers.file.directory=/storage/config
11-
- --providers.file.watch=true
12-
- --providers.docker=true
13-
- --providers.docker.exposedByDefault=false
14-
- --providers.docker.constraints=Label(`traefik.constraint-label-stack`,`mock_api`)
15-
- --entrypoints.mock_web.address=:80
16-
- --entrypoints.mock_websecure.address=:443
17-
- --accesslog=true
18-
ports:
19-
- 80:80
20-
- 8080:80
21-
- 443:443
22-
- 9500:8080
23-
volumes:
24-
- /var/run/docker.sock:/var/run/docker.sock
25-
- mock-config:/storage/config:ro
26-
- mock-certificates:/storage/certificates:ro
27-
depends_on:
28-
- mockapi
29-
networks:
30-
- gateway
31-
- mockapi
32-
334
mockapi:
345
container_name: mockapi
356
build:
@@ -44,32 +15,4 @@ services:
4415
- app/http.php
4516
volumes:
4617
- ./app:/usr/src/code/app
47-
- ./src:/usr/src/code/src
48-
- ./vendor:/usr/src/code/vendor
49-
labels:
50-
- "traefik.enable=true"
51-
- "traefik.constraint-label-stack=mock_api"
52-
- "traefik.docker.network=mockapi"
53-
- "traefik.http.services.mock_api.loadbalancer.server.port=80"
54-
#http
55-
- traefik.http.routers.mock_api_http.entrypoints=mock_web
56-
- traefik.http.routers.mock_api_http.rule=PathPrefix(`/`)
57-
- traefik.http.routers.mock_api_http.service=mock_api
58-
# https
59-
- traefik.http.routers.mock_api_https.entrypoints=mock_websecure
60-
- traefik.http.routers.mock_api_https.rule=PathPrefix(`/`)
61-
- traefik.http.routers.mock_api_https.service=mock_api
62-
- traefik.http.routers.mock_api_https.tls=true
63-
networks:
64-
- mockapi
65-
66-
volumes:
67-
mock-certificates:
68-
mock-config:
69-
70-
networks:
71-
mockapi:
72-
name: mockapi
73-
gateway:
74-
name: gateway
75-
18+
- ./src:/usr/src/code/src

tests/Android11Java11Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Android11Java11Test extends Base
1717
'chmod +x tests/sdks/android/gradlew',
1818
];
1919
protected string $command =
20-
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-30-jdk11 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
20+
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-30-jdk11 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
2121

2222
protected array $expectedOutput = [
2323
...Base::FOO_RESPONSES,

tests/Android11Java8Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Android11Java8Test extends Base
1717
'chmod +x tests/sdks/android/gradlew',
1818
];
1919
protected string $command =
20-
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-30-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
20+
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-30-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
2121

2222
protected array $expectedOutput = [
2323
...Base::FOO_RESPONSES,

tests/Android12Java11Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Android12Java11Test extends Base
1717
'chmod +x tests/sdks/android/gradlew',
1818
];
1919
protected string $command =
20-
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-32-jdk11 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
20+
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-32-jdk11 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
2121

2222
protected array $expectedOutput = [
2323
...Base::FOO_RESPONSES,

tests/Android12Java8Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Android12Java8Test extends Base
1717
'chmod +x tests/sdks/android/gradlew',
1818
];
1919
protected string $command =
20-
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-32-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
20+
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-32-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
2121

2222
protected array $expectedOutput = [
2323
...Base::FOO_RESPONSES,

tests/Android5Java11Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Android5Java11Test extends Base
1717
'chmod +x tests/sdks/android/gradlew',
1818
];
1919
protected string $command =
20-
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-21-jdk11 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
20+
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-21-jdk11 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
2121

2222
protected array $expectedOutput = [
2323
...Base::FOO_RESPONSES,

tests/Android5Java8Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Android5Java8Test extends Base
1717
'chmod +x tests/sdks/android/gradlew',
1818
];
1919
protected string $command =
20-
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-21-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
20+
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:android-21-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"';
2121

2222
protected array $expectedOutput = [
2323
...Base::FOO_RESPONSES,

tests/AppleSwift55Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AppleSwift55Test extends Base
1616
'cp tests/languages/apple/Tests.swift tests/sdks/apple/Tests/AppwriteTests/Tests.swift',
1717
];
1818
protected string $command =
19-
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/apple swiftarm/swift:5.5.2-focal-multi-arch swift test';
19+
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/apple swiftarm/swift:5.5.2-focal-multi-arch swift test';
2020

2121
protected array $expectedOutput = [
2222
...Base::FOO_RESPONSES,

0 commit comments

Comments
 (0)