From 33cf8f1ad3b42c8dfe9f5d92a702c728ab6aa31e Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Tue, 14 May 2024 09:34:47 +0700 Subject: [PATCH 1/4] feat: Support Alpine --- .github/workflows/build.yml | 34 +++++++++++++++++++ Dockerfile | 7 ++++ README.md | 2 ++ composer.json | 5 +-- .../tests/Service/HttpClientServiceTest.php | 2 +- .../tests/Service/HttpClientServiceTest.php | 2 +- 6 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 14fffeaa..7c0f656f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -173,3 +173,37 @@ jobs: uses: coverallsapp/github-action@v2 with: parallel-finished: true + + test-alpine: + runs-on: ubuntu-latest + needs: + - php-cs + strategy: + fail-fast: false + matrix: + arch: [ amd64, arm64 ] + + steps: + - uses: actions/checkout@v4 + name: Checkout repository + - name: Set up QEMU + if: matrix.arch == 'arm64' + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + if: matrix.arch == 'arm64' + uses: docker/setup-buildx-action@v3 + # - name: Build and cache + # uses: docker/build-push-action@v5 + # with: + # context: . + # push: false + # tags: "alpine-base:${{ matrix.arch }}" + # cache-from: type=gha + # cache-to: type=gha,mode=max + # platforms: linux/${{ matrix.arch }} + - name: run musl # If shared-mime-info not installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' + if: matrix.arch == 'amd64' + run: docker run --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home you54f/pact-php:alpine-base-${{ matrix.arch }} /bin/sh -c 'apk add --no-cache shared-mime-info && cd /home && composer install && composer gen-lib && composer test' + - name: run musl # If shared-mime-info installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' + if: matrix.arch == 'arm64' + run: docker run --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home you54f/pact-php:alpine-base-${{ matrix.arch }} /bin/sh -c 'apk add --no-cache shared-mime-info && cd /home && composer install && composer gen-lib && composer test' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a2a2071a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM php:8.3-alpine +RUN apk add --no-cache linux-headers libffi-dev protoc protobuf-dev musl-dev autoconf gcc g++ make +COPY --from=composer/composer:2-bin /composer /usr/local/bin/composer +RUN docker-php-ext-install sockets +RUN docker-php-ext-install ffi +RUN pecl install grpc +RUN echo 'extension=grpc.so' >> /usr/local/etc/php/conf.d/grpc.ini diff --git a/README.md b/README.md index 118e7071..2dd75817 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,8 @@ _\*_ v3 support is limited to the subset of functionality required to enable lan | Linux | arm64 | ✅ | 9.x + | | Windows | x86_64 | ✅ | All | | Windows | x86 | ✅ | 9.x - | +| Alpine | x86_64 | ✅ | 10.x + | +| Alpine | arm64 | ✅ | 10.x + | diff --git a/composer.json b/composer.json index 6eaf3eea..3a3e67dd 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "composer/semver": "^1.4.0|^3.2.0", "symfony/process": "^5.4|^6.0|^7.0", "guzzlehttp/psr7": "^2.4.5", - "pact-foundation/composer-downloads-plugin": "^2.0" + "pact-foundation/composer-downloads-plugin": "^2.1" }, "require-dev": { "ext-sockets": "*", @@ -123,9 +123,10 @@ "{$prefix}": "PHP_OS_FAMILY === 'Windows' ? 'pact_ffi' : 'libpact_ffi'", "{$os}": "PHP_OS === 'Darwin' ? 'osx' : strtolower(PHP_OS_FAMILY)", "{$architecture}": "in_array(php_uname('m'), ['arm64', 'aarch64']) ? (PHP_OS === 'Darwin' ? 'aarch64-apple-darwin' : 'aarch64') : 'x86_64'", + "{$musl}": "PHP_OS === 'Linux' && musl() === true ? '-musl' : ''", "{$extension}": "PHP_OS_FAMILY === 'Windows' ? 'dll' : (PHP_OS === 'Darwin' ? 'dylib' : 'so')" }, - "url": "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{$version}/{$prefix}-{$os}-{$architecture}.{$extension}.gz", + "url": "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{$version}/{$prefix}-{$os}-{$architecture}{$musl}.{$extension}.gz", "path": "bin/pact-ffi-lib/pact.{$extension}" }, "pact-stub-server": { diff --git a/example/binary/consumer/tests/Service/HttpClientServiceTest.php b/example/binary/consumer/tests/Service/HttpClientServiceTest.php index 40b3e22e..10ddb694 100644 --- a/example/binary/consumer/tests/Service/HttpClientServiceTest.php +++ b/example/binary/consumer/tests/Service/HttpClientServiceTest.php @@ -26,7 +26,7 @@ public function testGetImageContent() $response ->setStatus(200) ->addHeader('Content-Type', 'image/jpeg') - ->setBody(new Binary($path, in_array(php_uname('m'), ['AMD64', 'arm64', 'aarch64']) ? 'application/octet-stream' : 'image/jpeg')); + ->setBody(new Binary($path, PHP_OS_FAMILY === 'Windows' || (PHP_OS_FAMILY === 'Darwin' && php_uname('m') === 'arm64') ? 'application/octet-stream' : 'image/jpeg')); $config = new MockServerConfig(); $config diff --git a/example/multipart/consumer/tests/Service/HttpClientServiceTest.php b/example/multipart/consumer/tests/Service/HttpClientServiceTest.php index e53e1c9f..e2351107 100644 --- a/example/multipart/consumer/tests/Service/HttpClientServiceTest.php +++ b/example/multipart/consumer/tests/Service/HttpClientServiceTest.php @@ -36,7 +36,7 @@ public function testUpdateUserProfile() ->setBody(new Multipart( [ new Part(__DIR__ . '/../_resource/full_name.txt', 'full_name', 'text/plain'), - new Part(__DIR__ . '/../_resource/image.jpg', 'profile_image', in_array(php_uname('m'), ['AMD64', 'arm64', 'aarch64']) ? 'application/octet-stream' : 'image/jpeg'), + new Part(__DIR__ . '/../_resource/image.jpg', 'profile_image', PHP_OS_FAMILY === 'Windows' || (PHP_OS_FAMILY === 'Darwin' && php_uname('m') === 'arm64') ? 'application/octet-stream' : 'image/jpeg'), new Part(__DIR__ . '/../_resource/note.txt', 'personal_note', 'text/plain'), ], 'ktJmeYHbkTSa1jxD' From 83a962fce7dd44727ba5304052422cf529aa8f0b Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Fri, 17 May 2024 17:55:30 +0700 Subject: [PATCH 2/4] docs: Add a note about Ruby Standalone with Alpine support --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2dd75817..5b1ed9fc 100644 --- a/README.md +++ b/README.md @@ -270,8 +270,10 @@ _\*_ v3 support is limited to the subset of functionality required to enable lan | Linux | arm64 | ✅ | 9.x + | | Windows | x86_64 | ✅ | All | | Windows | x86 | ✅ | 9.x - | -| Alpine | x86_64 | ✅ | 10.x + | -| Alpine | arm64 | ✅ | 10.x + | +| Alpine | x86_64 | ✅ | All \* | +| Alpine | arm64 | ✅ | All \* | + +_\*_ For 9.x and below, supported with a workaround [Ruby Standalone with Alpine]. @@ -291,3 +293,4 @@ See [CONTRIBUTING](CONTRIBUTING.md). [9xx]: https://github.com/pact-foundation/pact-php/tree/release/9.x [installation]: #installation [message support]: https://github.com/pact-foundation/pact-specification/tree/version-3#introduces-messages-for-services-that-communicate-via-event-streams-and-message-queues +[Ruby Standalone with Alpine]: https://github.com/pact-foundation/pact-ruby-standalone/wiki/Using-the-pact-ruby-standalone-with-Alpine-Linux-Docker From 82f3ede9c1533b7604e82f9c186ce5f1695ae3f2 Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Fri, 17 May 2024 19:24:01 +0700 Subject: [PATCH 3/4] ci: Install dependency packages directly --- .github/workflows/build.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c0f656f..64d9718c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -192,18 +192,9 @@ jobs: - name: Set up Docker Buildx if: matrix.arch == 'arm64' uses: docker/setup-buildx-action@v3 - # - name: Build and cache - # uses: docker/build-push-action@v5 - # with: - # context: . - # push: false - # tags: "alpine-base:${{ matrix.arch }}" - # cache-from: type=gha - # cache-to: type=gha,mode=max - # platforms: linux/${{ matrix.arch }} - - name: run musl # If shared-mime-info not installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' + - name: run musl ${{ matrix.arch }} # If shared-mime-info not installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' if: matrix.arch == 'amd64' - run: docker run --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home you54f/pact-php:alpine-base-${{ matrix.arch }} /bin/sh -c 'apk add --no-cache shared-mime-info && cd /home && composer install && composer gen-lib && composer test' - - name: run musl # If shared-mime-info installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' + run: docker run --env PACT_DO_NOT_TRACK=1 --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home alpine:3.19 /bin/sh -c 'apk add --no-cache shared-mime-info php82-dev php82-ffi php82-pecl-grpc php82-sockets php82-tokenizer php82-dom php82-xml php82-xmlwriter php82-simplexml composer protoc protobuf-dev && cd /home && composer install && composer gen-lib && composer test' + - name: run musl ${{ matrix.arch }} # If shared-mime-info not installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' if: matrix.arch == 'arm64' - run: docker run --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home you54f/pact-php:alpine-base-${{ matrix.arch }} /bin/sh -c 'apk add --no-cache shared-mime-info && cd /home && composer install && composer gen-lib && composer test' + run: docker run --env PACT_DO_NOT_TRACK=1 --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home alpine:3.19 /bin/sh -c 'apk add --no-cache shared-mime-info php82-dev php82-ffi php82-pecl-grpc php82-sockets php82-tokenizer php82-dom php82-xml php82-xmlwriter php82-simplexml composer protoc protobuf-dev curl && curl -LO https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v0.1.2/pact-plugin-cli-linux-aarch64.gz && gunzip pact-plugin-cli-linux-aarch64.gz && mv pact-plugin-cli-linux-aarch64 /usr/bin/pact-plugin-cli && chmod +x /usr/bin/pact-plugin-cli && pact-plugin-cli install -y https://github.com/pact-foundation/pact-plugins/releases/tag/csv-plugin-0.0.6 && cd /home && composer install && composer gen-lib && composer test' From 07048ab422cb8a6d3d76977ef8c98e9b4fdeb5c8 Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Sat, 18 May 2024 07:57:06 +0700 Subject: [PATCH 4/4] ci: Merge run musl steps --- .github/workflows/build.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64d9718c..55a70669 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -192,9 +192,5 @@ jobs: - name: Set up Docker Buildx if: matrix.arch == 'arm64' uses: docker/setup-buildx-action@v3 - - name: run musl ${{ matrix.arch }} # If shared-mime-info not installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' - if: matrix.arch == 'amd64' + - name: run musl # If shared-mime-info not installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' run: docker run --env PACT_DO_NOT_TRACK=1 --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home alpine:3.19 /bin/sh -c 'apk add --no-cache shared-mime-info php82-dev php82-ffi php82-pecl-grpc php82-sockets php82-tokenizer php82-dom php82-xml php82-xmlwriter php82-simplexml composer protoc protobuf-dev && cd /home && composer install && composer gen-lib && composer test' - - name: run musl ${{ matrix.arch }} # If shared-mime-info not installed - Expected binary contents to have content type 'image/jpeg' but detected contents was 'application/octet-stream' - if: matrix.arch == 'arm64' - run: docker run --env PACT_DO_NOT_TRACK=1 --platform=linux/${{ matrix.arch }} --rm -v $PWD:/home alpine:3.19 /bin/sh -c 'apk add --no-cache shared-mime-info php82-dev php82-ffi php82-pecl-grpc php82-sockets php82-tokenizer php82-dom php82-xml php82-xmlwriter php82-simplexml composer protoc protobuf-dev curl && curl -LO https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v0.1.2/pact-plugin-cli-linux-aarch64.gz && gunzip pact-plugin-cli-linux-aarch64.gz && mv pact-plugin-cli-linux-aarch64 /usr/bin/pact-plugin-cli && chmod +x /usr/bin/pact-plugin-cli && pact-plugin-cli install -y https://github.com/pact-foundation/pact-plugins/releases/tag/csv-plugin-0.0.6 && cd /home && composer install && composer gen-lib && composer test'