Skip to content
refresh-ccw

GitHub Action

Is my docker parent image out-of-date?

v1.0.1 Latest version

Is my docker parent image out-of-date?

refresh-ccw

Is my docker parent image out-of-date?

Checks if your image uses an out-of-date parent image. Use this do determine whether you need to rebuild your image

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Is my docker parent image out-of-date?

uses: twiddler/is-my-docker-parent-image-out-of-date@v1.0.1

Learn more about this action in twiddler/is-my-docker-parent-image-out-of-date

Choose a version

Is my docker parent image out-of-date?

Test

Well, ask no more! This github action has the answer! 😎

Keeping your parent image up-to-date is essential to provide your built images with the latest (security) patches. However, you might not want to stupidly rebuild your image everyday. Use this action to check if you really have to rebuild! 🥳

Works with any container registry supported by containers/skopeo. The default container registry is Docker Hub. If your image is hosted there, you can use nginx instead of docker.io/nginx. If your image is hosted on GitHub, use e.g. ghcr.io/oracle/oraclelinux8-python:3.9.

I haven't tested this with multi-stage builds, but I guess it should be able to (only) check the last stage that really makes it into your built image. Feel free to open a pull request.

Inputs

Name Type Description
parent-image String The docker parent image you are building on top
my-image String Your image which uses FROM [parent-image]

Output

Name Type Description
out-of-date String 'true' if my-image does not use the latest version of parent-image, 'false' otherwise.

Example

If you want to rebuild your image when and only when its parent image changes, you could add an action like this to your project:

name: Rebuild image when parent-image changes

# Regularly check at 4 AM
on:
  schedule:
    - cron: "0 4 * * *"

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      # Checkout your repository. You don't need this for the check to work, but putting it here saves you an "if: ..."
      - name: Checkout
        uses: actions/checkout@v2

      # Now check if our parent image changed. The result will be available at `steps.[id of this step].outputs.out-of-date`
      - name: Check if we have to even do all this
        id: check
        uses: twiddler/is-my-docker-parent-image-out-of-date@v1
        with:
          parent-image: nginx:1.21.0
          my-image: user/app:latest

      # We only want to build and push if our parent image changed.
      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: user/app:latest
        # Add this line to all the steps you want to skip
        if: steps.check.outputs.out-of-date == 'true'