Skip to content

Commit

Permalink
feat: demo pact ffi musl converted to dynamic .so for alpine
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 13, 2024
1 parent 7f634f1 commit 2bfc7d9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,37 @@ jobs:
run: composer test
env:
PACT_DO_NOT_TRACK: true

test-docker:
runs-on: ubuntu-latest
needs:
- php-cs
strategy:
fail-fast: false
matrix:
arch: [ amd64, arm64 ]

name: musl builds


steps:
- uses: actions/checkout@v3
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: patch composer file for musl
run: |
sed -i 's/"{$musl}": "PHP_OS === '\''Linux'\'' ? '\'''\'' : '\'''\''",/"{$musl}": "PHP_OS === '\''Linux'\'' ? '\''-musl'\'' : '\'''\''",/g' composer.json
cat composer.json
# - name: build musl
# run: docker build . --platform=linux/${{ matrix.arch }} --progress plain -t pact-php:alpine-base
- 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 'cd /home && composer install && composer gen-lib && composer test'
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
RUN curl -LO https://github.com/YOU54F/pact-plugins/releases/download/pact-plugin-cli-v0.1.3/pact-plugin-cli-linux-$(uname -m)-musl.gz && \
gunzip pact-plugin-cli-linux-$(uname -m)-musl.gz && \
chmod +x pact-plugin-cli-linux-$(uname -m)-musl && \
mv pact-plugin-cli-linux-$(uname -m)-musl /usr/local/bin/pact-plugin-cli

RUN pact-plugin-cli install --yes https://github.com/you54f/pact-protobuf-plugin/releases/tag/v-0.3.14
RUN pact-plugin-cli install --yes https://github.com/you54f/pact-plugins/releases/tag/csv-plugin-0.0.6
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,31 @@
"extra": {
"downloads": {
"pact-ffi-headers": {
"version": "0.4.14",
"version": "0.4.16",
"url": "https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v{$version}/pact.h",
"path": "bin/pact-ffi-headers/pact.h"
},
"pact-ffi-lib": {
"version": "0.4.14",
"version": "0.4.16",
"variables": {
"{$prefix}": "PHP_OS_FAMILY === 'Windows' ? 'pact_ffi' : 'libpact_ffi'",
"{$musl}": "PHP_OS === 'Linux' ? '' : ''",
"{$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'",
"{$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/you54f/pact-reference/releases/download/libpact_ffi-v{$version}/{$prefix}-{$os}-{$architecture}{$musl}.{$extension}.gz",
"path": "bin/pact-ffi-lib/pact.{$extension}"
},
"pact-stub-server": {
"version": "0.5.3",
"version": "0.5.5",
"variables": {
"{$os}": "PHP_OS === 'Darwin' ? 'osx' : strtolower(PHP_OS_FAMILY)",
"{$musl}": "PHP_OS === 'Linux' ? '' : ''",
"{$architecture}": "in_array(php_uname('m'), ['arm64', 'aarch64']) ? 'aarch64' : 'x86_64'",
"{$extension}": "PHP_OS_FAMILY === 'Windows' ? '.exe' : ''"
},
"url": "https://github.com/pact-foundation/pact-stub-server/releases/download/v{$version}/pact-stub-server-{$os}-{$architecture}{$extension}.gz",
"url": "https://github.com/you54f/pact-stub-server/releases/download/v{$version}/pact-stub-server-{$os}-{$architecture}{$musl}{$extension}.gz",
"path": "bin/pact-stub-server/pact-stub-server{$extension}",
"executable": true
}
Expand Down

0 comments on commit 2bfc7d9

Please sign in to comment.