Skip to content

Docker Image Push (on commit and base image update) #220

Docker Image Push (on commit and base image update)

Docker Image Push (on commit and base image update) #220

Workflow file for this run

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:
- 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'
# Build image
- name: Access to repository contents
uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file "Dockerfile" --tag "$IMAGE_OWNER/$IMAGE_NAME:latest"
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}
# Push latest tag
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}
- name: Push to DockerHub
run: docker push "$IMAGE_OWNER/$IMAGE_NAME:latest"
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}
# More tags to push
- name: 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') }}
- name: Tag PHP Version
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 tag "$IMAGE_OWNER/$IMAGE_NAME:latest" "$IMAGE_OWNER/$IMAGE_NAME:php-$php_v"; docker push "$IMAGE_OWNER/$IMAGE_NAME:php-$php_v"
if: ${{ (github.event_name == 'push') || (steps.check.outputs.needs-updating == 'true') }}