From 7fedb0d1dc547c6aec6868d4dbe44f7a89a2058c Mon Sep 17 00:00:00 2001 From: Eduard Melnytskyi Date: Wed, 18 Dec 2024 18:41:39 +0100 Subject: [PATCH] Add intermediate layer for extension image build. --- .github/workflows/ci.yml | 22 +++---- .github/workflows/extensions-build.yml | 59 ++++++++++++++++++ alpine/extension/Dockerfile | 84 ++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/extensions-build.yml create mode 100644 alpine/extension/Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78c4cbc8..bd1bbc25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,17 +88,17 @@ jobs: # fi # echo "PREV_COMMIT_HASH=$PREV_COMMIT_HASH" >> $GITHUB_ENV - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v3 + # + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v3 + # + # - name: Login to DockerHub + # uses: docker/login-action@v1 + # with: + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} # - name: Re-tag images with previous commit hash # if: ${{ github.ref == 'refs/heads/master' }} diff --git a/.github/workflows/extensions-build.yml b/.github/workflows/extensions-build.yml new file mode 100644 index 00000000..e4e1f4cf --- /dev/null +++ b/.github/workflows/extensions-build.yml @@ -0,0 +1,59 @@ +name: Build GRPC-Protobuf Base Images + +on: + push: + branches: + - master + +jobs: + build-base: + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + fail-fast: false + matrix: + php_version: [8.3] + alpine_version: [3.20] + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Check if image exists in Docker Hub + id: check-image + run: | + IMAGE_TAG="spryker/grpc-protobuf:${{ matrix.php_version }}-alpine${{ matrix.alpine_version }}" + TOKEN=$(curl -s -u "${{ secrets.DOCKER_USERNAME }}:${{ secrets.DOCKER_PASSWORD }}" \ + "https://auth.docker.io/token?service=registry.docker.io&scope=repository:spryker/grpc-protobuf:pull" | jq -r .token) + EXISTS=$(curl -s -o /dev/null -w "%{http_code}" \ + -H "Authorization: Bearer $TOKEN" \ + "https://registry-1.docker.io/v2/spryker/grpc-protobuf/manifests/${{ matrix.php_version }}-alpine${{ matrix.alpine_version }}") + if [ "$EXISTS" -eq 200 ]; then + echo "Image $IMAGE_TAG already exists in Docker Hub." + echo "exists=true" >> $GITHUB_ENV + else + echo "Image $IMAGE_TAG does not exist. Proceeding with build." + echo "exists=false" >> $GITHUB_ENV + fi + + - name: Build and push base image + if: env.exists == 'false' + uses: docker/build-push-action@v5 + with: + push: true + tags: spryker/grpc-protobuf:${{ matrix.php_version }}-alpine${{ matrix.alpine_version }} + file: alpine/extension/Dockerfile + platforms: linux/amd64,linux/arm64 + cache-to: type=gha,mode=max + build-args: | + MAJOR_PHP_VERSION=${{ matrix.php_version }} + ALPINE_VERSION=${{ matrix.alpine_version }} \ No newline at end of file diff --git a/alpine/extension/Dockerfile b/alpine/extension/Dockerfile new file mode 100644 index 00000000..46d6baf5 --- /dev/null +++ b/alpine/extension/Dockerfile @@ -0,0 +1,84 @@ +# GRPC + Protobuf extension +ARG MAJOR_PHP_VERSION=8.3 +ARG ALPINE_VERSION=3.20 +FROM php:${MAJOR_PHP_VERSION}-fpm-alpine${ALPINE_VERSION} + +# Set environment variables +ENV srcRoot /data +ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so + +ARG PHP_RUN_DEPS="\ + freetype \ + gmp \ + gnu-libiconv \ + icu-libs \ + libbz2 \ + libc6-compat \ + libjpeg-turbo \ + libpng \ + libwebp \ + libxml2 \ + libxpm \ + libxslt \ + libzip \ + protobuf \ + grpc" + +ARG PHP_BUILD_DEPS="\ + autoconf \ + bzip2-dev \ + freetype-dev \ + gmp-dev \ + icu-dev \ + icu-data-full \ + libjpeg-turbo-dev \ + libpng-dev \ + libwebp-dev \ + libxml2-dev \ + libxpm-dev \ + libzip-dev \ + postgresql-dev \ + rabbitmq-c-dev \ + protobuf-dev \ + grpc-dev \ + g++" + +ARG PHP_PECL_EXTENSIONS="\ + opentelemetry \ + protobuf \ + grpc" + +ARG ADDITIONAL_PHP_PECL_EXTENSIONS="" + +RUN apk add --no-cache \ + bash \ + coreutils \ + curl \ + git \ + make \ + mysql-client \ + netcat-openbsd \ + openssh \ + postgresql-client \ + procps \ + python3 \ + shadow \ + unzip \ + linux-headers \ + libstdc++ \ + ${PHP_RUN_DEPS} \ + && apk add --no-cache --virtual .php-build-deps ${PHP_BUILD_DEPS} \ + && MAKEFLAGS="-j$(nproc)" pecl install -o -f ${PHP_PECL_EXTENSIONS} ${ADDITIONAL_PHP_PECL_EXTENSIONS} \ + && docker-php-ext-enable ${PHP_PECL_EXTENSIONS} \ + && rm -rf /tmp/pear \ + && apk del --no-cache .php-build-deps + +RUN mkdir -p ${srcRoot} + +# Set environment variables +ENV srcRoot /data +ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so + +WORKDIR ${srcRoot} + +USER root \ No newline at end of file