Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/lib.build-push-image.yml
Original file line number Diff line number Diff line change
@@ -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 }}"