Update build-images.yml #5
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 | |
on: | |
push: | |
branches: [ main ] | |
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@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Registry | |
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: 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: Github Short SHA | |
run: | | |
echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
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 |