From 157359304a2e2f94479e7d7d39a70205422d77ed Mon Sep 17 00:00:00 2001 From: Cristian Romanescu Date: Wed, 29 Jul 2026 21:03:35 +0300 Subject: [PATCH] Add support to build and push images to repository --- .github/workflows/lib.build-push-image.yml | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/lib.build-push-image.yml diff --git a/.github/workflows/lib.build-push-image.yml b/.github/workflows/lib.build-push-image.yml new file mode 100644 index 0000000..b6a8363 --- /dev/null +++ b/.github/workflows/lib.build-push-image.yml @@ -0,0 +1,78 @@ +# DO NOT EDIT - This file is managed by the template repository. +# Source: https://github.com/eaudeweb/drupal-workflows-template +# +# Docker deploy flow (2.x): build the site image from the project Dockerfile +# (FROM drupal-docker-appserver + composer install) and push it to the private +# Docker Hub repo. Replaces the host artifact tarball (lib.create-release-archive) +# — the artifact is now an immutable image tagged with the git tag (e.g. 0001). +on: + workflow_call: + inputs: + runner: + type: string + required: false + default: 'drupal-runner-v2' + image_name: + description: 'Docker Hub repo, e.g. drupaleaudeweb/project-eaudeweb-ro' + type: string + required: true + image_tag: + description: 'Image tag = the git tag (e.g. 0001)' + type: string + required: true + checkout_ref: + type: string + required: false + default: '' + appserver_tag: + description: 'Override the Dockerfile APPSERVER_TAG base (optional)' + type: string + required: false + default: '' + secrets: + dockerhub_user: + required: true + dockerhub_token: + required: true + outputs: + image: + value: '${{ inputs.image_name }}:${{ inputs.image_tag }}' + +jobs: + build_push_image: + name: 'Build and push site image' + runs-on: ${{ inputs.runner || 'drupal-runner-v2' }} + steps: + - name: 'Fail if a branch was selected' + if: | + github.event_name == 'workflow_dispatch' && + !startsWith(github.ref, 'refs/tags/') && + github.ref != 'refs/heads/test' + run: | + echo "This workflow should be triggered on a tag, not a branch. Please choose a tag." + exit 1 + + - name: 'Checkout source code' + uses: actions/checkout@v6 + with: + fetch-depth: 1 + ref: ${{ inputs.checkout_ref }} + + - name: 'Log in to Docker Hub' + uses: docker/login-action@v4 + with: + username: ${{ secrets.dockerhub_user }} + password: ${{ secrets.dockerhub_token }} + + - name: 'Build image' + # --pull refreshes the pinned appserver base from the private registry + # (login above grants access). The base tag is pinned in the Dockerfile; + # appserver_tag overrides it only when explicitly provided. + run: | + docker build --pull \ + ${{ inputs.appserver_tag != '' && format('--build-arg APPSERVER_TAG={0}', inputs.appserver_tag) || '' }} \ + -t "${{ inputs.image_name }}:${{ inputs.image_tag }}" \ + . + + - name: 'Push image' + run: docker push "${{ inputs.image_name }}:${{ inputs.image_tag }}"