Add ubuntu version for 8.2 #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Docker Images | |
on: | |
push: | |
branches: | |
- 'master' | |
tags: | |
- '*' | |
env: | |
PLATFORMS: linux/amd64,linux/arm64 | |
REPO_PREFIX: mobomo/drupalstand-ci | |
jobs: | |
generate_matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set_matrix.outputs.matrix }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Generate matrix | |
id: set_matrix | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs'); | |
const path = require('path'); | |
const repoPrefix = process.env.REPO_PREFIX; | |
// Function to check if the path is a directory and doesn't start with a dot | |
const isDirectory = source => fs.lstatSync(source).isDirectory() && !path.basename(source).startsWith('.'); | |
// Get all directories in the current directory (excluding ones starting with a dot) | |
const getDirectories = source => | |
fs.readdirSync(source).map(name => path.join(source, name)).filter(isDirectory); | |
// Get directories for the matrix generation | |
const directories = getDirectories('./'); | |
let matrix = []; | |
let refName = process.env.GITHUB_REF_NAME; | |
let tagVersion = (refName && refName !== 'master') ? refName : 'latest'; | |
directories.forEach(directory => { | |
const files = fs.readdirSync(directory); | |
files.forEach(file => { | |
if (file.startsWith('Dockerfile')) { | |
let baseTag = path.basename(directory).toLowerCase().replace('php', ''); | |
let variant = file === 'Dockerfile' ? '' : `-${file.replace('Dockerfile.', '')}`; | |
let tags = [`${repoPrefix}:${baseTag}${variant}-latest`]; | |
if (tagVersion !== 'latest') { | |
// If this is a tag push, also add a version-specific tag | |
tags.push(`${repoPrefix}:${baseTag}${variant}-${tagVersion}`); | |
} | |
matrix.push({ | |
context: directory, | |
dockerfile: file, | |
tags: tags.join(',') | |
}); | |
} | |
}); | |
}); | |
// Set the matrix output to a properly formatted JSON string | |
core.setOutput('matrix', JSON.stringify({ include: matrix })); | |
- name: Print matrix | |
run: echo "${{ steps.set_matrix.outputs.matrix }}" | |
- name: Print matrix jsobject | |
run: echo "${{ fromJson(steps.set_matrix.outputs.matrix) }}" | |
build: | |
needs: generate_matrix | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.generate_matrix.outputs.matrix) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ matrix.context }} | |
file: ${{ matrix.context }}/${{ matrix.dockerfile }} | |
platforms: ${{ env.PLATFORMS }} | |
push: true | |
tags: ${{ matrix.tags }} | |
- name: Build | |
if: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./${{ matrix.context }} | |
file: ${{ matrix.context }}/${{ matrix.dockerfile }} | |
platforms: ${{ env.PLATFORMS }} | |
push: false | |
tags: ${{ matrix.tags }} |