Skip to content

Merge branch 'main' into stop-php-7.4-and-8.0 #1209

Merge branch 'main' into stop-php-7.4-and-8.0

Merge branch 'main' into stop-php-7.4-and-8.0 #1209

name: Build Docker images
on:
push:
workflow_dispatch:
schedule:
- cron: '30 1 * * *'
env:
DOCKER_REPOSITORY: ghcr.io/friendsofshopware/platform-plugin-dev
CACHE_KEY: "2020-09-22"
jobs:
build-base:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3']
flavour: ['alpine', 'bullseye']
steps:
- name: Clone
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build docker image
uses: docker/build-push-action@v3
with:
build-args: |
PHP_VERSION=${{ matrix.php-version }}
FLAVOUR=${{ matrix.flavour }}
tags: "${{ env.DOCKER_REPOSITORY }}-base:${{ matrix.php-version }}-${{ matrix.flavour }}"
file: "${{ matrix.flavour }}/Dockerfile.base"
push: false
load: true
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.CACHE_KEY }}-${{ matrix.php-version }}-${{ matrix.flavour }}
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ env.CACHE_KEY }}-${{ matrix.php-version }}-${{ matrix.flavour }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
- name: Check for push
id: check-push
run: |
if [ "${{ secrets.DOCKER_USERNAME }}" == "" ] || [ "${{ secrets.DOCKER_PASSWORD }}" == "" ]; then
echo "No Docker credentials found, skipping push."
exit 0
fi
if [ "${{ github.event_name == 'pull_request' }}" == "true" ]; then
echo "Pull request, skipping push."
exit 0
fi
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "Not on main branch, skipping push."
exit 0
fi
echo "push=1" >> $GITHUB_OUTPUT
- name: Login to GitHub Docker Registry
uses: docker/login-action@v2
if: ${{ steps.check-push.outputs.push }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push docker image
if: ${{ steps.check-push.outputs.push }}
run: |
docker push "${{ env.DOCKER_REPOSITORY }}-base:${{ matrix.php-version }}-${{ matrix.flavour }}"
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: Clone
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Generate matrix
id: generate-matrix
run: |
matrix=$(node bin/generate-matrix.js)
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
build:
needs:
- build-base
- generate-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Clone
uses: actions/checkout@v4
- name: Get Tag
id: get-docker-tag
run: |
if [[ "${{ matrix.shopware-version }}" =~ ^v.* ]]; then
shopware_version_tag=$(echo "${{ matrix.shopware-version }}" | grep -m1 -E '(v[0-9]+\.[0-9]+\.[0-9]+)' -o)
else
shopware_version_tag="${{ matrix.shopware-version }}"
fi
[ "${shopware_version_tag}" == "" ] && exit 1
tag="${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}-${{ matrix.php-version }}-${{ matrix.flavour }}"
if [[ "${{ matrix.flavour }}" == "alpine" ]]; then
tag="$tag, ${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}-${{ matrix.php-version }}"
if [[ "${{ matrix.is-main }}" == "true" ]]; then
tag="$tag, ${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}"
fi
elif [[ "${{ matrix.is-main }}" == "true" ]]; then
tag="$tag, ${{ env.DOCKER_REPOSITORY }}:${shopware_version_tag}-${{ matrix.flavour }}"
fi
echo "Shopware version ${{ matrix.shopware-version }}"
echo "PHP version ${{ matrix.php-version }}"
echo "Image Tag: ${tag}"
echo "tag=${tag}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build docker image
uses: docker/build-push-action@v3
with:
build-args: |
SHOPWARE_VERSION=${{ matrix.shopware-version }}
PHP_VERSION=${{ matrix.php-version }}
TEMPLATE_REPOSITORY=${{ matrix.template }}
FLAVOUR=${{ matrix.flavour }}
tags: ${{ steps.get-docker-tag.outputs.tag }}
file: "${{ matrix.flavour }}/Dockerfile"
push: false
load: true
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.CACHE_KEY }}-${{ matrix.shopware-version }}-${{ matrix.flavour }}
cache-to: type=gha,mode=max,scope=${{ github.ref_name }}-${{ env.CACHE_KEY }}-${{ matrix.shopware-version }}-${{ matrix.flavour }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
- name: Check for push
id: check-push
run: |
if [ "${{ secrets.DOCKER_USERNAME }}" == "" ] || [ "${{ secrets.DOCKER_PASSWORD }}" == "" ]; then
echo "No Docker credentials found, skipping push."
exit 0
fi
if [ "${{ github.event_name == 'pull_request' }}" == "true" ]; then
echo "Pull request, skipping push."
exit 0
fi
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "Not on main branch, skipping push."
exit 0
fi
echo "push=1" >> $GITHUB_OUTPUT
- name: Login to GitHub Docker Registry
uses: docker/login-action@v2
if: ${{ steps.check-push.outputs.push }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push docker image
if: ${{ steps.check-push.outputs.push }}
run: |
tags="${{ steps.get-docker-tag.outputs.tag }}"
for tag in ${tags//,/}; do
docker push "${tag}"
done