Update build-images.yml #19
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 Docker Images | ||
permissions: | ||
contents: read | ||
packages: write | ||
on: | ||
push: | ||
branches: [ main ] | ||
paths-ignore: | ||
- "README.md" | ||
- "docker-compose.yml" | ||
- "examples/**" | ||
- ".run/**" | ||
- ".circleci/**" | ||
concurrency: | ||
group: "${{ github.workflow }}-${{ github.ref }}" | ||
cancel-in-progress: true | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php_version: ['8.3', '8.1', '8.0', '7.4'] | ||
variant: ['apache', 'apache-chrome'] | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
- name: Set variables | ||
run: | | ||
if [ "${{ matrix.variant }}" == "apache" ]; then | ||
echo "DOCKER_TAG=${{ matrix.php_version }}" >> $GITHUB_ENV | ||
echo "DOCKER_FILE=Dockerfile" >> $GITHUB_ENV | ||
elif [ "${{ matrix.variant }}" == "apache-chrome" ]; then | ||
echo "DOCKER_TAG=${{ matrix.php_version }}-headless" >> $GITHUB_ENV | ||
echo "DOCKER_FILE=Dockerfile-headless" >> $GITHUB_ENV | ||
else | ||
echo "Invalid variant: ${{ matrix.variant }}" | ||
exit 1 | ||
fi | ||
- name: Skip build if file does not exist | ||
run: | | ||
if [ ! -f "./${{ matrix.php_version }}/${{ env.DOCKER_FILE }}" ]; then | ||
exit 0 # Exit successfully if the file does not exist | ||
fi | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to Docker Registry | ||
# Only run this step if the secrets are set | ||
if: secrets.DOCKER_HUB_USER && secrets.DOCKER_HUB_TOKEN | ||
Check failure on line 58 in .github/workflows/build-images.yml GitHub Actions / Build Docker ImagesInvalid workflow file
|
||
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_HUB_USER }} --password-stdin | ||
- name: Login to GitHub Container Registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
- name: Github Short SHA | ||
run: | | ||
echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-7)" >> $GITHUB_ENV | ||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./${{ matrix.php_version }}/${{ env.DOCKER_FILE }} | ||
tags: | ||
ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }}, | ||
ghcr.io/${{ github.repository }}:${{ env.GITHUB_SHA_SHORT }} | ||
push: true | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |