From db7a832cf2f40fe3cb3bd51905c3539c3c1e8533 Mon Sep 17 00:00:00 2001 From: carry0987 Date: Sun, 17 Dec 2023 15:50:43 +0800 Subject: [PATCH] Create php-test-fpm.yml --- .github/workflows/php-test-fpm.yml | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/php-test-fpm.yml diff --git a/.github/workflows/php-test-fpm.yml b/.github/workflows/php-test-fpm.yml new file mode 100644 index 0000000..52c07a6 --- /dev/null +++ b/.github/workflows/php-test-fpm.yml @@ -0,0 +1,86 @@ +name: PHP-FPM Docker Build and Push + +on: + push: + tags: + - 'php-test-fpm-[^alpine]*' + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + platform: linux/amd64 + - os: buildjet-2vcpu-ubuntu-2204-arm + platform: linux/arm64 + outputs: + version: ${{ steps.prep.outputs.version }} + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up QEMU + if: matrix.platform != 'linux/arm64' + 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@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Prepare the Docker tags list and PHP version + id: prep + run: | + FULL_VERSION=$(echo ${{ github.ref }} | sed -e 's,.*/php-fpm-,,') + VERSION=${FULL_VERSION%-latest} + TAGS="${{ secrets.DOCKER_USERNAME }}/php:${VERSION}-fpm" + if [[ "$FULL_VERSION" == *"-latest" ]]; then + TAGS="$TAGS,${{ secrets.DOCKER_USERNAME }}/php:latest" + fi + echo "TAGS=$TAGS" >> $GITHUB_ENV + echo "PHP_VERSION=${VERSION%-fpm}" >> $GITHUB_ENV + echo "version=${VERSION%-fpm}" >> $GITHUB_ENV + echo "PHP_VERSION=${VERSION%-fpm}" + echo "Building with tags: $TAGS" + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./PHP/FPM + file: ./PHP/FPM/Dockerfile + build-args: PHP_VERSION=${{ env.PHP_VERSION }} + push: true + tags: ${{ env.TAGS }} + platforms: ${{ matrix.platform }} + + - name: Logout from DockerHub + run: docker logout + + manifest: + needs: build + runs-on: ubuntu-latest + steps: + - name: Create and push manifest + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }} + VERSION=${{ needs.build.outputs.version }} + AMD64_TAG="${{ secrets.DOCKER_USERNAME }}/php:${VERSION}-fpm-linux/amd64" + ARM64_TAG="${{ secrets.DOCKER_USERNAME }}/php:${VERSION}-fpm-linux/arm64" + FULL_TAG="${{ secrets.DOCKER_USERNAME }}/php:${VERSION}-fpm" + LATEST_TAG="${{ secrets.DOCKER_USERNAME }}/php:latest-fpm" + docker manifest create $FULL_TAG $AMD64_TAG $ARM64_TAG + docker manifest create $LATEST_TAG $AMD64_TAG $ARM64_TAG + docker manifest annotate $FULL_TAG $AMD64_TAG --arch amd64 + docker manifest annotate $FULL_TAG $ARM64_TAG --arch arm64 + docker manifest annotate $LATEST_TAG $AMD64_TAG --arch amd64 + docker manifest annotate $LATEST_TAG $ARM64_TAG --arch arm64 + docker manifest push $FULL_TAG + docker manifest push $LATEST_TAG + docker logout