From 9f588746cc814b297fed7e46a7587564c9db51cc Mon Sep 17 00:00:00 2001 From: Chase Bolt Date: Sun, 3 Nov 2024 10:26:46 -0800 Subject: [PATCH] use reusable workflows to test PRs without pushing to the registry --- .github/workflows/build-docker-image.yml | 80 +++++++++++++----------- .github/workflows/release.yml | 15 +++++ .github/workflows/test.yml | 8 +++ 3 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 32cc4d4..2614d87 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -1,9 +1,14 @@ name: Build Docker Image on: - push: - branches: - - "master" + workflow_call: + inputs: + push_images: + default: false + type: boolean + secrets: + dockerhub_username: + dockerhub_token: jobs: docker: @@ -18,109 +23,110 @@ jobs: - name: Login to DockerHub uses: docker/login-action@v1 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build And Push 7.1-alpine + username: ${{ secrets.dockerhub_username }} + password: ${{ secrets.dockerhub_token }} + if: github.ref_name == github.event.repository.default_branch + - name: Build 7.1-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/7.1/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.1-alpine - - name: Build And Push 7.2-alpine + - name: Build 7.2-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/7.2/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.2-alpine - - name: Build And Push 7.3-alpine + - name: Build 7.3-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/7.3/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.3-alpine - - name: Build And Push 7.4-alpine + - name: Build 7.4-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/7.4/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.4-alpine - - name: Build And Push 8.0-alpine + - name: Build 8.0-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/8.0/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.0-alpine - - name: Build And Push 8.1-alpine + - name: Build 8.1-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/8.1/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.1-alpine - - name: Build And Push 8.2-alpine + - name: Build 8.2-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/8.2/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.2-alpine - - name: Build And Push 8.3-alpine + - name: Build 8.3-alpine uses: docker/build-push-action@v2 with: context: . file: ./images/8.3/Dockerfile-alpine - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.3-alpine,umutphp/php-docker-images-for-ci:latest-alpine - - name: Build And Push 7.1 + - name: Build 7.1 uses: docker/build-push-action@v2 with: context: ./images/7.1/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.1 - - name: Build And Push 7.2 + - name: Build 7.2 uses: docker/build-push-action@v2 with: context: ./images/7.2/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.2 - - name: Build And Push 7.3 + - name: Build 7.3 uses: docker/build-push-action@v2 with: context: ./images/7.3/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.3 - - name: Build And Push 7.4 + - name: Build 7.4 uses: docker/build-push-action@v2 with: context: ./images/7.4/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:7.4 - - name: Build And Push 8.0 + - name: Build 8.0 uses: docker/build-push-action@v2 with: context: ./images/8.0/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.0 - - name: Build And Push 8.1 + - name: Build 8.1 uses: docker/build-push-action@v2 with: context: ./images/8.1/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.1 - - name: Build And Push 8.2 + - name: Build 8.2 uses: docker/build-push-action@v2 with: context: ./images/8.2/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.2 - - name: Build And Push 8.3 + - name: Build 8.3 uses: docker/build-push-action@v2 with: context: ./images/8.3/ - push: true + push: ${{ inputs.push_images }} tags: umutphp/php-docker-images-for-ci:8.3,umutphp/php-docker-images-for-ci:latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5990bb7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,15 @@ +name: Build & Push Docker Images + +on: + push: + branches: + - main + +jobs: + build-push-images: + uses: ./.github/workflows/build-docker-image.yml + with: + push_images: true + secrets: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..04c8acb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,8 @@ +name: Build Docker Images + +on: + pull_request: + +jobs: + build-images: + uses: ./.github/workflows/build-docker-image.yml