Build Docker Images #231
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 | |
env: | |
DOCKERHUB_TAG: "foorschtbar/php-webserver" | |
DOCKERHUB_SHORT_DESCRIPTION: "This is an usefull extension of the official php:*-apache Docker image." | |
DOCKERHUB_README_FILE: "README.md" | |
on: | |
push: | |
schedule: | |
- cron: "0 5 * * 5" | |
defaults: | |
run: | |
shell: "bash -Eeuo pipefail -x {0}" | |
jobs: | |
main: | |
name: Build & Push Docker Images | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
php: ["8.3"] | |
python: ["python", "no-python"] | |
include: | |
- php: "8.3" | |
python: "no-python" | |
tag_with_latest: true | |
tag_with_develop: true | |
- php: "8.3" | |
python: "python" | |
tag_with_python: true | |
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 | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
- name: Set cache buster | |
id: cache_buster | |
run: | | |
if [ '${{ github.event_name }}' == 'schedule' ] | |
then | |
echo "Scheduled run. Disable cache." | |
echo "::set-output name=suffix::-no-cache" | |
else | |
echo "Non-scheduled run. Enable cache." | |
echo "::set-output name=suffix::" | |
fi | |
- name: Get branche name | |
uses: nelonoel/[email protected] | |
- name: Set Docker Tags | |
id: docker_tags | |
run: | | |
TAGS=() | |
TAG_DEVELOP="" | |
TAG_PYTHON="" | |
# Add tag develop if needed | |
if [ ${BRANCH_NAME} == 'develop' ] | |
then | |
TAG_DEVELOP="-develop" | |
# Tag with "develop" | |
if [ '${{ matrix.tag_with_develop}}' == 'true' ] | |
then | |
TAGS+=(${{ env.DOCKERHUB_TAG }}:develop) | |
fi | |
else | |
# Tag with "latest" | |
if [ '${{ matrix.tag_with_latest }}' == 'true' ] | |
then | |
TAGS+=(${{ env.DOCKERHUB_TAG }}:latest) | |
fi | |
fi | |
# Add tag python if needed | |
if [ '${{ matrix.python }}' == 'python' ] | |
then | |
TAG_PYTHON="-python" | |
fi | |
# Build "long" tag | |
TAGS+=(${{ env.DOCKERHUB_TAG }}:${{ matrix.php }}$TAG_PYTHON$TAG_DEVELOP) | |
# Tag with "python" | |
if [ '${{ matrix.tag_with_python }}' == 'true' ] | |
then | |
TAGS+=(${{ env.DOCKERHUB_TAG }}:python) | |
fi | |
TAG_LIST=$(IFS=,; printf '%s' "${TAGS[*]}") | |
echo "Image tags:" | |
printf -- '- %s\n' "${TAGS[@]}" | |
echo "::set-output name=tags::$TAG_LIST" | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
build-args: | | |
FROM_TAG=${{ matrix.php }}-apache | |
PYTHON=${{ matrix.python }} | |
push: true | |
tags: ${{ steps.docker_tags.outputs.tags }} | |
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64 | |
cache-from: type=registry,ref=${{ env.DOCKERHUB_TAG }}:${{ matrix.php }}${{ steps.cache_buster.outputs.suffix }} | |
cache-to: type=inline | |
- name: Image digests | |
run: | | |
echo PHP version: ${{ matrix.php }}; \ | |
echo Python: ${{ matrix.python }}; \ | |
echo Branche: ${BRANCH_NAME}; \ | |
echo Digests: ${{ steps.docker_build.outputs.digest }} | |
pushreadme: | |
runs-on: ubuntu-latest | |
name: Push README to Docker Hub | |
steps: | |
- name: git checkout | |
uses: actions/checkout@v4 | |
- name: push README to Dockerhub | |
uses: christian-korneck/update-container-description-action@v1 | |
env: | |
DOCKER_USER: ${{ secrets.DOCKER_HUB_USERNAME }} | |
DOCKER_PASS: ${{ secrets.DOCKER_HUB_PASSWORD }} | |
with: | |
destination_container_repo: ${{ env.DOCKERHUB_TAG }} | |
provider: dockerhub | |
short_description: ${{ env.DOCKERHUB_SHORT_DESCRIPTION }} | |
readme_file: ${{ env.DOCKERHUB_README_FILE }} |