Build Docker image #75
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 image | |
on: | |
push: | |
branches: | |
- "trunk" | |
schedule: | |
- cron: "0 4 * * 0" | |
jobs: | |
build_push_to_dockerhub: | |
strategy: | |
matrix: | |
base_container: ["php:7.4-bullseye", "php:8.0-bullseye", "php:8.1-bullseye"] | |
runs-on: ubuntu-20.04 | |
steps: | |
# no need to use actions/checkout with docker/build-push-action workflow | |
# https://github.com/docker/build-push-action | |
## Set environment variables for the build container by matrix | |
# 7.4 is the current "latest" default version and gets this extra tag | |
# upon EOL, this should move to 8.0 | |
- name: Set PHP 7.4 settings | |
if: ${{ matrix.base_container == 'php:7.4-bullseye' }} | |
run: | | |
echo "BUILD_TAGS=10up/wordpress-ci:latest,10up/wordpress-ci:php-7.4" >> $GITHUB_ENV | |
echo "COMPOSER_VERSION=1" >> $GITHUB_ENV | |
- name: Set PHP 8.0 settings | |
if: ${{ matrix.base_container == 'php:8.0-bullseye' }} | |
run: | | |
echo "BUILD_TAGS=10up/wordpress-ci:php-8.0" >> $GITHUB_ENV | |
echo "COMPOSER_VERSION=2" >> $GITHUB_ENV | |
- name: Set PHP 8.1 settings | |
if: ${{ matrix.base_container == 'php:8.1-bullseye' }} | |
run: | | |
echo "BUILD_TAGS=10up/wordpress-ci:php-8.1" >> $GITHUB_ENV | |
echo "COMPOSER_VERSION=2" >> $GITHUB_ENV | |
## GitHub Action validation testing before starting workflow ## | |
- name: Ensure Docker token is present | |
env: | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
if: ${{ env.DOCKERHUB_TOKEN == '' }} | |
run: | | |
echo "Dockerhub token is not defined in GitHub secrets, exiting run" | |
exit 1 | |
- name: Ensure Docker username is present | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
if: ${{ env.DOCKERHUB_USERNAME == '' }} | |
run: | | |
echo "Dockerhub username is not defined in GitHub secrets, exiting run" | |
exit 1 | |
## Begin workflow ## | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# Never use cache with builds, build from scratch for security updates | |
- name: Build and push Docker images | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
no-cache: true | |
tags: ${{ env.BUILD_TAGS }} | |
build-args: | | |
PHP_IMG=${{ matrix.base_container }} | |
COMPOSER_VERSION=${{ env.COMPOSER_VERSION }} |