Docker Image Push (on commit and base image update) #1506
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: Docker Image Push (on commit and base image update) | |
on: | |
push: | |
branches: [ "master" ] | |
schedule: | |
- cron: "15 */8 * * *" | |
env: | |
IMAGE_OWNER: kimbtechnologies | |
IMAGE_NAME: php_nginx | |
BASE_IMAGE: library/php:fpm-alpine | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# check if update needed | |
- name: Check for new baseimage | |
id: check | |
uses: lucacome/docker-image-update-checker@v1 | |
with: | |
base-image: "${{env.BASE_IMAGE}}" | |
image: "${{env.IMAGE_OWNER}}/${{env.IMAGE_NAME}}:latest" | |
#env: | |
# DEBUG: true | |
if: github.event_name != 'push' | |
# setup build env. | |
- name: Access repository contents | |
uses: actions/checkout@v4 | |
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} | |
# build local AMD image | |
- name: Build the AMD image | |
run: docker build . --file "Dockerfile" --tag "$IMAGE_OWNER/$IMAGE_NAME:latest" | |
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} | |
- name: Push tag 8-latest | |
run: docker tag "$IMAGE_OWNER/$IMAGE_NAME:latest" "$IMAGE_OWNER/$IMAGE_NAME:8-latest"; docker push "$IMAGE_OWNER/$IMAGE_NAME:8-latest"; | |
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} | |
# Multi platform support | |
- name: Set up QEMU for Docker Buildx | |
uses: docker/setup-qemu-action@v3 | |
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} | |
# Multi platform image build and push | |
- name: Build and push the ARM Docker images | |
run: php_v=$(docker run --rm "$IMAGE_OWNER/$IMAGE_NAME:latest" sh -c 'echo "$PHP_VERSION"'); php_v=$(echo $php_v | grep -o '[0-9\.]*'); docker buildx build --platform linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/arm64 . --file "Dockerfile" --tag "$IMAGE_OWNER/$IMAGE_NAME:latest" --tag "$IMAGE_OWNER/$IMAGE_NAME:php-$php_v" --push | |
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }} | |