Skip to content

Build and push Docker images #457

Build and push Docker images

Build and push Docker images #457

Workflow file for this run

name: Build and push Docker images
on:
schedule:
- cron: '42 5 * * *'
push:
branches:
- '**'
pull_request:
branches:
- '**'
jobs:
build-and-push:
name: Build and push Docker image
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
strategy:
fail-fast: false
matrix:
alpine: ["3.14"]
composer: ["2", "1"]
node: ["16", "14", "12", "10"]
php: ["7.4", "7.3"]
surf: ["2"]
include:
- alpine: "3.12"
php: "7.2"
composer: "2"
node: "16"
surf: "2"
- alpine: "3.12"
php: "7.2"
composer: "2"
node: "14"
surf: "2"
- alpine: "3.12"
php: "7.2"
composer: "2"
node: "12"
surf: "2"
- alpine: "3.12"
php: "7.2"
composer: "2"
node: "10"
surf: "2"
- alpine: "3.12"
php: "7.2"
composer: "1"
node: "16"
surf: "2"
- alpine: "3.12"
php: "7.2"
composer: "1"
node: "14"
surf: "2"
- alpine: "3.12"
php: "7.2"
composer: "1"
node: "12"
surf: "2"
- alpine: "3.12"
php: "7.2"
composer: "1"
node: "10"
surf: "2"
- alpine: "3.16"
composer: "2"
php: "7.4"
node: "10"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "7.4"
node: "12"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "7.4"
node: "14"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "7.4"
node: "16"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.0"
node: "10"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.0"
node: "12"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.0"
node: "14"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.0"
node: "16"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.1"
node: "10"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.1"
node: "12"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.1"
node: "14"
surf: "3"
- alpine: "3.16"
composer: "2"
php: "8.1"
node: "16"
surf: "3"
- alpine: "3.17"
composer: "2"
php: "8.2"
node: "16"
surf: "3"
env:
LATEST_COMPOSER: "2"
LATEST_PHP: "7.4"
LATEST_NODE: "14"
IMAGE_NAME: t3easy/surf
PLATFORMS: linux/amd64,linux/arm64
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push latest image
uses: docker/build-push-action@v4
if: ${{ matrix.composer == env.LATEST_COMPOSER && matrix.node == env.LATEST_NODE && matrix.php == env.LATEST_PHP }}
with:
push: ${{ github.event_name != 'pull_request' }}
platforms: ${{ env.PLATFORMS }}
build-args: |
ALPINE_VERSION=${{ matrix.alpine }}
COMPOSER_VERSION=${{ matrix.composer }}
NODE_VERSION=${{ matrix.node }}
PHP_VERSION=${{ matrix.php }}
SURF_VERSION=${{ matrix.surf }}
tags: |
${{ env.IMAGE_NAME }}
ghcr.io/${{ env.IMAGE_NAME }}
${{ env.IMAGE_NAME }}:${{ matrix.surf }}-php${{ matrix.php }}-composer${{ matrix.composer }}-node${{ matrix.node }}
ghcr.io/${{ env.IMAGE_NAME }}:${{ matrix.surf }}-php${{ matrix.php }}-composer${{ matrix.composer }}-node${{ matrix.node }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Build and push images
uses: docker/build-push-action@v4
if: ${{ matrix.composer != env.LATEST_COMPOSER || matrix.node != env.LATEST_NODE || matrix.php != env.LATEST_PHP }}
with:
push: ${{ github.event_name != 'pull_request' }}
platforms: ${{ env.PLATFORMS }}
build-args: |
ALPINE_VERSION=${{ matrix.alpine }}
COMPOSER_VERSION=${{ matrix.composer }}
NODE_VERSION=${{ matrix.node }}
PHP_VERSION=${{ matrix.php }}
SURF_VERSION=${{ matrix.surf }}
tags: |
${{ env.IMAGE_NAME }}:${{ matrix.surf }}-php${{ matrix.php }}-composer${{ matrix.composer }}-node${{ matrix.node }}
ghcr.io/${{ env.IMAGE_NAME }}:${{ matrix.surf }}-php${{ matrix.php }}-composer${{ matrix.composer }}-node${{ matrix.node }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache